/// <summary> /// Loads the values of this plantree from xml /// </summary> /// <param name="xml">xelement</param> public void LoadFromXML(XElement xml) { if (xml.Name != "FileTree") { throw new InvalidXMLException("element name does not equal: FileTree"); } if (xml.HasElements) { IEnumerable <XElement> elements = xml.Elements(); foreach (XElement child in elements) { if (child.Name == "Folder") { FolderNode node = new FolderNode(); node.LoadFromXML(child); Nodes.Add(node); } else if (child.Name == "Plan") { PlanNode node = new PlanNode(); node.LoadFromXML(child); Nodes.Add(node); } else { throw new InvalidXMLException("unknown element type: " + child.Name); } } } }
/// <summary> /// Adds a new plan node into this tree /// </summary> public void AddNewPlan() { PlanNode node = new PlanNode("Plan", new Plan()); node.Plan.AddContainer(); FindParentAndAdd(node); OnAddPlan?.Invoke(); }
/// <summary> /// Loads the foldernode values from xml /// </summary> /// <param name="xml">xml element</param> public override void LoadFromXML(XElement xml) { if (xml.Name != "Folder") { throw new InvalidXMLException("element name does not equal: Folder", xml); } // check that the xml tag has a name attribute and set the name of this node XAttribute name = xml.Attribute("name"); if (name == null) { throw new InvalidXMLException("folder does not contain a name", xml); } Text = name.Value; // loop through children IEnumerable <XElement> elements = xml.Elements(); foreach (XElement child in elements) { if (child.Name == "Folder") { FolderNode node = new FolderNode(); node.LoadFromXML(child); Nodes.Add(node); } else if (child.Name == "Plan") { PlanNode node = new PlanNode(); node.LoadFromXML(child); Nodes.Add(node); } else { throw new InvalidXMLException("unknown element type: " + child.Name, child); } } }