Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 7c050d6e authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

add supported version numbers to xml validator

parent 605fde57
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
using System.Xml.Schema; using System.Xml.Schema;
...@@ -46,12 +47,12 @@ namespace TUGraz.VectoCore.Utils ...@@ -46,12 +47,12 @@ namespace TUGraz.VectoCore.Utils
private bool _valid; private bool _valid;
private readonly XmlDocument _doc; private readonly XmlDocument _doc;
private static Dictionary<XmlDocumentType, string> schemaFilenames = new Dictionary<XmlDocumentType, string>() { private static Dictionary<XmlDocumentType, Tuple<string, string[]> > schemaFilenames = new Dictionary<XmlDocumentType, Tuple<string, string[]>>() {
{XmlDocumentType.DeclarationJobData, "VectoInput{0}.xsd" }, {XmlDocumentType.DeclarationJobData, Tuple.Create("VectoInput{0}.xsd", new [] {"1.0"}) },
{XmlDocumentType.DeclarationComponentData, "VectoComponent{0}.xsd" }, {XmlDocumentType.DeclarationComponentData, Tuple.Create("VectoComponent{0}.xsd", new [] {"1.0"}) },
{XmlDocumentType.EngineeringData, "VectoEngineeringInput{0}.xsd" }, {XmlDocumentType.EngineeringData, Tuple.Create("VectoEngineeringInput{0}.xsd", new [] {"0.7"}) },
{XmlDocumentType.ManufacturerReport, "VectoOutputManufacturer{0}.xsd" }, {XmlDocumentType.ManufacturerReport, Tuple.Create("VectoOutputManufacturer{0}.xsd", new [] {"0.4"}) },
{ XmlDocumentType.CustomerReport , "VectoOutputCustomer{0}.xsd"}, { XmlDocumentType.CustomerReport , Tuple.Create("VectoOutputCustomer{0}.xsd", new [] {"0.4"})},
}; };
private XMLValidator(Action<bool> resultaction, Action<XmlSeverityType, ValidationEvent> validationErrorAction) private XMLValidator(Action<bool> resultaction, Action<XmlSeverityType, ValidationEvent> validationErrorAction)
...@@ -108,7 +109,10 @@ namespace TUGraz.VectoCore.Utils ...@@ -108,7 +109,10 @@ namespace TUGraz.VectoCore.Utils
continue; continue;
} }
Stream resource; Stream resource;
var schemaFile = GetSchemaFilename(entry, string.IsNullOrWhiteSpace(version) ? "" : "."+ version); var schemaFile = GetSchemaFilename(entry, version);
if (schemaFile == null) {
continue;
}
try { try {
resource= RessourceHelper.LoadResourceAsStream(RessourceHelper.ResourceType.XMLSchema, schemaFile); resource= RessourceHelper.LoadResourceAsStream(RessourceHelper.ResourceType.XMLSchema, schemaFile);
} catch (Exception e) { } catch (Exception e) {
...@@ -126,7 +130,8 @@ namespace TUGraz.VectoCore.Utils ...@@ -126,7 +130,8 @@ namespace TUGraz.VectoCore.Utils
if (!schemaFilenames.ContainsKey(type)) { if (!schemaFilenames.ContainsKey(type)) {
throw new Exception(string.Format("Invalid argument {0} - only use single flags", type)); throw new Exception(string.Format("Invalid argument {0} - only use single flags", type));
} }
return string.Format(schemaFilenames[type], version); var entry = schemaFilenames[type];
return !entry.Item2.Contains(version) ? null : string.Format(entry.Item1, string.IsNullOrWhiteSpace(version) ? "" : "." + version);
} }
[Flags] [Flags]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment