using System;
using Deltares.DeltaModel;
using Deltares.Geotechnics;
using Deltares.Geotechnics.Converter;
using Deltares.Geotechnics.WaternetCreator;
using Deltares.Standard.IO.Xml;
using Deltares.Standard.Reflection;
namespace Deltares.Stability
{
///
/// This handler is responsible for handling an object which has been created with the SurfaceLine type.
/// Since the old SurfaceLine has been refactored, this handler will convert the old SurfaceLine to a SurfaceLine2.
///
public class SurfaceLineXmlHandler : IXmlHandler
{
public void SetVersion(string version) {}
///
/// This method returns true for a type and the
/// property.
///
/// The type to check for.
/// The property of the type to check for
/// True if type is and property is "SurfaceLine"
public bool CanHandle(Type type)
{
return type != null && (type == typeof(Location) || type.IsSubclassOf(typeof(Location)) || type == typeof(DikeLocation) || type.IsSubclassOf(typeof(DikeLocation)));
}
///
/// This method returns true for a type and the
/// property.
///
/// The type to check for.
/// The property of the type to check for
/// True if type is and property is "SurfaceLine"
public bool CanHandle(Type type, string property)
{
return CanHandle(type) &&
(property == StaticReflection.GetMemberName(x => x.Surfaceline) ||
property == StaticReflection.GetMemberName(x => x.SchematizedSurfaceLine));
}
///
/// Not implemented for this class.
///
///
///
///
public void Handle(object target, string property, object value, object[] objects)
{
throw new NotImplementedException();
}
///
/// If the is an old and the is a
/// , the will be converted to the new
/// and the property is set for the target.
///
/// The target to set the handle the value for
/// The value to handle
public void HandleObject(object target, object value)
{
var oldSurfaceLine = value as BaseSurfaceLine;
if (null != oldSurfaceLine)
{
if (target is Location)
{
((Location) target).Surfaceline = (new OldSurfaceLineToNewConverter()).Convert(oldSurfaceLine);
}
else if (target is DikeLocation)
{
((DikeLocation)target).SchematizedSurfaceLine = (new OldSurfaceLineToNewConverter()).Convert(oldSurfaceLine);
}
}
}
public Type GetFormerPropertyType(Type type, string property)
{
return null;
}
public void Upgrade(object[] targets) {}
}
}