From 83631c29c0de8019c229744063d919b904026399 Mon Sep 17 00:00:00 2001 From: Mariusz Date: Sat, 12 Jun 2021 22:58:19 +0200 Subject: [PATCH] Use Common XML serializer to manage xml documents #228 - added anchors --- .../HelpContent/HelpContentHelper.cs | 72 ++++++++++--------- .../Wrappers/WrapperBase.cs | 9 +-- .../Wrappers/WrapperTreeNode.cs | 7 +- .../UAModelDesignerSolutionWrapper.cs | 9 +-- ModelDesigner.ImportExport/MamlCreator.cs | 1 + ModelDesigner.ImportExport/XmlFile.cs | 33 ++++----- 6 files changed, 69 insertions(+), 62 deletions(-) diff --git a/ModelDesigner.DesignStudio/HelpContent/HelpContentHelper.cs b/ModelDesigner.DesignStudio/HelpContent/HelpContentHelper.cs index 0c6157f3..ce344f13 100644 --- a/ModelDesigner.DesignStudio/HelpContent/HelpContentHelper.cs +++ b/ModelDesigner.DesignStudio/HelpContent/HelpContentHelper.cs @@ -1,17 +1,9 @@ -// -// Title : Helper to generate URL for documentation -// System : Microsoft Visual C# .NET 2008 -// $LastChangedDate$ -// $Rev$ -// $LastChangedBy$ -// $URL$ -// $Id$ +//__________________________________________________________________________________________________ // -// Copyright (C)2008, CAS LODZ POLAND. -// TEL: +48 (42) 686 25 47 -// mailto://techsupp@cas.eu -// http://www.cas.eu -// +// Copyright (C) 2021, Mariusz Postol LODZ POLAND. +// +// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions +//__________________________________________________________________________________________________ using CAS.MAML.HelpTopics.Content; using System; @@ -21,92 +13,102 @@ namespace CAS.UA.Model.Designer.HelpContent { - class HelpContentHelper + internal class HelpContentHelper { #region private + private static SortedDictionary urls; + /// /// Initializes the class. /// static HelpContentHelper() { - if ( !System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() ) + if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) return; System.Net.WebClient Client = new System.Net.WebClient(); Stream stream; try { - using ( stream = Client.OpenRead( Properties.Settings.Default.HelpDocumentationAllTopicsWebAddress ) ) + using (stream = Client.OpenRead(Properties.Settings.Default.HelpDocumentationAllTopicsWebAddress)) { - if ( stream == null ) + if (stream == null) return; - urls = Topics.FromXmlStream( stream ); + urls = Topics.FromXmlStream(stream); } } - catch ( Exception ) { urls = null; } - if ( urls == null ) + catch (Exception) { urls = null; } + if (urls == null) urls = new SortedDictionary(); } - #endregion + + #endregion private #region public + public enum SelectedTopicName { None, Primary, Secondary } + /// /// Gets the help URL. /// /// Name of the topic. /// Complete Url to the proper site of help. - public static string GetHelpUrl( string PrimaryTopicName, string SecondaryTopicName, out SelectedTopicName selectedTopicName ) + public static string GetHelpUrl(string PrimaryTopicName, string SecondaryTopicName, out SelectedTopicName selectedTopicName) { string ret = string.Empty; selectedTopicName = SelectedTopicName.None; - if ( ( urls != null ) && ( urls.ContainsKey( PrimaryTopicName ) ) ) + if ((urls != null) && (urls.ContainsKey(PrimaryTopicName))) { - ret = Properties.Settings.Default.HelpDocumentationURLsuffix + urls[ PrimaryTopicName ].Url; + ret = Properties.Settings.Default.HelpDocumentationURLsuffix + urls[PrimaryTopicName].Url; selectedTopicName = SelectedTopicName.Primary; } - if ( ( urls != null ) && string.IsNullOrEmpty( ret ) && urls.ContainsKey( SecondaryTopicName ) ) + if ((urls != null) && string.IsNullOrEmpty(ret) && urls.ContainsKey(SecondaryTopicName)) { - ret = Properties.Settings.Default.HelpDocumentationURLsuffix + urls[ SecondaryTopicName ].Url; + ret = Properties.Settings.Default.HelpDocumentationURLsuffix + urls[SecondaryTopicName].Url; selectedTopicName = SelectedTopicName.Secondary; } return Properties.Settings.Default.HelpDocumentationOpcUaEbookURL + ret; } + public static void Initialize() { } - #endregion + + #endregion public #region static + /// /// Deserializes objects from XML file /// /// The stream. /// Deserialized object - internal static SortedDictionary FromXmlStream( Stream stream ) + internal static SortedDictionary FromXmlStream(Stream stream) { try { - StreamReader reader = new StreamReader( stream ); + StreamReader reader = new StreamReader(stream); Topics tpcs = null; - using ( reader ) + using (reader) { - XmlSerializer xmlSerializer = new XmlSerializer( typeof( Topics ) ); - tpcs = (Topics)xmlSerializer.Deserialize( reader ); + //TODO Use Common XML serializer to manage xml documents #228 + XmlSerializer xmlSerializer = new XmlSerializer(typeof(Topics)); + tpcs = (Topics)xmlSerializer.Deserialize(reader); } - if ( tpcs == null ) + if (tpcs == null) return null; return tpcs.CreateDictionary(); } - catch ( Exception ) + catch (Exception) { return null; } } + #endregion static } -} +} \ No newline at end of file diff --git a/ModelDesigner.DesignStudio/Wrappers/WrapperBase.cs b/ModelDesigner.DesignStudio/Wrappers/WrapperBase.cs index e416adf8..c7ab9127 100644 --- a/ModelDesigner.DesignStudio/Wrappers/WrapperBase.cs +++ b/ModelDesigner.DesignStudio/Wrappers/WrapperBase.cs @@ -1,9 +1,9 @@ -//___________________________________________________________________________________ +//__________________________________________________________________________________________________ // -// Copyright (C) 2020, Mariusz Postol LODZ POLAND. +// Copyright (C) 2021, Mariusz Postol LODZ POLAND. // -// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI -//___________________________________________________________________________________ +// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions +//__________________________________________________________________________________________________ using System.IO; using System.Xml.Serialization; @@ -65,6 +65,7 @@ protected string ModelDesignerNodeStringRepresentation get { StringWriter sw = new System.IO.StringWriter(); + //TODO Use Common XML serializer to manage xml documents #228 XmlSerializer serializer = new XmlSerializer(this.ModelDesignerNode.GetType()); serializer.Serialize(sw, this.ModelDesignerNode); return sw.ToString(); diff --git a/ModelDesigner.DesignStudio/Wrappers/WrapperTreeNode.cs b/ModelDesigner.DesignStudio/Wrappers/WrapperTreeNode.cs index 14e8a22b..047a9fe5 100644 --- a/ModelDesigner.DesignStudio/Wrappers/WrapperTreeNode.cs +++ b/ModelDesigner.DesignStudio/Wrappers/WrapperTreeNode.cs @@ -1,9 +1,9 @@ -//___________________________________________________________________________________ +//__________________________________________________________________________________________________ // // Copyright (C) 2021, Mariusz Postol LODZ POLAND. // -// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI -//___________________________________________________________________________________ +// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions +//__________________________________________________________________________________________________ using CAS.UA.Model.Designer.Properties; using CAS.UA.Model.Designer.ToForms; @@ -86,6 +86,7 @@ private static object GetModelDesignerNodeFromStringRepresentation(string modelD } if (SerializedType == null) return null; + //TODO Use Common XML serializer to manage xml documents #228 XmlSerializer serializer = new XmlSerializer(SerializedType); stringReader = new StringReader(modelDesignerNodeStringRepresentation); return serializer.Deserialize(stringReader); diff --git a/ModelDesigner.DesignStudio/Wrappers4ProperyGrid/UAModelDesignerSolutionWrapper.cs b/ModelDesigner.DesignStudio/Wrappers4ProperyGrid/UAModelDesignerSolutionWrapper.cs index 40d92088..e68cf2d9 100644 --- a/ModelDesigner.DesignStudio/Wrappers4ProperyGrid/UAModelDesignerSolutionWrapper.cs +++ b/ModelDesigner.DesignStudio/Wrappers4ProperyGrid/UAModelDesignerSolutionWrapper.cs @@ -1,9 +1,9 @@ -//___________________________________________________________________________________ +//__________________________________________________________________________________________________ // -// Copyright (C) 2020, Mariusz Postol LODZ POLAND. +// Copyright (C) 2021, Mariusz Postol LODZ POLAND. // -// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI -//___________________________________________________________________________________ +// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions +//__________________________________________________________________________________________________ using CAS.CommServer.UA.ModelDesigner.Configuration; using CAS.UA.Model.Designer.Wrappers; @@ -13,6 +13,7 @@ namespace CAS.UA.Model.Designer.Wrappers4ProperyGrid { /// /// Instance of this class is to be used as a wrapper by the to expose to the user and + //TODO Use Common XML serializer to manage xml documents #228 /// by the to save information on the solution. /// [DefaultProperty("Server")] diff --git a/ModelDesigner.ImportExport/MamlCreator.cs b/ModelDesigner.ImportExport/MamlCreator.cs index d04e18b7..a8cfe72f 100644 --- a/ModelDesigner.ImportExport/MamlCreator.cs +++ b/ModelDesigner.ImportExport/MamlCreator.cs @@ -170,6 +170,7 @@ private static bool WriteToXML( FileInfo filePathToSave, topic tpc ) { using ( StreamWriter stWriter = new StreamWriter( filePathToSave.FullName ) ) { + //TODO Use Common XML serializer to manage xml documents #228 XmlSerializer xmlSerializer = new XmlSerializer( typeof( topic ) ); XmlSerializerNamespaces xs = new XmlSerializerNamespaces(); xs.Add( "", "http://ddue.schemas.microsoft.com/authoring/2003/5" ); diff --git a/ModelDesigner.ImportExport/XmlFile.cs b/ModelDesigner.ImportExport/XmlFile.cs index c05fe8a6..bd7138af 100644 --- a/ModelDesigner.ImportExport/XmlFile.cs +++ b/ModelDesigner.ImportExport/XmlFile.cs @@ -1,17 +1,9 @@ -//_______________________________________________________________ -// Title : XmlFile - Provides static methods for serialization objects into XML documents and writing the XML document to a file. -// System : Microsoft VisualStudio 2015 / C# -// $LastChangedDate$ -// $Rev$ -// $LastChangedBy$ -// $URL$ -// $Id$ +//__________________________________________________________________________________________________ // -// Copyright (C) 2017, CAS LODZ POLAND. -// TEL: +48 608 61 98 99 -// mailto://techsupp@cas.eu -// http://www.cas.eu -//_______________________________________________________________ +// Copyright (C) 2021, Mariusz Postol LODZ POLAND. +// +// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions +//__________________________________________________________________________________________________ using System; using System.IO; @@ -25,8 +17,8 @@ namespace CAS.UA.Model.Designer.ImportExport /// public static class XmlFile { - #region public + /// /// A structure containing dat to be serialized /// @@ -36,15 +28,18 @@ public struct DataToSerialize /// The referenced by the object. /// public XmlSerializerNamespaces XmlNamespaces; + /// /// The object containing working data to be serialized and saved in the file. /// public Type4Serialization Data; + /// ///Name of the stylesheet document. /// public string StylesheetName; } + /// /// Serializes the specified and writes the XML document to a file. /// @@ -56,6 +51,7 @@ public static void WriteXmlFile(DataToSerialize dataObject, string p { WriteXmlFile(dataObject.Data, path, mode, dataObject.StylesheetName, dataObject.XmlNamespaces); } + /// /// Serializes the specified and writes the XML document to a file. /// @@ -69,6 +65,7 @@ public static void WriteXmlFile(type dataObject, string path, FileMode mod { WriteXmlFile(dataObject, path, mode, stylesheetName, null); } + /// /// Serializes the specified and writes the XML document to a file. /// @@ -86,6 +83,7 @@ public static void WriteXmlFile(type dataObject, string path, FileMode mod throw new ArgumentNullException("path"); if (dataObject == null) throw new ArgumentNullException("content"); + //TODO Use Common XML serializer to manage xml documents #228 XmlSerializer _srlzr = new XmlSerializer(typeof(type)); XmlWriterSettings _setting = new XmlWriterSettings() { @@ -101,6 +99,7 @@ public static void WriteXmlFile(type dataObject, string path, FileMode mod _srlzr.Serialize(_writer, dataObject, xmlNamespaces); } } + /// /// Serializes the specified and writes the XML document to a file. /// @@ -113,6 +112,7 @@ public static void WriteXmlFile(type dataObject, string path, FileMode mod { WriteXmlFile(dataObject, path, mode, dataObject.StylesheetName); } + /// /// Reads an XML document from the file and deserializes its content to returned object. /// @@ -126,13 +126,14 @@ public static type ReadXmlFile(string path) if (string.IsNullOrEmpty(path)) throw new ArgumentNullException("path"); type _content = default(type); + //TODO Use Common XML serializer to manage xml documents #228 XmlSerializer _srlzr = new XmlSerializer(typeof(type)); using (FileStream _docStrm = new FileStream(path, FileMode.Open, FileAccess.Read)) using (XmlReader _writer = XmlReader.Create(_docStrm)) _content = (type)_srlzr.Deserialize(_writer); return _content; } - #endregion + #endregion public } -} +} \ No newline at end of file