private static Version GetLayoutVersion(XDocument doc) { XAttribute versionAttr = doc.Root.Attribute(Parameters.Version); if (versionAttr == null) { return(Cascara.AssemblyVersion); } if (!Version.TryParse(versionAttr.Value, out Version ver)) { string msg = Resources.LayoutExceptionMalformattedLayoutVersion; throw LayoutScriptException.Create <LayoutScriptException>(null, new XmlSourceEntity(versionAttr), msg, versionAttr.Value); } return(ver); }
public static new XmlLayoutScript Parse(string source) { // Parse XML document string XDocument doc; try { doc = XDocument.Parse(source, LoadOptions.SetLineInfo); } catch (XmlException e) { string msg = e.Message; throw LayoutScriptException.Create <LayoutScriptException>(null, e, null, msg); } // Create and return layout return(CreateXmlBinaryLayout(doc, null)); }
private static XmlLayoutScript CreateXmlBinaryLayout(XDocument doc, string sourcePath) { // Ensure root element is named correctly if (doc.Root.Name.LocalName != Keywords.XmlDocumentRoot) { string msg = Resources.SyntaxExceptionXmlInvalidRootElement; throw LayoutScriptException.Create <SyntaxException>(null, new XmlSourceEntity(doc.Root), msg, Keywords.XmlDocumentRoot); } // Read version Version ver = GetLayoutVersion(doc); // Ensure root element is not empty if (!doc.Root.HasElements) { string msg = Resources.SyntaxExceptionEmptyLayout; throw LayoutScriptException.Create <SyntaxException>(null, new XmlSourceEntity(doc.Root), msg); } // Create and return layout object return(new XmlLayoutScript(doc, ver, sourcePath)); }
public static new XmlLayoutScript Load(string path) { // Load XML document XDocument doc; try { doc = XDocument.Load(path, LoadOptions.SetLineInfo); } catch (Exception e) { if (!(e is IOException) && !(e is XmlException)) { throw; } string msg = e.Message; throw LayoutScriptException.Create <LayoutScriptException>(null, e, null, msg); } // Create and return layout return(CreateXmlBinaryLayout(doc, path)); }