/// <summary> /// Loads the module description from XML element. /// </summary> /// <param name="elem">The serialized module description.</param> internal void Load(XmlElement elem) { Path = elem.Attributes["path"].Value; if (elem.Attributes["snKey"] != null) { SNKeyPath = elem.Attributes["snKey"].Value.NullIfEmpty(); } else { SNKeyPath = null; } if (elem.Attributes["snKeyPass"] != null) { SNKeyPassword = elem.Attributes["snKeyPass"].Value.NullIfEmpty(); } else { SNKeyPassword = null; } Rules.Clear(); foreach (XmlElement i in elem.ChildNodes.OfType <XmlElement>()) { var rule = new Rule(); rule.Load(i); Rules.Add(rule); } }
/// <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); } } }
/// <summary> /// Loads the module description from XML element. /// </summary> /// <param name="elem">The serialized module description.</param> internal void Load(XmlElement elem) { Path = elem.Attributes["path"].Value; if (elem.Attributes["external"] != null) { IsExternal = bool.Parse(elem.Attributes["external"].Value); } else { IsExternal = false; } if (elem.Attributes["snKey"] != null) { SNKeyPath = elem.Attributes["snKey"].Value.NullIfEmpty(); } else { SNKeyPath = null; } if (elem.Attributes["snKeyPass"] != null) { SNKeyPassword = elem.Attributes["snKeyPass"].Value.NullIfEmpty(); } else { SNKeyPassword = null; } bool delaySig = false; if (elem.Attributes["snDelaySig"] != null) { bool.TryParse(elem.Attributes["snDelaySig"].Value, out delaySig); } SNDelaySig = delaySig; if (elem.Attributes["snPubKey"] != null) { SNPubKeyPath = elem.Attributes["snPubKey"].Value.NullIfEmpty(); } else { SNPubKeyPath = null; } if (elem.Attributes["snSigKey"] != null) { SNSigKeyPath = elem.Attributes["snSigKey"].Value.NullIfEmpty(); } else { SNSigKeyPath = null; } if (elem.Attributes["snPubSigKey"] != null) { SNPubSigKeyPath = elem.Attributes["snPubSigKey"].Value.NullIfEmpty(); } else { SNPubSigKeyPath = null; } Rules.Clear(); foreach (XmlElement i in elem.ChildNodes.OfType <XmlElement>()) { var rule = new Rule(); rule.Load(i); Rules.Add(rule); } }
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); } } }