Index: DamEngine/trunk/src/Deltares.DamEngine.Interface/EngineInterface.cs =================================================================== diff -u -r4000 -r4052 --- DamEngine/trunk/src/Deltares.DamEngine.Interface/EngineInterface.cs (.../EngineInterface.cs) (revision 4000) +++ DamEngine/trunk/src/Deltares.DamEngine.Interface/EngineInterface.cs (.../EngineInterface.cs) (revision 4052) @@ -31,177 +31,176 @@ using Deltares.DamEngine.Io.XmlInput; using Deltares.DamEngine.Io.XmlOutput; -namespace Deltares.DamEngine.Interface +namespace Deltares.DamEngine.Interface; + +/// +/// The main interface class for accessing the Dam Engine +/// +public class EngineInterface { /// - /// The main interface class for accessing the Dam Engine + /// Initializes a new instance of the class. /// - public class EngineInterface + /// Xml string containing the model input. + public EngineInterface(string modelInput) { - /// - /// Initializes a new instance of the class. - /// - /// Xml string containing the model input. - public EngineInterface(string modelInput) + if (String.IsNullOrEmpty(modelInput)) { - if (String.IsNullOrEmpty(modelInput)) - { - throw new EngineInterfaceException(Resources.Error_EmptyInputString); - } - - Input input = DamXmlSerialization.LoadInputFromXmlString(modelInput); - DamProjectData = FillDamFromXmlInput.CreateDamProjectData(input); - SendMessage(new LogMessage - { - MessageType = LogMessageType.Info, - Message = Resources.ModelAccepted - }); + throw new EngineInterfaceException(Resources.Error_EmptyInputString); } - /// - /// Gets or sets the progress delegate. - /// - /// - /// The progress delegate. - /// - public ProgressDelegate ProgressDelegate { get; set; } + Input input = DamXmlSerialization.LoadInputFromXmlString(modelInput); + DamProjectData = FillDamFromXmlInput.CreateDamProjectData(input); + SendMessage(new LogMessage + { + MessageType = LogMessageType.Info, + Message = Resources.ModelAccepted + }); + } - /// - /// Gets or sets the send message delegate. - /// - /// - /// The send message delegate. - /// - public SendMessageDelegate SendMessageDelegate { get; set; } + /// + /// Gets or sets the progress delegate. + /// + /// + /// The progress delegate. + /// + public ProgressDelegate ProgressDelegate { get; set; } - /// - /// Gets or sets the user abort delegate. - /// - /// - /// The user abort delegate. - /// - public UserAbortDelegate UserAbortDelegate { get; set; } + /// + /// Gets or sets the send message delegate. + /// + /// + /// The send message delegate. + /// + public SendMessageDelegate SendMessageDelegate { get; set; } - /// - /// Gets or sets the dam project data. - /// - /// - /// The dam project data. - /// - public DamProjectData DamProjectData { get; set; } + /// + /// Gets or sets the user abort delegate. + /// + /// + /// The user abort delegate. + /// + public UserAbortDelegate UserAbortDelegate { get; set; } - /// - /// Validates the model. - /// - /// Validation messages in an XML string - public string Validate() + /// + /// Gets or sets the dam project data. + /// + /// + /// The dam project data. + /// + public DamProjectData DamProjectData { get; set; } + + /// + /// Validates the model. + /// + /// Validation messages in an XML string + public string Validate() + { + SendMessage(new LogMessage { - SendMessage(new LogMessage - { - MessageType = LogMessageType.Info, - Message = Resources.StartValidation - }); - List validationMessages = null; + MessageType = LogMessageType.Info, + Message = Resources.StartValidation + }); + List validationMessages = null; - try + try + { + DamProjectData.Dike.Validate(DamProjectData.DamProjectType == DamProjectType.Operational); + } + catch (Exception e) + { + var validationMessage = new LogMessage(LogMessageType.Error, null, e.Message); + validationMessages = new List { - DamProjectData.Dike.Validate(DamProjectData.DamProjectType == DamProjectType.Operational); - } - catch (Exception e) - { - var validationMessage = new LogMessage(LogMessageType.Error, null, e.Message); - validationMessages = new List - { - validationMessage - }; - DamProjectData.CalculationMessages = new List(); - } - - // Local validation can give messages and these have to be added to the results but note that there - // already can be messages added by instantiation of the interface too. So add the local to the global - if (validationMessages != null && validationMessages.Count > 0) - { - if (DamProjectData != null && DamProjectData.CalculationMessages != null) - { - DamProjectData.CalculationMessages.AddRange(validationMessages); - } - } - - // Now check if there are any messages at all, if so return them. - if (DamProjectData != null && DamProjectData.CalculationMessages != null && DamProjectData.CalculationMessages.Count > 0) - { - Output output = FillXmlOutputFromDam.CreateOutput(DamProjectData); - string outputXml = DamXmlSerialization.SaveOutputAsXmlString(output); - SendMessage(new LogMessage - { - MessageType = LogMessageType.Info, - Message = Resources.EndValidation - }); - return outputXml; - } - - SendMessage(new LogMessage - { - MessageType = LogMessageType.Info, - Message = Resources.EndValidation - }); - return null; + validationMessage + }; + DamProjectData.CalculationMessages = new List(); } - /// - /// Runs this instance. - /// - /// Returns the output in an XML string - public string Run() + // Local validation can give messages and these have to be added to the results but note that there + // already can be messages added by instantiation of the interface too. So add the local to the global + if (validationMessages != null && validationMessages.Count > 0) { - string outputXml; - SendMessage(new LogMessage + if (DamProjectData != null && DamProjectData.CalculationMessages != null) { - MessageType = LogMessageType.Info, - Message = Resources.StartCalculation - }); - - switch (DamProjectData.DamProjectType) - { - case DamProjectType.Operational: - var operationalCalculator = new OperationalCalculator(); - operationalCalculator.Execute(DamProjectData); - break; - case DamProjectType.Design: - var designCalculator = new DesignCalculator(); - designCalculator.RegisterProgress(ProgressDelegate); - designCalculator.Execute(DamProjectData); - break; + DamProjectData.CalculationMessages.AddRange(validationMessages); } + } + // Now check if there are any messages at all, if so return them. + if (DamProjectData != null && DamProjectData.CalculationMessages != null && DamProjectData.CalculationMessages.Count > 0) + { Output output = FillXmlOutputFromDam.CreateOutput(DamProjectData); - outputXml = DamXmlSerialization.SaveOutputAsXmlString(output); + string outputXml = DamXmlSerialization.SaveOutputAsXmlString(output); SendMessage(new LogMessage { MessageType = LogMessageType.Info, - Message = Resources.EndCalculation + Message = Resources.EndValidation }); return outputXml; } - private void SendMessage(LogMessage logMessage) + SendMessage(new LogMessage { - SendMessageDelegate?.Invoke(logMessage); - } + MessageType = LogMessageType.Info, + Message = Resources.EndValidation + }); + return null; + } - private void Progress(double progress) + /// + /// Runs this instance. + /// + /// Returns the output in an XML string + public string Run() + { + string outputXml; + SendMessage(new LogMessage { - ProgressDelegate?.Invoke(progress); + MessageType = LogMessageType.Info, + Message = Resources.StartCalculation + }); + + switch (DamProjectData.DamProjectType) + { + case DamProjectType.Operational: + var operationalCalculator = new OperationalCalculator(); + operationalCalculator.Execute(DamProjectData); + break; + case DamProjectType.Design: + var designCalculator = new DesignCalculator(); + designCalculator.RegisterProgress(ProgressDelegate); + designCalculator.Execute(DamProjectData); + break; } - private bool UserAbort() + Output output = FillXmlOutputFromDam.CreateOutput(DamProjectData); + outputXml = DamXmlSerialization.SaveOutputAsXmlString(output); + SendMessage(new LogMessage { - if (UserAbortDelegate != null) - { - return UserAbortDelegate(); - } + MessageType = LogMessageType.Info, + Message = Resources.EndCalculation + }); + return outputXml; + } - return false; + private void SendMessage(LogMessage logMessage) + { + SendMessageDelegate?.Invoke(logMessage); + } + + private void Progress(double progress) + { + ProgressDelegate?.Invoke(progress); + } + + private bool UserAbort() + { + if (UserAbortDelegate != null) + { + return UserAbortDelegate(); } + + return false; } } \ No newline at end of file