Ejemplo n.º 1
0
            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);
            }
Ejemplo n.º 2
0
            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));
            }
Ejemplo n.º 3
0
            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));
            }
Ejemplo n.º 4
0
            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));
            }