using System; using Deltares.Standard.IO.Xml; namespace Deltares.Stability { public class StabilityXmlHandler : IXmlHandler { public bool CanHandle(Type type, string property) { if (type == typeof(StabilityModel)) { switch (property) { case "SlipPlaneMinDepth": case "SlipPlaneMinLength": return true; default: return false; } } else if (type == typeof(SlipplaneConstraints)) { switch (property) { case "IsXEntryMinUsed": case "IsXEntryMaxUsed": return true; default: return false; } } else { return false; } } public bool CanHandle(Type type) { return false; } public Type GetFormerPropertyType(Type type, string property) { if (type == typeof(StabilityModel)) { switch (property) { case "SlipPlaneMinDepth": case "SlipPlaneMinLength": return typeof(double); default: return null; } } else if (type == typeof(SlipplaneConstraints)) { switch (property) { case "IsXEntryMinUsed": case "IsXEntryMaxUsed": return typeof(bool); default: return null; } } return null; } public void Handle(object target, string property, object value, object[] objects) { StabilityModel stabilityModel = target as StabilityModel; SlipplaneConstraints constraints = target as SlipplaneConstraints; if (stabilityModel != null) { switch (property) { case "SlipPlaneMinDepth": stabilityModel.SlipPlaneConstraints.SlipPlaneMinDepth = (double)value; break; case "SlipPlaneMinLength": stabilityModel.SlipPlaneConstraints.SlipPlaneMinLength = (double)value; break; } } else if (constraints != null) { switch (property) { case "IsXEntryMinUsed": bool minUsed = (bool)value; if (minUsed && double.IsNaN(constraints.XEntryMin)) { constraints.XEntryMin = 0; } else if (!minUsed) { constraints.XEntryMin = double.NaN; } break; case "IsXEntryMaxUsed": bool maxUsed = (bool)value; if (maxUsed && double.IsNaN(constraints.XEntryMax)) { constraints.XEntryMax = 0; } else if (!maxUsed) { constraints.XEntryMax = double.NaN; } break; } } } public void HandleObject(object target, object value) { } public void SetVersion(string version) { } public void Upgrade(object[] target) { } } }