Ejemplo n.º 1
0
        /// <summary>
        ///     Loads the rule description from XML element.
        /// </summary>
        /// <param name="elem">The serialized module description.</param>
        internal void Load(XmlElement elem)
        {
            Pattern = elem.Attributes["pattern"].Value;

            if (elem.Attributes["preset"] != null)
            {
                Preset = (ProtectionPreset)Enum.Parse(typeof(ProtectionPreset), elem.Attributes["preset"].Value, true);
            }
            else
            {
                Preset = ProtectionPreset.None;
            }

            if (elem.Attributes["inherit"] != null)
            {
                Inherit = bool.Parse(elem.Attributes["inherit"].Value);
            }
            else
            {
                Inherit = true;
            }

            Clear();
            foreach (XmlElement i in elem.ChildNodes.OfType <XmlElement>())
            {
                var x = new SettingItem <Protection>();
                x.Load(i);
                Add(x);
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }