示例#1
0
        public Hashtable Compile(HelpSource hs)
        {
            string [] files = Directory.GetFiles(FilesPath, Match);
            Hashtable ret   = new Hashtable();

            foreach (string s in files)
            {
                ErrorDocumentation d;

                hs.Message(TraceLevel.Info, s);

                int errorNum = 0;

                try
                {
                    errorNum = int.Parse(Path.GetFileName(s).Substring(ErrorNumSubstringStart, ErrorNumSubstringLength));
                }
                catch
                {
                    hs.Message(TraceLevel.Info, "Ignoring file {0}", s);
                }

                string errorName = String.Format(FriendlyFormatString, errorNum);

                d = (ErrorDocumentation)ret [errorName];
                if (d == null)
                {
                    ret [errorName] = d = new ErrorDocumentation(errorName);
                }

                if (d.Details == null)
                {
                    string xmlFile = Path.ChangeExtension(s, "xml");
                    hs.Message(TraceLevel.Verbose, xmlFile);
                    if (File.Exists(xmlFile))
                    {
                        XmlSerializer cfgRdr = new XmlSerializer(typeof(ErrorDetails));
                        d.Details = (ErrorDetails)cfgRdr.Deserialize(new XmlTextReader(xmlFile));
                    }
                }
                // Encoding is same as used in MCS, so we will be able to do all those files
                using (StreamReader reader = new StreamReader(s, Encoding.GetEncoding(28591)))
                {
                    d.Examples.Add(reader.ReadToEnd());
                }
            }

            return(ret);
        }
示例#2
0
        public override void PopulateSearchableIndex(IndexWriter writer)
        {
            foreach (Node n in Tree.Nodes)
            {
                XmlSerializer      reader = new XmlSerializer(typeof(ErrorDocumentation));
                ErrorDocumentation d      = (ErrorDocumentation)reader.Deserialize(GetHelpStream(n.Element.Substring(6)));
                SearchableDocument doc    = new SearchableDocument();
                doc.title = d.ErrorName;
                doc.url   = n.Element;
                doc.text  = d.Details != null?d.Details.ToString() : string.Empty;

                doc.examples = d.Examples.Cast <string> ().Aggregate((e1, e2) => e1 + Environment.NewLine + e2);
                doc.hottext  = d.ErrorName;
                writer.AddDocument(doc.LuceneDoc);
            }
        }
示例#3
0
        public override string GetText(string url, out Node match_node)
        {
            match_node = null;

            string c = GetCachedText(url);

            if (c != null)
            {
                return(c);
            }

            if (url == "root:")
            {
                if (HelpSource.use_css)
                {
                    return(BuildHtml(css_error_code, "<div id=\"error_ref\" class=\"header\"><div class=\"title\">Compiler Error Reference</div></div>"));
                }
                else
                {
                    return(BuildHtml(String.Empty, "<table width=\"100%\" bgcolor=\"#b0c4de\" cellpadding=\"5\"><tr><td><h3>Compiler Error Reference</h3></tr></td></table>"));
                }
            }

            if (!url.StartsWith("error:"))
            {
                return(null);
            }

            foreach (Node n in Tree.Nodes)
            {
                if (n.Element != url)
                {
                    continue;
                }

                match_node = n;
                XmlSerializer      reader = new XmlSerializer(typeof(ErrorDocumentation));
                ErrorDocumentation d      = (ErrorDocumentation)reader.Deserialize(
                    GetHelpStream(n.Element.Substring(6))
                    );
                return(BuildHtml(css_error_code, d.RenderAsHtml()));
            }

            return(null);
        }
示例#4
0
        public override void CloseTree(HelpSource hs, Tree tree)
        {
            Hashtable     entries = config.Compile(hs);
            MemoryStream  ms      = new MemoryStream();
            XmlSerializer writer  = new XmlSerializer(typeof(ErrorDocumentation));

            foreach (DictionaryEntry de in entries)
            {
                ErrorDocumentation d = (ErrorDocumentation)de.Value;
                string             s = (string)de.Key;

                tree.LookupNode(s, "error:" + s);

                writer.Serialize(ms, d);
                ms.Position = 0;
                hs.PackStream(ms, s);
                ms.SetLength(0);
            }

            tree.Sort();
        }
示例#5
0
		public Hashtable Compile ()
		{
			string [] files = Directory.GetFiles (FilesPath, Match);
			Hashtable ret = new Hashtable ();
			
			foreach (string s in files) {
				ErrorDocumentation d;
				
				Console.WriteLine (s);

				int errorNum = 0;

				try {
					errorNum = int.Parse (Path.GetFileName (s).Substring (ErrorNumSubstringStart, ErrorNumSubstringLength));
				} catch {
					Console.WriteLine ("Ignoring file {0}", s);
				}
				
				string errorName = String.Format (FriendlyFormatString, errorNum);
				
				d = (ErrorDocumentation)ret [errorName];
				if (d == null)
					ret [errorName] = d = new ErrorDocumentation (errorName);
				
				if (d.Details == null) {
					string xmlFile = Path.ChangeExtension (s, "xml");
					Console.WriteLine (xmlFile);
					if (File.Exists (xmlFile)) {
						XmlSerializer cfgRdr = new XmlSerializer (typeof (ErrorDetails));
						d.Details = (ErrorDetails)cfgRdr.Deserialize (new XmlTextReader (xmlFile));
					}
				}
				// Encoding is same as used in MCS, so we will be able to do all those files
				using (StreamReader reader = new StreamReader (s, Encoding.GetEncoding (28591))) {
					d.Examples.Add (reader.ReadToEnd ());
				}
			}
			
			return ret;
		}