コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: SafeFileSerializer.cs プロジェクト: emtees/old-code
		public static object Load (string path, IWarningLogger log) {
			prereqs (path);

			if (!File.Exists (path))
				return null;

			object result = null;

			StreamingContext ctxt = new StreamingContext (StreamingContextStates.All);
			BinaryFormatter fmt = new BinaryFormatter (null, ctxt);

			try {
                                using (FileStream stream = new FileStream (path, FileMode.Open, FileAccess.Read)) {
                                        result = fmt.Deserialize (stream);
                                }
			} catch (Exception e) {
				if (log != null)
					log.Warning (1005, "Error recovering data from " + path, e.Message);
				else
					Console.Error.WriteLine ("Unable to log error loading log; you can " +
								 "probably ignore this message: {0}", e.Message);
				return null;
			}

			return result;
		}
コード例 #3
0
        // return true on error
        public static bool Save(string path, object obj, IWarningLogger log)
        {
            prereqs(path);

            StreamingContext ctxt = new StreamingContext(StreamingContextStates.All);
            BinaryFormatter  fmt  = new BinaryFormatter(null, ctxt);

            try {
                using (FileStream stream = new FileStream(path + newext, FileMode.Create, FileAccess.Write)) {
                    fmt.Serialize(stream, obj);
                }

                bool exists = File.Exists(path);

                if (exists)
                {
                    File.Move(path, path + oldext);
                }

                File.Move(path + newext, path);

                if (exists)
                {
                    File.Delete(path + oldext);
                }
            } catch (Exception e) {
                log.Warning(1006, "Error writing data to " + path + newext, e.Message);
                File.Delete(path + newext);
                return(true);
            }

            return(false);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public static object Load(string path, IWarningLogger log)
        {
            prereqs(path);

            if (!File.Exists(path))
            {
                return(null);
            }

            object result = null;

            StreamingContext ctxt = new StreamingContext(StreamingContextStates.All);
            BinaryFormatter  fmt  = new BinaryFormatter(null, ctxt);

            try {
                using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) {
                    result = fmt.Deserialize(stream);
                }
            } catch (Exception e) {
                if (log != null)
                {
                    log.Warning(1005, "Error recovering data from " + path, e.Message);
                }
                else
                {
                    Console.Error.WriteLine("Unable to log error loading log; you can " +
                                            "probably ignore this message: {0}", e.Message);
                }
                return(null);
            }

            return(result);
        }
コード例 #6
0
ファイル: EnumResult.cs プロジェクト: retahc/old-code
        protected override bool ImportXml(XmlReader xr, IWarningLogger log)
        {
            int depth = xr.Depth;

            while (xr.Depth >= depth)
            {
                if (xr.NodeType != XmlNodeType.Element)
                {
                    xr.Read();
                    continue;
                }

                if (xr.Name != "enum")
                {
                    log.Warning(3019, "Unknown element in EnumResult during XML import",
                                xr.Name);
                    xr.Skip();
                    break;
                }

                string s = xr.ReadElementString();

                try {
                    ValueString = s;
                } catch (Exception e) {
                    log.Error(3019, "Error converting input string to enumeration value",
                              e.Message);
                    return(true);
                }
            }

            return(false);
        }
コード例 #7
0
ファイル: MBDirectory.cs プロジェクト: retahc/old-code
        protected override bool ImportXml(XmlReader xr, IWarningLogger log)
        {
            while (xr.NodeType == XmlNodeType.Whitespace)
            {
                if (!xr.Read())
                {
                    log.Warning(3019, "Empty node for directory result", null);
                    return(true);
                }
            }

            if (xr.Name != "directory")
            {
                log.Warning(3019, "Expected an element named 'directory' in XML import, " +
                            "got '" + xr.Name + "'", null);
                return(true);
            }

            string s = xr.GetAttribute("storage");

            if (s == null)
            {
                log.Warning(3019, "Did not get storage kind for directory element in XML import", null);
                return(true);
            }

            if (ParseStorageKind(s, out storage))
            {
                return(true);
            }

            subpath = xr.GetAttribute("path");

            if (subpath == null)
            {
                log.Warning(3019, "Did not get path for directory element in XML import", null);
                return(true);
            }

            //xr.ReadEndElement ();
            return(false);
        }
コード例 #8
0
        public bool TryMatch(string name, MatcherKind kind, out TargetTemplate tmpl, IWarningLogger log)
        {
            tmpl = null;
            IMatcher which   = null;
            int      quality = 0;

            IEnumerable <IMatcher> mlist = GetMatchers(kind, log);

            if (mlist == null)
            {
                return(true);
            }

            foreach (IMatcher m in mlist)
            {
                int            q;
                TargetTemplate match = m.TryMatch(name, out q);

                if (match == null)
                {
                    continue;
                }

                if (q < quality)
                {
                    continue;
                }

                if (tmpl != null && q == quality)
                {
                    // FIXME: provide a way to specify which one should take priority!
                    string s = String.Format("Two matches succeed with equal quality: " +
                                             "{0} and {1}; going with the first",
                                             which, m);
                    log.Warning(2026, s, name);
                    break;
                }

                which   = m;
                tmpl    = match;
                quality = q;
            }

            return(false);
        }
コード例 #9
0
ファイル: MBBool.cs プロジェクト: retahc/old-code
        protected override bool ImportXml(XmlReader xr, IWarningLogger log)
        {
            string s = xr.ReadString();

            switch (s)
            {
            case "true":
                value = true;
                break;

            case "false":
                value = false;
                break;

            default:
                log.Warning(3019, "Invalid boolean value during XML import", s);
                return(true);
            }

            return(false);
        }
コード例 #10
0
ファイル: TypeResolver.cs プロジェクト: emtees/old-code
	public bool TryMatch (string name, MatcherKind kind, out TargetTemplate tmpl, IWarningLogger log) 
	{
	    tmpl = null;
	    IMatcher which = null;
	    int quality = 0;
	    
	    IEnumerable<IMatcher> mlist = GetMatchers (kind, log);

	    if (mlist == null)
		return true;

	    foreach (IMatcher m in mlist) {
		int q;
		TargetTemplate match = m.TryMatch (name, out q);

		if (match == null)
		    continue;
		
		if (q < quality)
		    continue;
		
		if (tmpl != null && q == quality) {
		    // FIXME: provide a way to specify which one should take priority!
		    string s = String.Format ("Two matches succeed with equal quality: " + 
		    			      "{0} and {1}; going with the first",
		    			      which, m);
		    log.Warning (2026, s, name);
		    break;
		}
		
		which = m;
		tmpl = match;
		quality = q;
	    }
	    
	    return false;
	}
コード例 #11
0
ファイル: NameLookupContext.cs プロジェクト: retahc/old-code
        Type TemplateForRule(Type rtype, IWarningLogger log)
        {
            Type match = null;

            foreach (Type t in VisibleTypes)
            {
                if (!t.IsSubclassOf(typeof(TargetTemplate)))
                {
                    continue;
                }

                object[] attrs = t.GetCustomAttributes(typeof(RuleBindingAttribute), false);

                if (attrs == null || attrs.Length == 0)
                {
                    continue;
                }

                if (!(attrs[0] as RuleBindingAttribute).RuleType.Equals(rtype))
                {
                    continue;
                }

                if (match != null)
                {
                    string s = String.Format("Two potential templates associated with rule {0}: " +
                                             "{1} or {2}", rtype, match, t);
                    log.Warning(9999, s, null);
                    break;
                }

                match = t;
            }

            return(match); // may be null;
        }
コード例 #12
0
ファイル: BundleManagerBase.cs プロジェクト: retahc/old-code
        // Rule template helpers

        public bool GetTemplateForRule(string ns, Type rtype, out TargetTemplate ttmpl, IWarningLogger log)
        {
            ttmpl = null;

            StructureTemplate stmpl = GetNamespaceTemplate(ns, log);

            if (stmpl == null || !sused[ns])
            {
                log.Error(9999, "Trying to use structure template of namespace " +
                          ns + ", but either it wasn't defined or it hasn't been " +
                          "initialized yet.", null);
                return(true);
            }

            // See if we can find a type that has a StructureBinding to tmpl
            // and a RuleBinding to rtype.

            string pns = MBuildPrefix + ns;
            Type   ttype = null, stype = stmpl.GetType();

            foreach (Assembly assy in BundleAssemblies)
            {
                foreach (Type t in assy.GetExportedTypes())
                {
                    if (t.Namespace != pns)
                    {
                        continue;
                    }

                    if (!t.IsSubclassOf(typeof(TargetTemplate)))
                    {
                        continue;
                    }

                    object[] attrs = t.GetCustomAttributes(typeof(StructureBindingAttribute), false);

                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    StructureBindingAttribute sba = (StructureBindingAttribute)attrs[0];

                    if (sba.StructureType == null)
                    {
                        continue;
                    }

                    if (!sba.StructureType.Equals(stype))
                    {
                        continue;
                    }

                    attrs = t.GetCustomAttributes(typeof(RuleBindingAttribute), false);

                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    if (!((RuleBindingAttribute)attrs[0]).RuleType.Equals(rtype))
                    {
                        continue;
                    }

                    if (ttype != null)
                    {
                        log.Warning(9999, "Two hits for rule template: " + ttype.ToString() +
                                    " and " + t.ToString(), rtype.ToString());
                    }

                    ttype = t;
                }
            }

            if (ttype != null)
            {
                ttmpl = (TargetTemplate)Activator.CreateInstance(ttype, stmpl);
            }

            return(false);
        }
コード例 #13
0
ファイル: MBDictionary.cs プロジェクト: emtees/old-code
		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;
		}
コード例 #14
0
ファイル: Result.cs プロジェクト: emtees/old-code
		public static Result ImportXml (XmlReader xr, out string id, IWarningLogger log) {
			id = null;

			if (xr.Name != "result") {
				log.Warning (3019, "Expected 'result' node but got " + xr.Name + " on XML import", null);
				return null;
			}

			id = xr.GetAttribute ("id");

			if (id == null) {
				log.Warning (3019, "No 'id' attribute on result element during XML import", null);
				return null;
			}

			log.PushLocation (id);

			string type = xr.GetAttribute ("type");

			if (type == null) {
				log.Warning (3019, "No 'type' attribute on result element during XML import", null);
				log.PopLocation ();
				return null;
			}

			int depth = xr.Depth;
			Result r;

			while (xr.Read ())
				if (xr.NodeType != XmlNodeType.Attribute &&
				    xr.NodeType != XmlNodeType.Whitespace)
					break;

			//Console.WriteLine ("here: id {0}, type {1}", id, type);
			//Console.WriteLine ("here: {0}: {1} = \"{2}\"; ac = {3}, d = {4} (vs {5})", xr.NodeType, xr.Name, xr.Value,
			//		   xr.AttributeCount, xr.Depth, depth);

			try {
				Type t;

				t = System.Type.GetType (type, false);

				if (t == null) {
					log.Warning (3019, "Unknown result type during XML import", type);
					log.PopLocation ();
					return null;
				}

				if (!t.IsSubclassOf (typeof (Result))) {
					log.Warning (3019, "Type is not a subclass of Result", t.FullName);
					log.PopLocation ();
					return null;
				}
				
				r = MyCreateInstance (t);

				if (r.ImportXml (xr, log)) {
					log.PopLocation ();
					// error will be reported
					return null;
				}
				log.PopLocation ();
			} finally {
				while (xr.Depth > depth) {
					if (!xr.Read ()) {
						log.Warning (3019, "Unexpected end of XML document", null);
						break;
					}
				}
			}

			return r;
		}
コード例 #15
0
ファイル: ActionLog.cs プロジェクト: retahc/old-code
        public void Warning(int category, string text, string detail)
        {
            uilog.Warning(category, text, detail);

            Log("warning", WarnErrMessage(category, text, detail), detail);
        }
コード例 #16
0
ファイル: WarningLoggerProxy.cs プロジェクト: retahc/old-code
 public void Warning(int category, string text, string detail)
 {
     real.Warning(category, text, detail);
 }
コード例 #17
0
ファイル: CompositeResult.cs プロジェクト: emtees/old-code
		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;
		}
コード例 #18
0
ファイル: SafeFileSerializer.cs プロジェクト: emtees/old-code
		// return true on error
		public static bool Save (string path, object obj, IWarningLogger log) {
			prereqs (path);

			StreamingContext ctxt = new StreamingContext (StreamingContextStates.All);
			BinaryFormatter fmt = new BinaryFormatter (null, ctxt);
			
			try {
				using (FileStream stream = new FileStream (path + newext, FileMode.Create, FileAccess.Write)) {
					fmt.Serialize (stream, obj);
				}

				bool exists = File.Exists (path);

				if (exists)
					File.Move (path, path + oldext);

				File.Move (path + newext, path);

				if (exists)
					File.Delete (path + oldext);
			} catch (Exception e) {
				log.Warning (1006, "Error writing data to " + path + newext, e.Message);
				File.Delete (path + newext);
				return true;
			}

			return false;
		}
コード例 #19
0
ファイル: BundleManagerBase.cs プロジェクト: emtees/old-code
	// Rule template helpers

	public bool GetTemplateForRule (string ns, Type rtype, out TargetTemplate ttmpl, IWarningLogger log)
	{
	    ttmpl = null;

	    StructureTemplate stmpl = GetNamespaceTemplate (ns, log);

	    if (stmpl == null || !sused[ns]) {
		log.Error (9999, "Trying to use structure template of namespace " +
			   ns + ", but either it wasn't defined or it hasn't been " +
			   "initialized yet.", null);
		return true;
	    }

	    // See if we can find a type that has a StructureBinding to tmpl
	    // and a RuleBinding to rtype.

	    string pns = MBuildPrefix + ns;
	    Type ttype = null, stype = stmpl.GetType ();

	    foreach (Assembly assy in BundleAssemblies) {
		foreach (Type t in assy.GetExportedTypes ()) {
		    if (t.Namespace != pns)
			continue;

		    if (!t.IsSubclassOf (typeof (TargetTemplate)))
			continue;

		    object[] attrs = t.GetCustomAttributes (typeof (StructureBindingAttribute), false);

		    if (attrs.Length == 0)
			continue;

		    StructureBindingAttribute sba = (StructureBindingAttribute) attrs[0];

		    if (sba.StructureType == null)
			continue;

		    if (!sba.StructureType.Equals (stype))
			continue;

		    attrs = t.GetCustomAttributes (typeof (RuleBindingAttribute), false);

		    if (attrs.Length == 0)
			continue;

		    if (!((RuleBindingAttribute) attrs[0]).RuleType.Equals (rtype))
			continue;

		    if (ttype != null) {
			log.Warning (9999, "Two hits for rule template: " + ttype.ToString () +
				     " and " + t.ToString (), rtype.ToString ());
		    }

		    ttype = t;
		}
	    }

	    if (ttype != null)
		ttmpl = (TargetTemplate) Activator.CreateInstance (ttype, stmpl);

	    return false;
	}
コード例 #20
0
ファイル: NameLookupContext.cs プロジェクト: emtees/old-code
	Type TemplateForRule (Type rtype, IWarningLogger log)
	{
	    Type match = null;

	    foreach (Type t in VisibleTypes) {
		if (!t.IsSubclassOf (typeof (TargetTemplate)))
		    continue;

		object[] attrs = t.GetCustomAttributes (typeof (RuleBindingAttribute), false);

		if (attrs == null || attrs.Length == 0)
		    continue;

		if (!(attrs[0] as RuleBindingAttribute).RuleType.Equals (rtype))
		    continue;

		if (match != null) {
		    string s = String.Format ("Two potential templates associated with rule {0}: " +
					      "{1} or {2}", rtype, match, t);
		    log.Warning (9999, s, null);
		    break;
		}
		
		match = t;
	    }

	    return match; // may be null;
	}
コード例 #21
0
ファイル: CompositeResult.cs プロジェクト: retahc/old-code
        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);
        }
コード例 #22
0
ファイル: MBFile.cs プロジェクト: emtees/old-code
		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;
		}
コード例 #23
0
 void Warning(int category, string text, string detail)
 {
     log.PushLocation(Location);
     log.Warning(category, text, detail);
     log.PopLocation();
 }
コード例 #24
0
        public static Result ImportXml(XmlReader xr, out string id, IWarningLogger log)
        {
            id = null;

            if (xr.Name != "result")
            {
                log.Warning(3019, "Expected 'result' node but got " + xr.Name + " on XML import", null);
                return(null);
            }

            id = xr.GetAttribute("id");

            if (id == null)
            {
                log.Warning(3019, "No 'id' attribute on result element during XML import", null);
                return(null);
            }

            log.PushLocation(id);

            string type = xr.GetAttribute("type");

            if (type == null)
            {
                log.Warning(3019, "No 'type' attribute on result element during XML import", null);
                log.PopLocation();
                return(null);
            }

            int    depth = xr.Depth;
            Result r;

            while (xr.Read())
            {
                if (xr.NodeType != XmlNodeType.Attribute &&
                    xr.NodeType != XmlNodeType.Whitespace)
                {
                    break;
                }
            }

            //Console.WriteLine ("here: id {0}, type {1}", id, type);
            //Console.WriteLine ("here: {0}: {1} = \"{2}\"; ac = {3}, d = {4} (vs {5})", xr.NodeType, xr.Name, xr.Value,
            //		   xr.AttributeCount, xr.Depth, depth);

            try {
                Type t;

                t = System.Type.GetType(type, false);

                if (t == null)
                {
                    log.Warning(3019, "Unknown result type during XML import", type);
                    log.PopLocation();
                    return(null);
                }

                if (!t.IsSubclassOf(typeof(Result)))
                {
                    log.Warning(3019, "Type is not a subclass of Result", t.FullName);
                    log.PopLocation();
                    return(null);
                }

                r = MyCreateInstance(t);

                if (r.ImportXml(xr, log))
                {
                    log.PopLocation();
                    // error will be reported
                    return(null);
                }
                log.PopLocation();
            } finally {
                while (xr.Depth > depth)
                {
                    if (!xr.Read())
                    {
                        log.Warning(3019, "Unexpected end of XML document", null);
                        break;
                    }
                }
            }

            return(r);
        }