public XmlRoutine() { _xml = new XmlDocument(); Name = Guid.NewGuid().ToString("n"); if (Routines.UserInputs.Any()) { XmlRoutines.Add(Guid.NewGuid().ToString("n"), Routines.UserInputs.ToList()); } }
public XmlRoutine(string filepath, string routineName = "") : this() { _xml.Load(filepath); XmlNode xMeta = _xml.SelectSingleNode("//Meta"); Name = xMeta["Name"].InnerText; DateCreated = DateTime.Parse(xMeta["DateCreated"].InnerText); if (xMeta.SelectSingleNode("UseDelays") != null) { UseDelays = bool.Parse(xMeta["UseDelays"].InnerText); } string xPath = "//Routine"; XmlNodeList xRoutines = _xml.SelectNodes(xPath); for (int i = 0; i < xRoutines.Count; i++) { string xRoutineName = xRoutines[i].Attributes["name"]?.Value ?? Guid.NewGuid().ToString("n"); if (!XmlRoutines.ContainsKey(xRoutineName)) { XmlRoutines.Add(xRoutineName, new List <RoutineInput>()); } XmlNodeList xInputs = xRoutines[i].SelectNodes("Inputs/Input"); foreach (XmlNode xInput in xInputs) { XmlRoutines[xRoutineName].Add(new RoutineInput(xInput)); } } List <RoutineInput> selectedRoutineInputs; if (!string.IsNullOrEmpty(routineName)) { XmlRoutines.TryGetValue(routineName, out selectedRoutineInputs); } else { selectedRoutineInputs = XmlRoutines.Values.First(); } if (selectedRoutineInputs != null) { foreach (RoutineInput selectedRoutineInput in selectedRoutineInputs) { base.Enqueue(selectedRoutineInput); } } }