diff --git a/libraries/MTConnect.NET-XML/Assets/XmlAssetCollection.cs b/libraries/MTConnect.NET-XML/Assets/XmlAssetCollection.cs index 5be2fe4c..038852a3 100644 --- a/libraries/MTConnect.NET-XML/Assets/XmlAssetCollection.cs +++ b/libraries/MTConnect.NET-XML/Assets/XmlAssetCollection.cs @@ -1,6 +1,7 @@ // Copyright (c) 2023 TrakHound Inc., All Rights Reserved. // TrakHound Inc. licenses this file to you under the MIT license. +using MTConnect.Assets.Xml.CuttingTools; using System.Collections.Generic; using System.Xml; using System.Xml.Schema; @@ -8,14 +9,19 @@ namespace MTConnect.Assets.Xml { - public class XmlAssetCollection : IXmlSerializable + //public class XmlAssetCollection : IXmlSerializable + public class XmlAssetCollection { private readonly bool _indentOutput = false; - [XmlIgnore] + [XmlArray("Assets")] + [XmlArrayItem(typeof(XmlCuttingToolAsset), ElementName = "CuttingTool")] public List Assets { get; set; } + //[XmlIgnore] + //public List Assets { get; set; } + public XmlAssetCollection() { Assets = new List(); } @@ -153,5 +159,6 @@ public XmlSchema GetSchema() } #endregion + } } \ No newline at end of file diff --git a/libraries/MTConnect.NET-XML/Assets/XmlAssetsDocument.cs b/libraries/MTConnect.NET-XML/Assets/XmlAssetsDocument.cs index d3362a03..cf67c43b 100644 --- a/libraries/MTConnect.NET-XML/Assets/XmlAssetsDocument.cs +++ b/libraries/MTConnect.NET-XML/Assets/XmlAssetsDocument.cs @@ -1,10 +1,17 @@ // Copyright (c) 2023 TrakHound Inc., All Rights Reserved. // TrakHound Inc. licenses this file to you under the MIT license. +using MTConnect.Assets.ComponentConfigurationParameters; +using MTConnect.Assets.CuttingTools; +using MTConnect.Assets.Files; +using MTConnect.Assets.QIF; +using MTConnect.Assets.RawMaterials; +using MTConnect.Assets.Xml.CuttingTools; +using MTConnect.Assets.Xml.Files; +using MTConnect.Assets.Xml.RawMaterials; using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; using System.Xml; using System.Xml.Serialization; @@ -20,8 +27,17 @@ public class XmlAssetsResponseDocument [XmlElement("Header")] public XmlAssetsHeader Header { get; set; } - [XmlElement("Assets")] - public XmlAssetCollection AssetCollection { get; set; } + + [XmlArray("Assets")] + [XmlArrayItem(typeof(XmlComponentConfigurationParametersAsset), ElementName = ComponentConfigurationParametersAsset.TypeId)] + [XmlArrayItem(typeof(XmlCuttingToolAsset), ElementName = CuttingToolAsset.TypeId)] + [XmlArrayItem(typeof(XmlFileAsset), ElementName = FileAsset.TypeId)] + [XmlArrayItem(typeof(XmlQIFDocumentWrapperAsset), ElementName = QIFDocumentWrapperAsset.TypeId)] + [XmlArrayItem(typeof(XmlRawMaterialAsset), ElementName = RawMaterialAsset.TypeId)] + public List Assets { get; set; } + + //[XmlElement("Assets")] + //public XmlAssetCollection AssetCollection { get; set; } [XmlIgnore] public Version Version { get; set; } @@ -32,13 +48,59 @@ public AssetsResponseDocument ToAssetsDocument() var assetsDocument = new AssetsResponseDocument(); assetsDocument.Header = Header.ToErrorHeader(); assetsDocument.Version = Version; + //assetsDocument.Assets = Assets; - // Add Assets - if (AssetCollection != null && !AssetCollection.Assets.IsNullOrEmpty()) + if (!Assets.IsNullOrEmpty()) { - assetsDocument.Assets = AssetCollection.Assets.ToList(); + var assets = new List(); + + foreach (var asset in Assets) + { + // ComponentConfigurationParameters + if (asset.GetType() == typeof(XmlComponentConfigurationParametersAsset)) + { + var componentConfigurationParametersAsset = ((XmlComponentConfigurationParametersAsset)asset).ToAsset(); + if (componentConfigurationParametersAsset != null) assets.Add(componentConfigurationParametersAsset); + } + + // CuttingTool + if (asset.GetType() == typeof(XmlCuttingToolAsset)) + { + var cuttingToolAsset = ((XmlCuttingToolAsset)asset).ToAsset(); + if (cuttingToolAsset != null) assets.Add(cuttingToolAsset); + } + + // File + if (asset.GetType() == typeof(XmlFileAsset)) + { + var fileAsset = ((XmlFileAsset)asset).ToAsset(); + if (fileAsset != null) assets.Add(fileAsset); + } + + // QIF + if (asset.GetType() == typeof(XmlQIFDocumentWrapperAsset)) + { + var qifAsset = ((XmlQIFDocumentWrapperAsset)asset).ToAsset(); + if (qifAsset != null) assets.Add(qifAsset); + } + + // RawMaterial + if (asset.GetType() == typeof(XmlRawMaterialAsset)) + { + var rawMaterialAsset = ((XmlRawMaterialAsset)asset).ToAsset(); + if (rawMaterialAsset != null) assets.Add(rawMaterialAsset); + } + } + + assetsDocument.Assets = assets; } - else assetsDocument.Assets = new List(); + + //// Add Assets + //if (AssetCollection != null && !AssetCollection.Assets.IsNullOrEmpty()) + //{ + // assetsDocument.Assets = AssetCollection.Assets.ToList(); + //} + //else assetsDocument.Assets = new List(); return assetsDocument; } @@ -54,11 +116,12 @@ public static AssetsResponseDocument FromXml(byte[] xmlBytes) var bytes = XmlFunctions.SanitizeBytes(xmlBytes); var xml = Encoding.UTF8.GetString(bytes); - xml = xml.Trim(); - var version = MTConnectVersion.Get(xml); - using (var textReader = new StringReader(Namespaces.Clear(xml))) + xml = xml.Trim(); + xml = Namespaces.Clear(xml); + + using (var textReader = new StringReader(xml)) { using (var xmlReader = XmlReader.Create(textReader)) {