diff --git a/VECTO.sln b/VECTO.sln index b3f181895f9cdbecd9cc757c279fcc333b2852d1..0ba2c4ba457e42dcd52f30f4f8686d545440ef71 100644 --- a/VECTO.sln +++ b/VECTO.sln @@ -343,10 +343,10 @@ Global {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Debug|Any CPU.Build.0 = Debug|Any CPU {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Debug|x64.ActiveCfg = Debug|Any CPU {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Debug|x86.ActiveCfg = Debug|Any CPU - {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Deploy|Any CPU.ActiveCfg = Deploy|Any CPU - {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Deploy|Any CPU.Build.0 = Deploy|Any CPU - {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Deploy|x64.ActiveCfg = Deploy|Any CPU - {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Deploy|x86.ActiveCfg = Deploy|Any CPU + {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU + {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Deploy|Any CPU.Build.0 = Debug|Any CPU + {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Deploy|x64.ActiveCfg = Debug|Any CPU + {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Deploy|x86.ActiveCfg = Debug|Any CPU {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Release|Any CPU.ActiveCfg = Release|Any CPU {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Release|Any CPU.Build.0 = Release|Any CPU {512C2CD1-E5BE-4F6B-943B-2BFA7E0CBD64}.Release|x64.ActiveCfg = Release|Any CPU @@ -361,9 +361,10 @@ Global {D959CB7C-F514-4F5E-9C33-684D0012474B}.Debug|Any CPU.Build.0 = Debug|Any CPU {D959CB7C-F514-4F5E-9C33-684D0012474B}.Debug|x64.ActiveCfg = Debug|Any CPU {D959CB7C-F514-4F5E-9C33-684D0012474B}.Debug|x86.ActiveCfg = Debug|Any CPU - {D959CB7C-F514-4F5E-9C33-684D0012474B}.Deploy|Any CPU.ActiveCfg = Deploy|Any CPU - {D959CB7C-F514-4F5E-9C33-684D0012474B}.Deploy|x64.ActiveCfg = Deploy|Any CPU - {D959CB7C-F514-4F5E-9C33-684D0012474B}.Deploy|x86.ActiveCfg = Deploy|Any CPU + {D959CB7C-F514-4F5E-9C33-684D0012474B}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU + {D959CB7C-F514-4F5E-9C33-684D0012474B}.Deploy|Any CPU.Build.0 = Debug|Any CPU + {D959CB7C-F514-4F5E-9C33-684D0012474B}.Deploy|x64.ActiveCfg = Debug|Any CPU + {D959CB7C-F514-4F5E-9C33-684D0012474B}.Deploy|x86.ActiveCfg = Debug|Any CPU {D959CB7C-F514-4F5E-9C33-684D0012474B}.Release|Any CPU.ActiveCfg = Release|Any CPU {D959CB7C-F514-4F5E-9C33-684D0012474B}.Release|Any CPU.Build.0 = Release|Any CPU {D959CB7C-F514-4F5E-9C33-684D0012474B}.Release|x64.ActiveCfg = Release|Any CPU @@ -378,9 +379,10 @@ Global {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Debug|Any CPU.Build.0 = Debug|Any CPU {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Debug|x64.ActiveCfg = Debug|Any CPU {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Debug|x86.ActiveCfg = Debug|Any CPU - {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Deploy|Any CPU.ActiveCfg = Deploy|Any CPU - {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Deploy|x64.ActiveCfg = Deploy|Any CPU - {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Deploy|x86.ActiveCfg = Deploy|Any CPU + {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU + {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Deploy|Any CPU.Build.0 = Debug|Any CPU + {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Deploy|x64.ActiveCfg = Debug|Any CPU + {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Deploy|x86.ActiveCfg = Debug|Any CPU {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Release|Any CPU.ActiveCfg = Release|Any CPU {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Release|Any CPU.Build.0 = Release|Any CPU {41314A40-AB3E-4F43-B1A4-58443F4014F2}.Release|x64.ActiveCfg = Release|Any CPU @@ -395,9 +397,10 @@ Global {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Debug|Any CPU.Build.0 = Debug|Any CPU {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Debug|x64.ActiveCfg = Debug|Any CPU {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Debug|x86.ActiveCfg = Debug|Any CPU - {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Deploy|Any CPU.ActiveCfg = Deploy|Any CPU - {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Deploy|x64.ActiveCfg = Deploy|Any CPU - {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Deploy|x86.ActiveCfg = Deploy|Any CPU + {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU + {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Deploy|Any CPU.Build.0 = Debug|Any CPU + {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Deploy|x64.ActiveCfg = Debug|Any CPU + {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Deploy|x86.ActiveCfg = Debug|Any CPU {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Release|Any CPU.ActiveCfg = Release|Any CPU {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Release|Any CPU.Build.0 = Release|Any CPU {749F150A-F974-46DC-A1E2-F4153C54FC0D}.Release|x64.ActiveCfg = Release|Any CPU diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/AbstractDeclarationXMLComponentDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/AbstractDeclarationXMLComponentDataProvider.cs index 84b7c3e0bf3a96c85bffcc62d082261eeeca3b8b..915c604e57fb1127bae0d6c2e65058e7c94ce4d6 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/AbstractDeclarationXMLComponentDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/AbstractDeclarationXMLComponentDataProvider.cs @@ -29,159 +29,159 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Collections.Generic; -using System.Linq; -using System.Xml; -using System.Xml.XPath; -using TUGraz.VectoCommon.Exceptions; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Configuration; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration -{ - public abstract class AbstractDeclarationXMLComponentDataProvider - { - protected readonly XMLDeclarationInputDataProvider InputData; - protected XPathNavigator Navigator; - - protected string XBasePath = ""; - protected XmlNamespaceManager Manager; - - - protected readonly string VehiclePath; - - protected XPathHelper Helper; - - protected AbstractDeclarationXMLComponentDataProvider() {} - - protected AbstractDeclarationXMLComponentDataProvider(XMLDeclarationInputDataProvider xmlInputDataProvider) - { - InputData = xmlInputDataProvider; - Navigator = xmlInputDataProvider.Document.CreateNavigator(); - Manager = new XmlNamespaceManager(Navigator.NameTable ?? new NameTable()); - Helper = new XPathHelper(ExecutionMode.Declaration); - Helper.AddNamespaces(Manager); - - SourceType = DataSourceType.Embedded; - Source = ""; - - VehiclePath = Helper.QueryAbs( - Helper.NSPrefix(XMLNames.VectoInputDeclaration, Constants.XML.RootNSPrefix), - XMLNames.Component_Vehicle - ); - } - - public string Source { get; protected set; } - - public DataSourceType SourceType { get; protected set; } - - public virtual bool SavedInDeclarationMode - { - get { return true; } - } - - public virtual string Manufacturer - { - get { return GetElementValue(XMLNames.Component_Manufacturer); } - } - - public virtual string Model - { - get { return GetElementValue(XMLNames.Component_Model); } - } - - - public virtual string Date - { - get { return GetElementValue(XMLNames.Component_Date); } - } - - public virtual CertificationMethod CertificationMethod - { - get { - var value = GetElementValue(XMLNames.Component_CertificationMethod); - return value.ParseEnum<CertificationMethod>(); - } - } - - public virtual string CertificationNumber - { - get { return GetElementValue(XMLNames.Component_CertificationNumber); } - } - - public virtual string DigestValue - { - get { return GetElementValue("..//*[local-name()='DigestValue']"); } - } - - - protected bool ElementExists(string relativePath) - { - var path = Helper.Query(XBasePath, relativePath.Any() ? relativePath : null); - //new StringBuilder(XBasePath + (relativePath.Any() ? "/" + relativePath : "")); - - var node = Navigator.SelectSingleNode(path, Manager); - return node != null; - } - - protected string GetElementValue(string relativePath) - { - var path = Helper.Query(XBasePath, relativePath.Any() ? relativePath : null); - - var node = Navigator.SelectSingleNode(path, Manager); - if (node == null) { - throw new VectoException("Node {0} not found in input data", path); - } - return node.InnerXml; - } - - protected double GetDoubleElementValue(string relativePath) - { - return GetElementValue(relativePath).ToDouble(); - } - - protected string GetAttributeValue(string relativePath, string attrName) - { - var nodes = - Navigator.Select(string.IsNullOrWhiteSpace(relativePath) ? XBasePath : Helper.Query(XBasePath, relativePath), - Manager); - if (nodes.Count == 0) { - return null; - } - nodes.MoveNext(); - return nodes.Current.GetAttribute(attrName, ""); - } - - protected TableData ReadTableData(Dictionary<string, string> attributeMapping, string relativePath, - XPathNavigator origin = null) - { - var startNode = origin ?? Navigator.SelectSingleNode(XBasePath, Manager); - if (startNode == null) { - throw new VectoException("start node for base-path {0} not found!", XBasePath); - } - var table = new TableData(); - foreach (var entry in attributeMapping) { - if (startNode.Select(Helper.Query(relativePath, "@" + entry.Value), Manager).Count == 0) { - continue; - } - table.Columns.Add(entry.Key); - } - var nodes = startNode.Select(relativePath, Manager); - while (nodes.MoveNext()) { - var row = table.NewRow(); - foreach (var attribute in attributeMapping) { - if (nodes.Current.SelectSingleNode("@" + attribute.Value) != null) { - row[attribute.Key] = nodes.Current.GetAttribute(attribute.Value, ""); - } - } - table.Rows.Add(row); - } - - return table; - } - } -} \ No newline at end of file +using System.Collections.Generic; +using System.Linq; +using System.Xml; +using System.Xml.XPath; +using TUGraz.VectoCommon.Exceptions; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Configuration; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration +{ + public abstract class AbstractDeclarationXMLComponentDataProvider + { + protected readonly XMLDeclarationInputDataProvider InputData; + protected XPathNavigator Navigator; + + protected string XBasePath = ""; + protected XmlNamespaceManager Manager; + + + protected readonly string VehiclePath; + + protected XPathHelper Helper; + + protected AbstractDeclarationXMLComponentDataProvider() {} + + protected AbstractDeclarationXMLComponentDataProvider(XMLDeclarationInputDataProvider xmlInputDataProvider) + { + InputData = xmlInputDataProvider; + Navigator = xmlInputDataProvider.Document.CreateNavigator(); + Manager = new XmlNamespaceManager(Navigator.NameTable ?? new NameTable()); + Helper = new XPathHelper(ExecutionMode.Declaration); + Helper.AddNamespaces(Manager); + + SourceType = DataSourceType.Embedded; + Source = ""; + + VehiclePath = Helper.QueryAbs( + Helper.NSPrefix(XMLNames.VectoInputDeclaration, Constants.XML.RootNSPrefix), + XMLNames.Component_Vehicle + ); + } + + public string Source { get; protected set; } + + public DataSourceType SourceType { get; protected set; } + + public virtual bool SavedInDeclarationMode + { + get { return true; } + } + + public virtual string Manufacturer + { + get { return GetElementValue(XMLNames.Component_Manufacturer); } + } + + public virtual string Model + { + get { return GetElementValue(XMLNames.Component_Model); } + } + + + public virtual string Date + { + get { return GetElementValue(XMLNames.Component_Date); } + } + + public virtual CertificationMethod CertificationMethod + { + get { + var value = GetElementValue(XMLNames.Component_CertificationMethod); + return value.ParseEnum<CertificationMethod>(); + } + } + + public virtual string CertificationNumber + { + get { return GetElementValue(XMLNames.Component_CertificationNumber); } + } + + public virtual string DigestValue + { + get { return GetElementValue("..//*[local-name()='DigestValue']"); } + } + + + protected bool ElementExists(string relativePath) + { + var path = Helper.Query(XBasePath, relativePath.Any() ? relativePath : null); + //new StringBuilder(XBasePath + (relativePath.Any() ? "/" + relativePath : "")); + + var node = Navigator.SelectSingleNode(path, Manager); + return node != null; + } + + protected string GetElementValue(string relativePath) + { + var path = Helper.Query(XBasePath, relativePath.Any() ? relativePath : null); + + var node = Navigator.SelectSingleNode(path, Manager); + if (node == null) { + throw new VectoException("Node {0} not found in input data", path); + } + return node.InnerXml; + } + + protected double GetDoubleElementValue(string relativePath) + { + return GetElementValue(relativePath).ToDouble(); + } + + protected string GetAttributeValue(string relativePath, string attrName) + { + var nodes = + Navigator.Select(string.IsNullOrWhiteSpace(relativePath) ? XBasePath : Helper.Query(XBasePath, relativePath), + Manager); + if (nodes.Count == 0) { + return null; + } + nodes.MoveNext(); + return nodes.Current.GetAttribute(attrName, ""); + } + + protected TableData ReadTableData(Dictionary<string, string> attributeMapping, string relativePath, + XPathNavigator origin = null) + { + var startNode = origin ?? Navigator.SelectSingleNode(XBasePath, Manager); + if (startNode == null) { + throw new VectoException("start node for base-path {0} not found!", XBasePath); + } + var table = new TableData(); + foreach (var entry in attributeMapping) { + if (startNode.Select(Helper.Query(relativePath, "@" + entry.Value), Manager).Count == 0) { + continue; + } + table.Columns.Add(entry.Key); + } + var nodes = startNode.Select(relativePath, Manager); + while (nodes.MoveNext()) { + var row = table.NewRow(); + foreach (var attribute in attributeMapping) { + if (nodes.Current.SelectSingleNode("@" + attribute.Value) != null) { + row[attribute.Key] = nodes.Current.GetAttribute(attribute.Value, ""); + } + } + table.Rows.Add(row); + } + + return table; + } + } +} diff --git a/VectoCore/VectoCore/Utils/RessourceHelper.cs b/VectoCore/VectoCore/Utils/RessourceHelper.cs index 93f200613416e46fc6a89d81aec0b0f4dbcdcf25..83c1ff6493727a2aaf66afcfc1a39a7892b03264 100644 --- a/VectoCore/VectoCore/Utils/RessourceHelper.cs +++ b/VectoCore/VectoCore/Utils/RessourceHelper.cs @@ -29,41 +29,41 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System; -using System.IO; -using System.Reflection; -using TUGraz.VectoCommon.Exceptions; - -namespace TUGraz.VectoCore.Utils -{ - public static class RessourceHelper - { - public static Stream ReadStream(string resourceName) - { - var assembly = Assembly.GetExecutingAssembly(); - var resource = assembly.GetManifestResourceStream(resourceName); - if (resource == null) { - throw new VectoException("Resource file not found: " + resourceName); - } - return resource; - } - - public enum ResourceType - { - XMLSchema = 1, - } - - public static Stream LoadResourceAsStream(ResourceType type, string resourceName) - { - string resourceBase; - switch (type) { - case ResourceType.XMLSchema: - resourceBase = "TUGraz.VectoCore.Resources.XSD."; - break; - default: - throw new ArgumentOutOfRangeException("type", type, null); - } - return ReadStream(resourceBase + resourceName); - } - } -} \ No newline at end of file +using System; +using System.IO; +using System.Reflection; +using TUGraz.VectoCommon.Exceptions; + +namespace TUGraz.VectoCore.Utils +{ + public static class RessourceHelper + { + public static Stream ReadStream(string resourceName) + { + var assembly = Assembly.GetExecutingAssembly(); + var resource = assembly.GetManifestResourceStream(resourceName); + if (resource == null) { + throw new VectoException("Resource file not found: " + resourceName); + } + return resource; + } + + public enum ResourceType + { + XMLSchema = 1, + } + + public static Stream LoadResourceAsStream(ResourceType type, string resourceName) + { + string resourceBase; + switch (type) { + case ResourceType.XMLSchema: + resourceBase = "TUGraz.VectoCore.Resources.XSD."; + break; + default: + throw new ArgumentOutOfRangeException("type", type, null); + } + return ReadStream(resourceBase + resourceName); + } + } +}