/// <summary> /// Initializes a new instance of the <see cref="SectionDefinition"/> class. /// </summary> /// <param name="element">The XML-element to read the data from.</param> public SectionDefinition(XElement element) : this() { this.SectionString.String = element.TryGetAttributeValue("Text", null); // Parse the aspects... foreach (XElement aspectE in element.Elements("Aspect")) { SectionParserDefinition spDefinition = new SectionParserDefinition(aspectE); if (string.IsNullOrWhiteSpace(spDefinition.Type)) { // TODO: Log warning continue; } this.Parsers.Add(spDefinition); } // Parse the areas... foreach (XElement areaE in element.Elements("Area")) { AreaDefinition areaDefinition = new AreaDefinition(areaE); if (!areaDefinition.IsValidDefinition()) { // TODO: Log warning continue; } this.Areas.Add(areaDefinition); } }
/// <summary> /// Saves the parser definition to a file. /// </summary> /// <param name="fileName">The file to save the parser definition to.</param> public void Save(string fileName) { Assertions.AssertNotEmpty(fileName, "fileName"); ControlInformation ci = new ControlInformation(); ci.FaxName = this.ParserName; foreach (SectionDefinitionViewModel svm in this.Sections) { SectionDefinition sd = new SectionDefinition(); sd.SectionString = new GenericParserString(svm.Name); foreach (SectionParserDefinitionViewModel spvm in svm.Aspects) { SectionParserDefinition spd = new SectionParserDefinition(); spd.Type = spvm.Type; spvm.Parser.OnSave(spd.Options); sd.Parsers.Add(spd); } foreach (AreaDefinitionViewModel avm in svm.Areas) { AreaDefinition ad = new AreaDefinition(); ad.AreaString = new GenericParserString(avm.Name); ad.MapToPropertyExpression = avm.MapToPropertyExpression; sd.Areas.Add(ad); } ci.Sections.Add(sd); } ci.Save(fileName); }