// Copyright (C) Stichting Deltares 2020. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero 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.Text; using System.Xml.Serialization; namespace Deltares.LayerOnSlopeTool.Io { public class MStabDamXmlSerializer { /// /// Saves the tnsPrefixDamMStabDoc as XML. /// /// The filename. /// The tnsPrefixDamMStabDoc. public static void SaveDamMStabDocAsXmlFile(string filename, tnsPrefixDamMStabDoc tnsPrefixDamMStabDoc) { string xmlString = SaveDamMStabDocAsXmlString(tnsPrefixDamMStabDoc); File.WriteAllText(filename, xmlString, Encoding.Unicode); } /// /// Loads the tnsPrefixDamMStabDoc from XML. /// /// The filename. /// tnsPrefixDamMStabDoc object public static tnsPrefixDamMStabDoc LoadDamMStabDocFromXmlFile(string filename) { string xmlString = File.ReadAllText(filename); tnsPrefixDamMStabDoc tnsPrefixDamMStabDoc = LoadDamMStabDocFromXmlString(xmlString); return tnsPrefixDamMStabDoc; } /// /// Saves the tnsPrefixDamMStabDoc as XML string. /// /// The tnsPrefixDamMStabDoc. /// xm string public static string SaveDamMStabDocAsXmlString(tnsPrefixDamMStabDoc tnsPrefixDamMStabDoc) { tnsPrefixDamMStabDoc.tnsPrefixFileIdentification = CreateFileIdentification(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(tnsPrefixDamMStabDoc)); TextWriter writer = new StringWriter(); xmlSerializer.Serialize(writer, tnsPrefixDamMStabDoc); return writer.ToString(); } /// /// Loads the tnsPrefixDamMStabDoc from XML string. /// /// The XML string. /// tnsPrefixDamMStabDoc object public static tnsPrefixDamMStabDoc LoadDamMStabDocFromXmlString(string xmlString) { tnsPrefixDamMStabDoc tnsPrefixDamMStabDoc; XmlSerializer xmlSerializer = new XmlSerializer(typeof(tnsPrefixDamMStabDoc)); StringReader reader = new StringReader(xmlString); tnsPrefixDamMStabDoc = (tnsPrefixDamMStabDoc)xmlSerializer.Deserialize(reader); return tnsPrefixDamMStabDoc; } private static tnsPrefixDamMStabDocTnsPrefixFileIdentification CreateFileIdentification() { tnsPrefixDamMStabDocTnsPrefixFileIdentification tnsPrefixDamMStabDocFileIdentification = new tnsPrefixDamMStabDocTnsPrefixFileIdentification(); var hostAssembly = Assembly.GetEntryAssembly(); if (hostAssembly == null) { hostAssembly = Assembly.GetExecutingAssembly(); } tnsPrefixDamMStabDocFileIdentification.Application = hostAssembly.GetName().Name; tnsPrefixDamMStabDocFileIdentification.Version = hostAssembly.GetName().Version.ToString(); tnsPrefixDamMStabDocFileIdentification.Created = DateTime.Now.ToShortDateString() + " "+ DateTime.Now.ToShortTimeString(); tnsPrefixDamMStabDocFileIdentification.Company = "Deltares"; return tnsPrefixDamMStabDocFileIdentification; } } }