protected override bool ImportXml(XmlReader xr, IWarningLogger log) { int d = xr.Depth; while (!xr.EOF && xr.Depth >= d) { if (xr.NodeType != XmlNodeType.Element) { xr.Read(); continue; } if (xr.NodeType != XmlNodeType.Element || xr.Name != "result") { log.Warning(3019, "Expected 'result' element in dictionary but got '" + xr.Name + "' instead during XML import.", null); xr.Read(); continue; } string id; Result r = Result.ImportXml(xr, out id, log); if (r == null) { return(true); } this[id] = r; } return(false); }
protected override bool ImportXml(XmlReader xr, IWarningLogger log) { bool gotdir = false; bool gotname = false; int depth = xr.Depth; while (xr.Depth >= depth) { if (xr.NodeType != XmlNodeType.Element) { //Console.WriteLine ("skipping {0}: {1} = \"{2}\"", xr.NodeType, xr.Name, xr.Value); xr.Read(); continue; } switch (xr.Name) { case "result": string ignore; Result r = Result.ImportXml(xr, out ignore, log); if (r == null) { return(true); } if (!(r is MBDirectory)) { log.Warning(3019, "Result embedded in file result is not directory during XML import", null); return(true); } dir = (MBDirectory)r; gotdir = true; break; case "name": name = xr.ReadElementString(); gotname = true; break; default: log.Warning(3019, "Unknown element in file result during XML import", xr.Name); xr.Skip(); break; } } if (!gotdir) { log.Warning(3019, "Did not find directory in file element during XML import", null); return(true); } if (!gotname) { log.Warning(3019, "Did not find name in file element during XML import", null); return(true); } return(false); }
protected override bool ImportXml(XmlReader xr, IWarningLogger log) { // We try very hard to load composites because they are liable to // change between versions, and we don't want to trash people's // configurations. ArrayList fields = GetFieldData(); bool[] check = new bool[fields.Count]; int d = xr.Depth; while (!xr.EOF && xr.Depth >= d) { if (xr.NodeType != XmlNodeType.Element) { xr.Read(); continue; } if (xr.Name != "field") { log.Warning(3019, "Expected 'field' element inside composite but got '" + xr.Name + "' during XML import", null); xr.Read(); continue; } //Console.WriteLine ("composite doit: {0}: {1} = \"{2}\"; ac = {3}, d = {4}", xr.NodeType, xr.Name, xr.Value, // xr.AttributeCount, xr.Depth); bool is_null = false; string name = null; string decltype = null; name = xr.GetAttribute("name"); if (name == null) { log.Warning(3019, "Didn't find 'name' attribute in 'field' element during XML import", null); return(true); } decltype = xr.GetAttribute("decl_type"); if (decltype == null) { log.Warning(3019, "Didn't find 'decl_type' attribute in 'field' element during XML import; continuing", null); } if (xr.GetAttribute("is_null") != null) { is_null = true; } int i; FieldInfo fi = null; for (i = 0; i < fields.Count; i++) { fi = (FieldInfo)fields[i]; if (fi.Name == name && fi.DeclaringType.FullName == decltype) { break; } } if (!is_null) { xr.Read(); while (xr.NodeType == XmlNodeType.Whitespace) { xr.Read(); } } //Console.WriteLine ("composite after maybe read: {0}: {1} = \"{2}\"; ac = {3}, d = {4}", xr.NodeType, xr.Name, xr.Value, // xr.AttributeCount, xr.Depth); if (i == fields.Count) { log.Warning(3019, "Didn't find the field '" + name + "' in self; still trying to load. Result may need to be uncached.", null); xr.Skip(); continue; } if (is_null) { fi.SetValue(this, null); check[i] = true; continue; } string ignore; Result r = Result.ImportXml(xr, out ignore, log); if (r == null) { log.Warning(3019, "Couldn't load result for field '" + name + "'; still trying to load. Result may need to be uncached", null); continue; } try { fi.SetValue(this, r); check[i] = true; } catch (ArgumentException) { string msg = String.Format("Field {0} is of type {1}, but {2} was restored from the XML. Still trying to load. Result may" + " need to be uncached.", name, fi.MemberType, r.GetType()); log.Warning(3019, msg, r.ToString()); } } for (int i = 0; i < fields.Count; i++) { if (check[i]) { continue; } FieldInfo fi = (FieldInfo)fields[i]; log.Warning(3019, "Didn't load field '" + fi.Name + "' in composite; still trying to load. Result may need to be uncached", null); } return(false); }