예제 #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);
            }
        }
예제 #2
0
        public void Load(XmlElement elem)
        {
            this.Pattern = elem.Attributes["pattern"].Value;

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

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

            foreach (XmlElement i in elem.ChildNodes.OfType <XmlElement>())
            {
                var x = new SettingItem <IConfusion>();
                x.Load(i);
                this.Add(x);
            }
        }
예제 #3
0
        /// <summary>
        ///     Loads the project from specified XML document.
        /// </summary>
        /// <param name="doc">The XML document storing the project.</param>
        /// <exception cref="Confuser.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);
                }
            }
        }
예제 #4
0
        public void Load(XmlDocument doc)
        {
            doc.Schemas.Add(Schema);
            List <Tuple <string, XmlSchemaException> > exceptions = new List <Tuple <string, XmlSchemaException> >();

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

            XmlElement docElem = doc.DocumentElement;

            this.OutputPath = docElem.Attributes["outputDir"].Value;
            this.SNKeyPath  = docElem.Attributes["snKey"].Value;

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

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

            foreach (XmlElement i in docElem.ChildNodes.OfType <XmlElement>())
            {
                if (i.Name == "plugin")
                {
                    Plugins.Add(i.Attributes["path"].Value);
                }
                else if (i.Name == "rule")
                {
                    Rule settings = new Rule();
                    settings.Load(i);
                    Rules.Add(settings);
                }
                else if (i.Name == "packer")
                {
                    Packer = new SettingItem <Packer>();
                    Packer.Load(i);
                }
                else
                {
                    ProjectAssembly asm = new ProjectAssembly();
                    asm.Load(i);
                    this.Add(asm);
                }
            }
        }