Index: DamClients/DamLive/trunk/src/Deltares.Dam.Application.Live/Deltares.Dam.Application.Live.csproj =================================================================== diff -u -r3449 -r3693 --- DamClients/DamLive/trunk/src/Deltares.Dam.Application.Live/Deltares.Dam.Application.Live.csproj (.../Deltares.Dam.Application.Live.csproj) (revision 3449) +++ DamClients/DamLive/trunk/src/Deltares.Dam.Application.Live/Deltares.Dam.Application.Live.csproj (.../Deltares.Dam.Application.Live.csproj) (revision 3693) @@ -88,6 +88,8 @@ + + Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/TimeSerieCollection.cs =================================================================== diff -u -r3691 -r3693 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/TimeSerieCollection.cs (.../TimeSerieCollection.cs) (revision 3691) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/TimeSerieCollection.cs (.../TimeSerieCollection.cs) (revision 3693) @@ -67,6 +67,17 @@ /// /// Loads a time serie collection from file and validates the file with the resource embedded XSD /// + /// The file info object containing the file to load + /// When valid a loaded time serie collection + /// + public static TimeSerieCollection LoadFromFile(FileInfo fileInfo) + { + return LoadFromFile(fileInfo.FullName, true); + } + + /// + /// Loads a time serie collection from file and validates the file with the resource embedded XSD + /// /// The file to load /// When valid a loaded time serie collection /// Index: DamClients/DamLive/trunk/src/Deltares.Dam.Application.Live/CalculationParametersAssembler.cs =================================================================== diff -u --- DamClients/DamLive/trunk/src/Deltares.Dam.Application.Live/CalculationParametersAssembler.cs (revision 0) +++ DamClients/DamLive/trunk/src/Deltares.Dam.Application.Live/CalculationParametersAssembler.cs (revision 3693) @@ -0,0 +1,241 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of the application DAM - Clients Library. +// +// DAM - UI is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.IO; +using System.Reflection; +using System.Xml; +using System.Xml.Linq; +using System.Xml.Schema; +using Deltares.Standard; + +namespace Deltares.Dam.Data.Assemblers +{ + using Standard.Extensions; + + /// + /// + /// + public class CalculationParametersAssembler : DtoAssembler + { + #region Constant declarations + + /// + /// Holds the common part of the path to the embedded resource + /// + private const string EmbeddedResourcePath = "Deltares.Dam.Data.Xsd"; + + public const string XmlCalculationModulesElementName = "CalculationModules"; + public const string XmlStabilityInsideElementName = "StabilityInside"; + public const string XmlStabilityOutsideElementName = "StabilityOutside"; + public const string XmlPipingWtiElementName = "PipingWti"; + public const string XmlPipingBlighElementName = "PipingBligh"; + public const string XmlPipingSellmeijerElementName = "PipingSellmeijer"; + // Obsolete module names + public const string XmlObsoletePipingSellmeijerProbabilisticElementName = "PipingSellmeijerProbabilistic"; + public const string XmlObsoleteStabilityElementName = "Stability"; + public const string XmlObsoletePipingIJkdijkElementName = "PipingIJkdijk"; + public const string XmlObsoleteOvertoppingElementName = "Overtopping"; + + public const string XmlMStabParametersElementName = "MStabParameters"; + public const string XmlMStabIsCalculateAllStabilityProjectsAtOnceElementName = "IsCalculateAllStabilityProjectsAtOnce"; + public const string XmlMStabCalculationModelElementName = "CalculationModel"; + public const string XmlMStabSearchMethodElementName = "SearchMethod"; + public const string XmlMStabUseZonesElementName = "UseZones"; + // Obsolete Mstab parameters + public const string XmlObsoleteMStabProbabilisticElementName = "Probabilistic"; + public const string XmlObsoleteMStabIsOverrulePLLineCreationMethodName = "IsOverrulePLLineCreationMethod"; + public const string XmlObsoleteMStabPLLineCreationMethodname = "PLLineCreationMethod"; + public const string XmlObsoleteMStabShearStrengthElementName = "ShearStrength"; + + /// + /// Holds the xml element name + /// + private const string XmlElementName = "CalculationParameters"; + + /// + /// Holds the name of the xml schema + /// + private const string XmlSchemaName = "CalculationParametersDefinition"; + + /// + /// Holds the xml namespace + /// + private const string XmlElementNamespace = "http://deltares.nl/2008/" + XmlSchemaName; + + /// + /// Holds the xsd resource path + /// + private const string XsdEmbeddedResourcePath = EmbeddedResourcePath + "." + XmlSchemaName + ".xsd"; + + + #endregion + + /// + /// + /// + public CalculationParametersAssembler() + : base(XmlElementName, XmlElementNamespace, Assembly.GetExecutingAssembly().GetEmbeddedFile(XsdEmbeddedResourcePath)) + { + } + + /// + /// Gets or sets the name of the file. + /// + /// + /// The name of the file. + /// + public string FileName { get; set; } + + public override CalculationParameters CreateDomainObject(XElement dtoObj) + { + + CalculationParameters calculationParameters = base.CreateDomainObject(dtoObj); + + // Calculation modules + XElement calculationModulesElement = dtoObj.Element(XmlCalculationModulesElementName); + if (calculationModulesElement != null) + { + CalculationModules calculationModules = new CalculationModules(); + var found = false; + XElement element = calculationModulesElement.Element(CalculationParametersAssembler.XmlStabilityInsideElementName); + if (element != null) + { + calculationModules.StabilityInside = int.Parse(element.Value) != 0; + found = true; + } + element = calculationModulesElement.Element(CalculationParametersAssembler.XmlObsoleteStabilityElementName); + if (element != null && !found) + { + calculationModules.StabilityInside = int.Parse(element.Value) != 0; + found = true; + } + element = calculationModulesElement.Element(CalculationParametersAssembler.XmlStabilityOutsideElementName); + if (element != null) + { + calculationModules.StabilityOutside = int.Parse(element.Value) != 0; + } + + element = calculationModulesElement.Element(CalculationParametersAssembler.XmlPipingWtiElementName); + if (element != null) + { + calculationModules.PipingWti = int.Parse(element.Value) != 0; + } + + element = calculationModulesElement.Element(CalculationParametersAssembler.XmlPipingBlighElementName); + if (element != null) + { + calculationModules.PipingBligh = int.Parse(element.Value) != 0; + } + + element = calculationModulesElement.Element(CalculationParametersAssembler.XmlPipingSellmeijerElementName); + if (element != null) + { + calculationModules.PipingSellmeijer = int.Parse(element.Value) != 0; + } + + // Check for obsolete keys + ThrowIfObsoleteKeyNameFound(calculationModulesElement, XmlObsoletePipingSellmeijerProbabilisticElementName, FileName); + ThrowIfObsoleteKeyNameFound(calculationModulesElement, XmlObsoletePipingIJkdijkElementName, FileName); + ThrowIfObsoleteKeyNameFound(calculationModulesElement, XmlObsoleteOvertoppingElementName, FileName); + + + calculationParameters.CalculationModules = calculationModules; + } + + // MStab parameters + XElement mstabParametersElement = dtoObj.Element(XmlMStabParametersElementName); + if (mstabParametersElement != null) + { + MStabParameters mstabParameters = new MStabParameters(); + + XElement element; + + element = mstabParametersElement.Element(CalculationParametersAssembler.XmlMStabIsCalculateAllStabilityProjectsAtOnceElementName); + if (element != null) + { + mstabParameters.IsCalculateAllStabilityProjectsAtOnce = int.Parse(element.Value) != 0; + } + + element = mstabParametersElement.Element(CalculationParametersAssembler.XmlMStabCalculationModelElementName); + if (element != null) + { + mstabParameters.Model = (MStabModelType)Enum.Parse(typeof(MStabModelType), element.Value, true); + } + + element = mstabParametersElement.Element(CalculationParametersAssembler.XmlMStabSearchMethodElementName); + if (element != null) + { + mstabParameters.SearchMethod = (MStabSearchMethod)Enum.Parse(typeof(MStabSearchMethod), element.Value, true); + } + + element = mstabParametersElement.Element(CalculationParametersAssembler.XmlMStabUseZonesElementName); + mstabParameters.CalculationOptions = new MStabCalculationOptions(); + mstabParameters.CalculationOptions.ZonesType = MStabZonesType.NoZones; + if (element != null) + { + int useZones = int.Parse(element.Value); + mstabParameters.CalculationOptions.ZonesType = (MStabZonesType)useZones; + } + + // Check for obsolete keys + ThrowIfObsoleteKeyNameFound(mstabParametersElement, XmlObsoleteMStabProbabilisticElementName, FileName); + ThrowIfObsoleteKeyNameFound(mstabParametersElement, XmlObsoleteMStabIsOverrulePLLineCreationMethodName, FileName); + ThrowIfObsoleteKeyNameFound(mstabParametersElement, XmlObsoleteMStabPLLineCreationMethodname, FileName); + ThrowIfObsoleteKeyNameFound(mstabParametersElement, XmlObsoleteMStabShearStrengthElementName, FileName); + + calculationParameters.MStabParameters = mstabParameters; + } + + return calculationParameters; + } + + private static void ThrowIfObsoleteKeyNameFound(XElement calculationModulesElement, string obsoleteElementKeyName, string fileName) + { + XElement obsoleteElement = calculationModulesElement.Element(obsoleteElementKeyName); + if (obsoleteElement != null) + { + throw new DtoAssemblerException(String.Format("Your input file {0} is incorrect. The specified parameter '{1}' in your xml is obsolete. Please remove it.", fileName, obsoleteElementKeyName)); + } + } + + #region Schema Validator Method + + public bool ValidateSchema(XDocument doc, out string message) + { + bool result = true; + string errorMessage = String.Empty; + + XmlSchemaSet schemas = new XmlSchemaSet(); + + Stream xsdStream = Common.GetEmbeddedFile(Assembly.GetExecutingAssembly(), XsdEmbeddedResourcePath); + schemas.Add(XmlElementNamespace, XmlReader.Create(xsdStream)); + + doc.Validate(schemas, (o, e) => { result = false; errorMessage = e.Message; }, true); + + message = errorMessage; + + return result; + } + + #endregion + } +} \ No newline at end of file Index: DamClients/DamLive/trunk/src/Deltares.Dam.Application.Live/CalculationParameters.cs =================================================================== diff -u --- DamClients/DamLive/trunk/src/Deltares.Dam.Application.Live/CalculationParameters.cs (revision 0) +++ DamClients/DamLive/trunk/src/Deltares.Dam.Application.Live/CalculationParameters.cs (revision 3693) @@ -0,0 +1,69 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of the application DAM - Clients Library. +// +// DAM - UI is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.IO; +using System.Xml.Linq; +using Deltares.Dam.Data.Assemblers; + +namespace Deltares.Dam.Data +{ + using System; + + public class CalculationModules + { + public bool StabilityInside { get; set; } + public bool StabilityOutside { get; set; } + public bool PipingWti { get; set; } + public bool PipingBligh { get; set; } + public bool PipingSellmeijer { get; set; } + } + + public class CalculationParameters + { + public string WorkingPath { get; set; } + public string StabilityWorkingPath { get; set; } + public string PipingWorkingPath { get; set; } + public string StabilityExePath { get; set; } + + public bool CalculateAllAtOnce + { + get { return MStabParameters == null || MStabParameters.IsCalculateAllStabilityProjectsAtOnce; } + set { MStabParameters.IsCalculateAllStabilityProjectsAtOnce = value; } + } + + public static CalculationParameters LoadFromFile(FileInfo xmlFile) + { + return LoadFromFile(xmlFile.FullName); + } + + public static CalculationParameters LoadFromFile(string xmlFileName) + { + if (string.IsNullOrWhiteSpace(xmlFileName)) throw new ArgumentException("xmlFileName"); + + XDocument calculationParametersFileDocument = XDocument.Load(xmlFileName); + var assembler = new CalculationParametersAssembler(); + return assembler.CreateDomainObject(calculationParametersFileDocument); + } + + public CalculationModules CalculationModules { get; set; } + public MStabParameters MStabParameters { get; set; } + } +}