Beispiel #1
0
        /// <summary>
        ///     Loads the project from specified XML document.
        /// </summary>
        /// <param name="doc">The XML document storing the project.</param>
        /// <exception cref="DotProtect.Core.Project.ProjectValidationException">
        ///     The project XML contains schema errors.
        /// </exception>
        public void Load(XmlDocument doc)
        {
            doc.Schemas.Add(Schema);
            var exceptions = new List <XmlSchemaException>();

            doc.Validate((sender, e) =>
            {
                if (e.Severity != XmlSeverityType.Error)
                {
                    return;
                }
                exceptions.Add(e.Exception);
            });
            if (exceptions.Count > 0)
            {
                throw new ProjectValidationException(exceptions);
            }

            XmlElement docElem = doc.DocumentElement;

            OutputDirectory = docElem.Attributes["outputDir"].Value;
            BaseDirectory   = docElem.Attributes["baseDir"].Value;

            if (docElem.Attributes["seed"] != null)
            {
                Seed = docElem.Attributes["seed"].Value.NullIfEmpty();
            }
            else
            {
                Seed = null;
            }

            if (docElem.Attributes["debug"] != null)
            {
                Debug = bool.Parse(docElem.Attributes["debug"].Value);
            }
            else
            {
                Debug = false;
            }

            Packer = null;
            Clear();
            ProbePaths.Clear();
            PluginPaths.Clear();
            Rules.Clear();
            foreach (XmlElement i in docElem.ChildNodes.OfType <XmlElement>())
            {
                if (i.Name == "rule")
                {
                    var rule = new Rule();
                    rule.Load(i);
                    Rules.Add(rule);
                }
                else if (i.Name == "packer")
                {
                    Packer = new SettingItem <Packer>();
                    Packer.Load(i);
                }
                else if (i.Name == "probePath")
                {
                    ProbePaths.Add(i.InnerText);
                }
                else if (i.Name == "plugin")
                {
                    PluginPaths.Add(i.InnerText);
                }
                else
                {
                    var asm = new ProjectModule();
                    asm.Load(i);
                    Add(asm);
                }
            }
        }