From 5821bd9b921b8c5dcd66486bf915e1bd3dd37a4f Mon Sep 17 00:00:00 2001 From: Buddhika Chathuranga Date: Mon, 13 Apr 2020 09:40:50 +0530 Subject: [PATCH] XML Schema embedded --- src/Core/WinSWCore/ServiceDescriptor.cs | 17 ++++++++++++++--- src/Core/WinSWCore/WinSWCore.csproj | 8 ++++++++ src/Core/WinSWCore/XMLSchema.xsd | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/Core/WinSWCore/XMLSchema.xsd diff --git a/src/Core/WinSWCore/ServiceDescriptor.cs b/src/Core/WinSWCore/ServiceDescriptor.cs index e62c6bf..4e3a25e 100755 --- a/src/Core/WinSWCore/ServiceDescriptor.cs +++ b/src/Core/WinSWCore/ServiceDescriptor.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Reflection; using System.Text; using System.Xml; using System.Xml.Schema; @@ -104,13 +105,23 @@ namespace winsw { XmlReaderSettings settings = new XmlReaderSettings(); + Assembly a = Assembly.GetExecutingAssembly(); + string[] resourceNames = this.GetType().Assembly.GetManifestResourceNames(); + try { - settings.Schemas.Add(null, BasePath + ".xsd"); + using (Stream schemaStream = a.GetManifestResourceStream("winsw.XMLSchema.xsd")) + { + using (XmlReader schemaReader = XmlReader.Create(schemaStream)) + { + settings.Schemas.Add(null, schemaReader); + } + + } } - catch (FileNotFoundException) + catch(Exception e) { - throw new FileNotFoundException("XSD file not found"); + throw e; } settings.ValidationType = ValidationType.Schema; diff --git a/src/Core/WinSWCore/WinSWCore.csproj b/src/Core/WinSWCore/WinSWCore.csproj index f36eb56..6bfba5a 100644 --- a/src/Core/WinSWCore/WinSWCore.csproj +++ b/src/Core/WinSWCore/WinSWCore.csproj @@ -9,6 +9,10 @@ true + + + + @@ -44,4 +48,8 @@ + + + + diff --git a/src/Core/WinSWCore/XMLSchema.xsd b/src/Core/WinSWCore/XMLSchema.xsd new file mode 100644 index 0000000..26b3f0d --- /dev/null +++ b/src/Core/WinSWCore/XMLSchema.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + \ No newline at end of file