/// <summary> /// Parses template data for binary section from given XML /// </summary> /// <param name="element">XElement containing template data for binary section</param> /// <param name="partsList">current list of binary parts</param> private void ParseSection(XElement element, ObservableCollection <BinaryPart> partsList) { long id = long.Parse(element.Attribute(Constants.TemplateXML_ID).Value); string name = element.Attribute(Constants.TemplateXML_Name).Value; LoopType loopType = (LoopType)Enum.Parse(typeof(LoopType), element.Attribute(Constants.TemplateXML_LoopType)?.Value ?? LoopType.NONE.ToString(), true); long loopCountReference = long.Parse(element.Attribute(Constants.TemplateXML_LoopCountReference)?.Value ?? "0"); int loopCount = int.Parse(element.Attribute(Constants.TemplateXML_LoopCount)?.Value ?? "0"); BinarySection binarySection = new BinarySection(id, name); if (loopType != LoopType.NONE) { binarySection.LoopSettings = new LoopSettings() { Type = loopType, LoopCountFixed = loopCount, LoopCountReference = loopCountReference }; } partsList.Add(binarySection); foreach (XElement childElement in element.Elements()) { ParsePart(childElement, binarySection.Parts); } }
private XElement CreateXML_Section(BinarySection section) { XElement xmlSection = new XElement(Constants.TemplateXML_BinarySection); xmlSection.Add(new XAttribute(Constants.TemplateXML_ID, section.ID)); xmlSection.Add(new XAttribute(Constants.TemplateXML_Name, section.Name)); if (section.LoopSettings != null) { xmlSection.Add(new XAttribute(Constants.TemplateXML_LoopType, section.LoopSettings.Type.ToString())); xmlSection.Add(new XAttribute(Constants.TemplateXML_LoopCountReference, section.LoopSettings.LoopCountReference)); xmlSection.Add(new XAttribute(Constants.TemplateXML_LoopCount, section.LoopSettings.LoopCountFixed)); } foreach (var part in section.Parts) { xmlSection.Add(CreateXML_Part(part)); } return(xmlSection); }