Skip to content

Commit

Permalink
Use Common XML serializer to manage xml documents #228
Browse files Browse the repository at this point in the history
- fixes #228
  • Loading branch information
mpostol committed Jun 26, 2021
1 parent 3086c57 commit 93923ae
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void BuildTest()
Mock<IGraphicalUserInterface> _guiuMocck = new Mock<IGraphicalUserInterface>();
_guiuMocck.SetupGet(x => x.MessageBoxShowWarningAskYN).Returns(() => (t, c) => true);
UAModelDesignerProject _projectDescriptor = _projectDescriptor = UAModelDesignerProject.CreateEmpty("BoilerType");
_projectDescriptor.FileName = @"DemoConfiguration\BoilerType.BuildTest.xml";
_projectDescriptor.FileName = @"DemoConfiguration\BoilerType.xml";
IProjectConfigurationManagement _newItemUnderTest = ProjectConfigurationManagement.ImportModelDesign(_solutionMock.Object, _guiuMocck.Object, _projectDescriptor);
List<string> _log = new List<string>();
_newItemUnderTest.Build(x => _log.Add(x));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AssemblyInfo.cs</LastGenOutput>
</Content>
<None Include="TestData\DemoConfiguration\BoilerType.BuildTest.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestData\DemoConfiguration\BoilerType.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
//
//___________________________________________________________________________________

using CAS.UA.Model.Designer.ImportExport;
using CAS.UA.Model.Designer.Solution;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using UAOOI.Common.Infrastructure.Serializers;

namespace CAS.UA.Model.Designer.Wrappers4PropertyGrid
{
Expand Down
10 changes: 1 addition & 9 deletions ModelDesigner.DesignStudio/HelpContent/HelpContentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

namespace CAS.UA.Model.Designer.HelpContent
{
Expand Down Expand Up @@ -91,14 +90,7 @@ internal static SortedDictionary<string, TopicNode> FromXmlStream(Stream stream)
{
try
{
StreamReader reader = new StreamReader(stream);
Topics tpcs = null;
using (reader)
{
//TODO Use Common XML serializer to manage xml documents #228
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Topics));
tpcs = (Topics)xmlSerializer.Deserialize(reader);
}
Topics tpcs = UAOOI.Common.Infrastructure.Serializers.XmlFile.ReadXmlFile<Topics>(stream);
if (tpcs == null)
return null;
return tpcs.CreateDictionary();
Expand Down
28 changes: 10 additions & 18 deletions ModelDesigner.DesignStudio/IO/ProjectConfigurationManagement.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//___________________________________________________________________________________
//__________________________________________________________________________________________________
//
// 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.IO;
using CAS.CommServer.UA.ModelDesigner.Configuration.UserInterface;
using CAS.UA.Model.Designer.ImportExport;
using CAS.UA.Model.Designer.Properties;
using CAS.UA.Model.Designer.Solution;
using System;
Expand Down Expand Up @@ -60,25 +59,18 @@ private static string ReplaceTokenAndReturnFullPath(string fileNameToBeProcessed

#endregion private

#region TypeGenericConfigurationManagement<OpcUaModelCompiler.ModelDesign>
#region TypeGenericConfigurationManagement

protected override string PrepareDataToSerialize()
/// <summary>
/// Gets the name of the stylesheet.
/// </summary>
/// <returns>name of the stylesheet is if applicable</returns>
protected override string GetStylesheetName()
{
return String.Empty;
}

//TODO Use Common XML serializer to manage xml documents #228

//protected override XmlFile.DataToSerialize<OpcUaModelCompiler.ModelDesign> PrepareDataToSerialize(OpcUaModelCompiler.ModelDesign modelDesign)
//{
// XmlFile.DataToSerialize<OpcUaModelCompiler.ModelDesign> _config;
// _config.Data = modelDesign;
// _config.XmlNamespaces = null;
// _config.StylesheetName = "OPCUAModelDesign.xslt";
// return _config;
//}

#endregion TypeGenericConfigurationManagement<OpcUaModelCompiler.ModelDesign>
#endregion TypeGenericConfigurationManagement

#region constructor

Expand Down
16 changes: 5 additions & 11 deletions ModelDesigner.DesignStudio/IO/SolutionConfigurationManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,15 @@ internal static void SetupFileDialog(IFileDialog dialog)

#region TypeGenericConfigurationManagement

protected override string PrepareDataToSerialize()
/// <summary>
/// Gets the name of the stylesheet.
/// </summary>
/// <returns>name of the stylesheet is if applicable</returns>
protected override string GetStylesheetName()
{
return "UAModelDesignerSolution.xslt";
}

//TODO Use Common XML serializer to manage xml documents #228
//protected override XmlFile.DataToSerialize<UAModelDesignerSolution> PrepareDataToSerialize(UAModelDesignerSolution solutionDesription)
//{
// XmlFile.DataToSerialize<UAModelDesignerSolution> _config;
// _config.Data = solutionDesription;
// _config.XmlNamespaces = null;
// _config.StylesheetName = "UAModelDesignerSolution.xslt";
// return _config;
//}

#endregion TypeGenericConfigurationManagement

#region ISolutionConfigurationManagement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//___________________________________________________________________________________
//__________________________________________________________________________________________________
//
// 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.UserInterface;
using CAS.UA.Model.Designer.ImportExport;
using CAS.UA.Model.Designer.Properties;
using System;
using System.IO;
using UAOOI.Common.Infrastructure.Serializers;

namespace CAS.UA.Model.Designer.IO
{
Expand Down Expand Up @@ -74,7 +75,7 @@ protected void Save(Type4Serialization modelDesign)
{
try
{
string stylesheetName = PrepareDataToSerialize();
string stylesheetName = GetStylesheetName();
GraphicalUserInterface.UseWaitCursor = true;
BeforeWrite?.Invoke(this, new StringEventArgs(DefaultFileName));
UAOOI.Common.Infrastructure.Serializers.XmlFile.WriteXmlFile<Type4Serialization>(modelDesign, DefaultFileName, FileMode.Create, stylesheetName);
Expand All @@ -89,8 +90,12 @@ protected void Save(Type4Serialization modelDesign)
GraphicalUserInterface.UseWaitCursor = false;
}
}
//TODO Use Common XML serializer to manage xml documents #228
protected abstract string PrepareDataToSerialize();

/// <summary>
/// Gets the name of the stylesheet.
/// </summary>
/// <returns>name of the stylesheet is if applicable</returns>
protected abstract string GetStylesheetName();

/// <summary>
/// Reads the configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using UAOOI.Common.Infrastructure.Serializers;

namespace CAS.UA.Model.Designer.Solution
{
/// <summary>
/// Class UAModelDesignerSolution.
/// </summary>
public partial class UAModelDesignerSolution : UAOOI.Common.Infrastructure.Serializers.INamespaces
public partial class UAModelDesignerSolution : INamespaces
{
/// <summary>
/// Creates an empty solution model.
Expand All @@ -35,7 +36,6 @@ internal static UAModelDesignerSolution CreateEmptyModel(string solutionName)

public IEnumerable<XmlQualifiedName> GetNamespaces()
{
//TODO Use Common XML serializer to manage xml documents #228
return new List<XmlQualifiedName>();
}

Expand Down
6 changes: 3 additions & 3 deletions ModelDesigner.DesignStudio/Wrappers/WrapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//__________________________________________________________________________________________________

using System.IO;
using System.Windows;
using System.Xml.Serialization;

namespace CAS.UA.Model.Designer.Wrappers
Expand Down Expand Up @@ -57,15 +58,14 @@ public WrapperBase(type child)
public override void MenuItemCopy_Action()
{
base.MenuItemCopy_Action();
System.Windows.Forms.Clipboard.SetText(this.ModelDesignerNodeStringRepresentation);
Clipboard.SetText(this.ModelDesignerNodeStringRepresentation);
}

protected string ModelDesignerNodeStringRepresentation
{
get
{
StringWriter sw = new System.IO.StringWriter();
//TODO Use Common XML serializer to manage xml documents #228
StringWriter sw = new StringWriter();
XmlSerializer serializer = new XmlSerializer(this.ModelDesignerNode.GetType());
serializer.Serialize(sw, this.ModelDesignerNode);
return sw.ToString();
Expand Down
38 changes: 20 additions & 18 deletions ModelDesigner.DesignStudio/Wrappers/WrapperTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,30 @@ private static object GetModelDesignerNodeFromStringRepresentation(string modelD
return null;
try
{
StringReader stringReader = new StringReader(modelDesignerNodeStringRepresentation);
XmlTextReader xmlTextReader = new XmlTextReader(stringReader)
Type SerializedType = null;
using (StringReader stringReader = new StringReader(modelDesignerNodeStringRepresentation))
{
WhitespaceHandling = WhitespaceHandling.None
};
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(xmlTextReader);
if (xmlDocument.DocumentElement == null)
return null;
string SerializedTypeAsString = typeof(OpcUaModelCompiler.NodeDesign).Namespace + "." + xmlDocument.DocumentElement.Name;
Type SerializedType = Type.GetType(SerializedTypeAsString);
if (SerializedType == null)
{
SerializedTypeAsString += ", OpcUaModelCompiler"; // we have to try also load to from different assembly
XmlTextReader xmlTextReader = new XmlTextReader(stringReader)
{
WhitespaceHandling = WhitespaceHandling.None
};
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(xmlTextReader);
if (xmlDocument.DocumentElement == null)
return null;
string SerializedTypeAsString = typeof(OpcUaModelCompiler.NodeDesign).Namespace + "." + xmlDocument.DocumentElement.Name;
SerializedType = Type.GetType(SerializedTypeAsString);
if (SerializedType == null)
{
SerializedTypeAsString += ", OpcUaModelCompiler"; // we have to try also load to from different assembly
SerializedType = Type.GetType(SerializedTypeAsString);
}
if (SerializedType == null)
return null;
}
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);
using (StringReader reader = new StringReader(modelDesignerNodeStringRepresentation))
return serializer.Deserialize(reader);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
namespace CAS.UA.Model.Designer.Wrappers4ProperyGrid
{
/// <summary>
/// Instance of this class is to be used as a wrapper by the <see cref="PropertyGrid"/> to expose to the user and
//TODO Use Common XML serializer to manage xml documents #228
/// by the <see cref="XmlSerializer"/> to save information on the solution.
/// Instance of this class is to be used as a wrapper to expose to the user
/// </summary>
[DefaultProperty("Server")]
internal class UAModelDesignerSolutionWrapper : NameWithEventBase<ISolutionTreeNodeUI>, IViewModel
Expand Down
9 changes: 5 additions & 4 deletions ModelDesigner.ImportExport.UnitTests/ArgumentUnitTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//___________________________________________________________________________________
//__________________________________________________________________________________________________
//
// 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.Common;
using CAS.UA.Common.Types;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using UAOOI.Common.Infrastructure.Serializers;

namespace CAS.UA.Model.Designer.ImportExport.UT
{
Expand Down
7 changes: 4 additions & 3 deletions ModelDesigner.ImportExport.UnitTests/NodeSetUnitTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//___________________________________________________________________________________
//__________________________________________________________________________________________________
//
// 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 Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UAOOI.Common.Infrastructure.Serializers;
using UAOOI.SemanticData.BuildingErrorsHandling;
using UAOOI.SemanticData.UAModelDesignExport.XML;

Expand Down
25 changes: 25 additions & 0 deletions ModelDesigner.ImportExport/ExportingStructures/topic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//__________________________________________________________________________________________________
//
// 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.Collections.Generic;
using System.Xml;
using UAOOI.Common.Infrastructure.Serializers;

namespace CAS.UA.Model.Designer.ImportExport.ExportingStructures
{
public partial class topic : INamespaces
{
public IEnumerable<XmlQualifiedName> GetNamespaces()
{
List<XmlQualifiedName> nsList = new List<XmlQualifiedName>
{
new XmlQualifiedName("", "http://ddue.schemas.microsoft.com/authoring/2003/5")
};
return nsList;
}
}
}
Loading

0 comments on commit 93923ae

Please sign in to comment.