public override void FromXml(string source) { // Deserialize asset from xml string XqlParser parser = new XqlParser(); parser.LoadData(source); List <Hashtable> results = parser.Query("SELECT _innerXml, name, assetId FROM " + ElementType); if (results.Count == 0) { throw new HsfElementException("Unable to parse " + ElementType + " from xml"); } // Load string values Name = results[0]["name"].ToString(); if (Name == "") { Name = "Unknown Asset"; } try { Id = Convert.ToInt64(results[0]["assetId"]); } catch (FormatException) { Id = 0; } // Load subsystems parser.LoadData(results[0]["_innerXml"].ToString()); SubsystemElement sampleSub = new SubsystemElement(); results = parser.Query("SELECT _outerXml FROM " + sampleSub.ElementType); foreach (Hashtable ht in results) { SubsystemElement newSub = new SubsystemElement(); newSub.FromXml(ht["_outerXml"].ToString()); Subsystems.Add(newSub); } // Load constraints ConstraintElement sampleCons = new ConstraintElement(); results = parser.Query("SELECT _outerXml FROM " + sampleCons.ElementType); foreach (Hashtable ht in results) { ConstraintElement newCons = new ConstraintElement(); newCons.FromXml(ht["_outerXml"].ToString()); Constraints.Add(newCons); } // Load position results = parser.Query("SELECT _outerXml FROM " + Position.ElementType); Position.FromXml(results[0]["_outerXml"].ToString()); }
public override void FromXml(string source) { // Attempts to load this element and children from given xml content string XqlParser parser = new XqlParser(); parser.LoadData(source); List <Hashtable> results = parser.Query("SELECT TargetName, TargetType, TaskType, MaxTimes, Value, _innerXml FROM " + ElementType); if (results.Count == 0) { throw new HsfElementException("Unable to parse " + ElementType + " from xml"); } // Load values TargetName = results[0]["TargetName"].ToString(); MaxTimes = Convert.ToDouble(results[0]["MaxTimes"]); Value = Convert.ToDouble(results[0]["Value"]); // Load enums Array posValues = Enum.GetValues(typeof(TargetType)); foreach (TargetType v in posValues) { if (Enum.GetName(typeof(TargetType), v) == results[0]["TargetType"].ToString()) { TargetType = v; } } posValues = Enum.GetValues(typeof(TaskType)); foreach (TaskType v in posValues) { if (Enum.GetName(typeof(TaskType), v) == results[0]["TaskType"].ToString()) { TaskType = v; } } // Load children Position.FromXml(results[0]["_innerXml"].ToString()); }