Esempio n. 1
0
        /// <summary>
        /// Loads a script document from the given file
        /// </summary>
        /// <param name="File">The file to load</param>
        /// <param name="Schema">The schema to validate against</param>
        /// <param name="OutDocument">If successful, the document that was read</param>
        /// <returns>True if the document could be read, false otherwise</returns>
        public static bool TryRead(FileReference File, ScriptSchema Schema, out ScriptDocument OutDocument)
        {
            ScriptDocument Document = new ScriptDocument(File);

            XmlReaderSettings Settings = new XmlReaderSettings();

            Settings.Schemas.Add(Schema.CompiledSchema);
            Settings.ValidationType          = ValidationType.Schema;
            Settings.ValidationEventHandler += Document.ValidationEvent;

            using (XmlReader Reader = XmlReader.Create(File.FullName, Settings))
            {
                // Read the document
                Document.LineInfo = (IXmlLineInfo)Reader;
                try
                {
                    Document.Load(Reader);
                }
                catch (XmlException Ex)
                {
                    if (!Document.bHasErrors)
                    {
                        CommandUtils.LogError("{0}", Ex.Message);
                        Document.bHasErrors = true;
                    }
                }

                // If we hit any errors while parsing
                if (Document.bHasErrors)
                {
                    OutDocument = null;
                    return(false);
                }

                // Check that the root element is valid. If not, we didn't actually validate against the schema.
                if (Document.DocumentElement.Name != ScriptSchema.RootElementName)
                {
                    CommandUtils.LogError("Script does not have a root element called '{0}'", ScriptSchema.RootElementName);
                    OutDocument = null;
                    return(false);
                }
                if (Document.DocumentElement.NamespaceURI != ScriptSchema.NamespaceURI)
                {
                    CommandUtils.LogError("Script root element is not in the '{0}' namespace (add the xmlns=\"{0}\" attribute)", ScriptSchema.NamespaceURI);
                    OutDocument = null;
                    return(false);
                }
            }

            OutDocument = Document;
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Read the script from the given file
        /// </summary>
        /// <param name="File">File to read from</param>
        bool TryRead(FileReference File)
        {
            // Read the document and validate it against the schema
            ScriptDocument Document;

            if (!ScriptDocument.TryRead(File, Schema, out Document))
            {
                NumErrors++;
                return(false);
            }

            // Read the root BuildGraph element
            EnterScope();
            foreach (ScriptElement Element in Document.DocumentElement.ChildNodes.OfType <ScriptElement>())
            {
                switch (Element.Name)
                {
                case "Include":
                    ReadInclude(Element, File.Directory);
                    break;

                case "Property":
                    ReadProperty(Element);
                    break;

                case "Local":
                    ReadLocalProperty(Element);
                    break;

                case "Agent":
                    ReadAgent(Element, null);
                    break;

                case "Aggregate":
                    ReadAggregate(Element);
                    break;

                case "Notify":
                    ReadNotifier(Element);
                    break;

                case "Trigger":
                    ReadTrigger(Element);
                    break;

                case "Warning":
                    ReadDiagnostic(Element, LogEventType.Warning, null, null, null);
                    break;

                case "Error":
                    ReadDiagnostic(Element, LogEventType.Error, null, null, null);
                    break;

                default:
                    LogError(Element, "Invalid element '{0}'", Element.Name);
                    break;
                }
            }
            LeaveScope();
            return(true);
        }
Esempio n. 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ScriptElement(FileReference InFile, int InLineNumber, string Prefix, string LocalName, string NamespaceUri, ScriptDocument Document)
     : base(Prefix, LocalName, NamespaceUri, Document)
 {
     File       = InFile;
     LineNumber = InLineNumber;
 }