mirror of https://github.com/winsw/winsw
XML schema validations added
parent
74d1a540dc
commit
b38a664128
|
@ -4,6 +4,7 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using System.Xml.Schema;
|
||||||
using winsw.Configuration;
|
using winsw.Configuration;
|
||||||
using winsw.Native;
|
using winsw.Native;
|
||||||
using winsw.Util;
|
using winsw.Util;
|
||||||
|
@ -72,6 +73,15 @@ namespace winsw
|
||||||
throw new InvalidDataException(e.Message, e);
|
throw new InvalidDataException(e.Message, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ValidateXmlSchema();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
// register the base directory as environment variable so that future expansions can refer to this.
|
// register the base directory as environment variable so that future expansions can refer to this.
|
||||||
Environment.SetEnvironmentVariable("BASE", d.FullName);
|
Environment.SetEnvironmentVariable("BASE", d.FullName);
|
||||||
|
|
||||||
|
@ -95,6 +105,30 @@ namespace winsw
|
||||||
this.dom = dom;
|
this.dom = dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ValidateXmlSchema()
|
||||||
|
{
|
||||||
|
XmlReaderSettings booksettings = new XmlReaderSettings();
|
||||||
|
booksettings.Schemas.Add(null, BasePath + ".xsd");
|
||||||
|
booksettings.ValidationType = ValidationType.Schema;
|
||||||
|
booksettings.ValidationEventHandler += new ValidationEventHandler(booksSettingsValidationEventHandler);
|
||||||
|
|
||||||
|
XmlReader books = XmlReader.Create(BasePath + ".xml");
|
||||||
|
|
||||||
|
books.Read();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void booksSettingsValidationEventHandler(object sender, ValidationEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Severity == XmlSeverityType.Warning)
|
||||||
|
{
|
||||||
|
throw new Exception("Warning in validation");
|
||||||
|
}
|
||||||
|
else if (e.Severity == XmlSeverityType.Error)
|
||||||
|
{
|
||||||
|
throw new Exception("Error in validation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ReSharper disable once InconsistentNaming
|
// ReSharper disable once InconsistentNaming
|
||||||
public static ServiceDescriptor FromXML(string xml)
|
public static ServiceDescriptor FromXML(string xml)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue