Example #1
1
		public static string GetHtml (string url, HelpSource helpSource, out Node match)
		{
			string htmlContent = null;
			match = null;
			
			if (helpSource != null)
				htmlContent = AppDelegate.Root.RenderUrl (url, generator, out match, helpSource);
			if (htmlContent == null) {
				// the displayed url have a lower case type code (e.g. t: instead of T:) which confuse monodoc
				if (url.Length > 2 && url[1] == ':')
					url = char.ToUpperInvariant (url[0]) + url.Substring (1);
				// It may also be url encoded so decode it
				url = Uri.UnescapeDataString (url);
				htmlContent = AppDelegate.Root.RenderUrl (url, generator, out match, helpSource);
				if (htmlContent != null && match != null && match.Tree != null)
					helpSource = match.Tree.HelpSource;
			}
			if (htmlContent == null)
				return null;
			
			var html = new StringWriter ();
   			html.Write ("<html>\n<head><title>{0}</title>", url);
			
			if (helpSource != null) {
				if (HtmlGenerator.InlineCss != null)
                    html.Write (" <style type=\"text/css\">{0}</style>\n", HtmlGenerator.InlineCss);
				/*if (helpSource.InlineJavaScript != null)
                    html.Write ("<script type=\"text/JavaScript\">{0}</script>\n", helpSource.InlineJavaScript);*/
            }

            html.Write ("</head><body>");
            html.Write (htmlContent);
            html.Write ("</body></html>\n");
            return html.ToString ();
		}
Example #2
0
		/// <summary>
		///   Load from file constructor
		/// </summary>
		public Tree (HelpSource hs, string filename)
		{
			HelpSource = hs;
			Encoding utf8 = new UTF8Encoding (false, true);

			if (!File.Exists (filename)){
				throw new FileNotFoundException ();
			}
		
			InputStream = File.OpenRead (filename);
			InputReader = new BinaryReader (InputStream, utf8);
			byte [] sig = InputReader.ReadBytes (4);
		
			if (!GoodSig (sig))
				throw new Exception ("Invalid file format");
		
			InputStream.Position = 4;
			// Try to read version information
			if (InputReader.ReadInt32 () == -(int)'v')
				VersionNumber = InputReader.ReadInt64 ();
			else
				InputStream.Position -= 4;

			var position = InputReader.ReadInt32 ();
			rootNode = new Node (this, position);
			InflateNode (rootNode);
		}
Example #3
0
		public static string GetHtml (string url, HelpSource helpSource, out Node match)
		{
			string htmlContent = null;
			match = null;
			
			if (helpSource != null)
				htmlContent = helpSource.GetText (url, out match);
			if (htmlContent == null){
				htmlContent = AppDelegate.Root.RenderUrl (url, out match);
				if (htmlContent != null && match != null && match.tree != null){
					helpSource = match.tree.HelpSource;
				}
			}
			if (htmlContent == null)
				return null;
			
			var html = new StringWriter ();
   			html.Write ("<html>\n<head><title>{0}</title>", url);
			
			if (helpSource != null){
            	if (helpSource.InlineCss != null) 
                    html.Write (" <style type=\"text/css\">{0}</style>\n", helpSource.InlineCss);
				if (helpSource.InlineJavaScript != null)
                    html.Write ("<script type=\"text/JavaScript\">{0}</script>\n", helpSource.InlineJavaScript);
            }

            html.Write ("</head><body>");
            html.Write (htmlContent);
            html.Write ("</body></html>\n");
            return html.ToString ();
		}
Example #4
0
		/// <summary>
		///   Load from file constructor
		/// </summary>
		public Tree (HelpSource hs, string filename)
#if LEGACY_MODE
			: base (null, null)
#endif
		{
			HelpSource = hs;
			Encoding utf8 = new UTF8Encoding (false, true);

			if (!File.Exists (filename)){
				throw new FileNotFoundException ();
			}
		
			InputStream = File.OpenRead (filename);
			InputReader = new BinaryReader (InputStream, utf8);
			byte [] sig = InputReader.ReadBytes (4);
		
			if (!GoodSig (sig))
				throw new Exception ("Invalid file format");
		
			InputStream.Position = 4;
			// Try to read old version information
			if (InputReader.ReadInt32 () == VersionNumberKey)
				VersionNumber = InputReader.ReadInt64 ();
			else {
				// We try to see if there is a version number at the end of the file
				InputStream.Seek (-(4 + 8), SeekOrigin.End); // VersionNumberKey + long
				try {
					if (InputReader.ReadInt32 () == VersionNumberKey)
						VersionNumber = InputReader.ReadInt64 ();
				} catch {}
				// We set the stream back at the beginning of the node definition list
				InputStream.Position = 4;
			}

			var position = InputReader.ReadInt32 ();
#if !LEGACY_MODE
			rootNode = new Node (this, position);
#else
			Address = position;
#endif
			InflateNode (RootNode);
		}
        public HelpSource GetHelpSourceAndIdForUrl(string url, HelpSource hintSource, out string internalId, out Dictionary <string, string> context, out Node node)
        {
            node       = null;
            internalId = null;
            context    = null;

            if (url == "root:")
            {
                context = new Dictionary <string, string> {
                    { "specialpage", "master-root" }
                };
                internalId = url;
                node       = null;
                // We return the first help source available since the generator will simply fetch this RootTree instance through it
                return(helpSources.FirstOrDefault());
            }
            if (url.StartsWith(RootNamespace, StringComparison.OrdinalIgnoreCase))
            {
                context = new Dictionary <string, string> {
                    { "specialpage", "root" }
                };
                return(this.GetHelpSourceAndIdFromName(url.Substring(RootNamespace.Length), out internalId, out node));
            }

            HelpSource helpSource = hintSource;

            if (helpSource == null || string.IsNullOrEmpty(internalId = helpSource.GetInternalIdForUrl(url, out node, out context)))
            {
                helpSource = null;
                foreach (var hs in helpSources.Where(h => h.CanHandleUrl(url)))
                {
                    if (!string.IsNullOrEmpty(internalId = hs.GetInternalIdForUrl(url, out node, out context)))
                    {
                        helpSource = hs;
                        break;
                    }
                }
            }

            return(helpSource);
        }
Example #6
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();
        }
Example #7
0
	/// <summary>
	///   Load from file constructor
	/// </summary>
	public Tree (HelpSource hs, string filename) : base (null, null)
	{
		Encoding utf8 = new UTF8Encoding (false, true);

		if (!File.Exists (filename)){
			throw new FileNotFoundException ();
		}
		
		InputStream = File.OpenRead (filename);
		InputReader = new BinaryReader (InputStream, utf8);
		byte [] sig = InputReader.ReadBytes (4);
		
		if (!GoodSig (sig))
			throw new Exception ("Invalid file format");
		
		InputStream.Position = 4;
		position = InputReader.ReadInt32 ();

		LoadNode ();
		HelpSource = hs;
	}
Example #8
0
		public static string GetHtml (string url, HelpSource helpSource, out Node match)
		{
			Console.WriteLine ("Calling URL {0} with HelpSource {1}", url, helpSource == null ? "(null)" : helpSource.Name);

			string htmlContent = null;
			match = null;
			
			if (helpSource != null)
				htmlContent = helpSource.GetText (url, out match);
			if (htmlContent == null){
				// the displayed url have a lower case type code (e.g. t: instead of T:) which confuse monodoc
				if (url.Length > 2 && url[1] == ':')
					url = char.ToUpperInvariant (url[0]) + url.Substring (1);
				// It may also be url encoded so decode it
				url = Uri.UnescapeDataString (url);
				htmlContent = Program.Root.RenderUrl (url, out match);
				if (htmlContent != null && match != null && match.tree != null){
					helpSource = match.tree.HelpSource;
				}
			}
			if (htmlContent == null)
				return null;
			
			var html = new StringWriter ();
   			html.Write ("<html>\n<head><title>{0}</title>", url);
			
			if (helpSource != null){
            	if (helpSource.InlineCss != null) 
                    html.Write (" <style type=\"text/css\">{0}</style>\n", helpSource.InlineCss);
				if (helpSource.InlineJavaScript != null)
                    html.Write ("<script type=\"text/JavaScript\">{0}</script>\n", helpSource.InlineJavaScript);
            }

            html.Write ("</head><body>");
            html.Write (htmlContent);
            html.Write ("</body></html>\n");
			return html.ToString ();
		}
Example #9
0
        public static void RenderEditPreview(string url, RootTree tree, XmlNode new_node, XmlWriter w)
        {
            string [] uSplit = ParseEditUrl(url);

            if (uSplit[0].StartsWith("monodoc:///"))
            {
                int        prov = int.Parse(uSplit [0].Substring("monodoc:///".Length));
                HelpSource hs   = tree.GetHelpSourceFromId(prov);
                hs.RenderPreviewDocs(new_node, w);
            }
            else
            {
                foreach (HelpSource hs in tree.HelpSources)
                {
                    if (hs is EcmaUncompiledHelpSource)
                    {
                        // It doesn't matter which EcmaHelpSource is chosen.
                        hs.RenderPreviewDocs(new_node, w);
                        break;
                    }
                }
            }
        }
Example #10
0
        public TOutput RenderUrl <TOutput> (string url, IDocGenerator <TOutput> generator, HelpSource hintSource = null)
        {
            Node dummy;

            return(RenderUrl <TOutput> (url, generator, out dummy, hintSource));
        }
Example #11
0
		/// <summary>
		///    Tree creation and merged tree constructor
		/// </summary>
		public Tree (HelpSource hs, string caption, string url)
#if !LEGACY_MODE
			: this (hs, null, caption, url)
		{
		}
Example #12
0
	public override void Run (IEnumerable<string> args)
	{
		var formats = new Dictionary<string, List<string>> ();
		string prefix = "tree";
		var formatOptions = CreateFormatOptions (this, formats);
		var options = new OptionSet () {
			formatOptions [0],
			{ "o|out=",
				"Provides the output file prefix; the files {PREFIX}.zip and " + 
					"{PREFIX}.tree will be created.\n" +
					"If not specified, `tree' is the default PREFIX.",
				v => prefix = v },
			formatOptions [1],
		};
		List<string> extra = Parse (options, args, "assemble", 
				"[OPTIONS]+ DIRECTORIES",
				"Assemble documentation within DIRECTORIES for use within the monodoc browser.");
		if (extra == null)
			return;

		List<Provider> list = new List<Provider> ();
		EcmaProvider ecma = null;
		bool sort = false;
		
		foreach (string format in formats.Keys) {
			switch (format) {
			case "ecma":
				if (ecma == null) {
					ecma = new EcmaProvider ();
					list.Add (ecma);
					sort = true;
				}
				foreach (string dir in formats [format])
					ecma.AddDirectory (dir);
				break;

			case "xhtml":
			case "hb":
				list.AddRange (formats [format].Select (d => (Provider) new XhtmlProvider (d)));
				break;

			case "man":
				list.Add (new ManProvider (formats [format].ToArray ()));
				break;

			case "simple":
				list.AddRange (formats [format].Select (d => (Provider) new SimpleProvider (d)));
				break;

			case "error":
				list.AddRange (formats [format].Select (d => (Provider) new ErrorProvider (d)));
				break;

			case "ecmaspec":
				list.AddRange (formats [format].Select (d => (Provider) new EcmaSpecProvider (d)));
				break;

			case "addins":
				list.AddRange (formats [format].Select (d => (Provider) new AddinsProvider (d)));
				break;
			}
		}

		HelpSource hs = new HelpSource (prefix, true);
		hs.TraceLevel = TraceLevel;

		foreach (Provider p in list) {
			p.PopulateTree (hs.Tree);
		}

		if (sort && hs.Tree != null)
			hs.Tree.Sort ();
			      
		//
		// Flushes the EcmaProvider
		//
		foreach (Provider p in list)
			p.CloseTree (hs, hs.Tree);

		hs.Save ();
	}
Example #13
0
		public static string GetHtml (string url, HelpSource helpSource)
		{
			Node _;
			return GetHtml (url, helpSource, out _);
		}
Example #14
0
	//
	// Called at shutdown time after the tree has been populated to perform
	// any fixups or final tasks.
	//
	public abstract void CloseTree (HelpSource hs, Tree tree);
Example #15
0
	/// <summary>
	///    Tree creation and merged tree constructor
	/// </summary>
	public Tree (HelpSource hs, string caption, string url) : base (caption, url)
	{
		HelpSource = hs;
	}
Example #16
0
 //
 // Called at shutdown time after the tree has been populated to perform
 // any fixups or final tasks.
 //
 public abstract void CloseTree(HelpSource hs, Tree tree);
Example #17
0
        /// <summary>
        ///    Tree creation and merged tree constructor
        /// </summary>
        public Tree(HelpSource hs, string caption, string url)
#if !LEGACY_MODE
            : this(hs, null, caption, url)
        {
        }
Example #18
0
		void LoadUrl (string url, bool syncTreeView = false, HelpSource source = null, bool addToHistory = true)
		{
			if (url == currentUrl)
				return;
			if (url.StartsWith ("#")) {
				Console.WriteLine ("FIXME: Anchor jump");
				return;
			}
			// In case user click on an external link e.g. [Android documentation] link at bottom of MonoDroid docs
			if (url.StartsWith ("http://") || url.StartsWith ("https://")) {
				UrlLauncher.Launch (url);
				return;
			}
			var ts = Interlocked.Increment (ref loadUrlTimestamp);
			Task.Factory.StartNew (() => {
				Node node;
				var res = DocTools.GetHtml (url, source, out node);
				return new { Node = node, Html = res };
			}).ContinueWith (t => {
				var node = t.Result.Node;
				var res = t.Result.Html;
				if (res != null) {
					BeginInvoke (new Action (() => {
						if (ts < loadUrlTimestamp)
							return;
						Text = currentUrl = node == null ? url : node.PublicUrl;
						if (addToHistory)
							history.AppendHistory (new LinkPageVisit (this, currentUrl));
						LoadHtml (res);
						this.match = node;
						if (syncTreeView) {
							if (tabContainer.SelectedIndex == 0 && match != null) {
								if (ShowNodeInTree (match))
									docTree.SelectedNode = nodeToTreeNodeMap[match];
							} else {
								tabContainer.SelectedIndex = 0;
							}
						}
						// Bookmark spinner management
						var bookmarkIndex = Program.BookmarkManager.FindIndexOfBookmarkFromUrl (url);
						if (bookmarkIndex == -1 || bookmarkIndex < bookmarkSelector.Items.Count)
							bookmarkSelector.SelectedIndex = bookmarkIndex;
					}));
				}
			});
		}
Example #19
0
	public static int Main (string [] args)
	{
		string output = "tree";
		HelpSource hs;
		ArrayList list = new ArrayList ();
		EcmaProvider ecma = null;
		bool sort = false;
		
		int argc = args.Length;
		for (int i = 0; i < argc; i++){
			string arg = args [i];
			
			switch (arg){
			case "-o": case "--out":
				if (i < argc)
					output = args [++i];
				else {
					Usage ();
					return 1;
				} 
				break;

			case "--ecma":
				if (i < argc){
					if (ecma == null) {
						ecma = new EcmaProvider ();
						list.Add (ecma);
						sort = true;
					}
					ecma.AddDirectory (args [++i]);
				} else {
					Usage ();
					return 1;
				}
				break;

			case "--xhtml":
			case "--hb":
				if (i < argc){
					Provider populator = new XhtmlProvider (args [++i]);

					list.Add (populator);
				} else {
					Usage ();
					return 1;
				}
				break;

			case "--man":
				if (i < argc){
					int countfiles = args.Length - ++i;
					string[] xmlfiles = new String[countfiles];
					for (int a = 0;a< countfiles;a++) {
						xmlfiles[a] = args [i];
						i++;
					}
					Provider populator = new ManProvider (xmlfiles);

					list.Add (populator);
				} else {
					Usage ();
					return 1;
				}
				break;

		case "--simple":
				if (i < argc){
					Provider populator = new SimpleProvider (args [++i]);

					list.Add (populator);
				} else {
					Usage ();
					return 1;
				}
				break;
			case "--error":
				if (i < argc){
					Provider populator = new ErrorProvider (args [++i]);

					list.Add (populator);
				} else {
					Usage ();
					return 1;
				}
				break;
			case "--ecmaspec":
				if (i < argc){
					Provider populator = new EcmaSpecProvider (args [++i]);

					list.Add (populator);
				} else {
					Usage ();
					return 1;
				}
				break;

			case "--addins":
				if (i < argc){
					Provider populator = new AddinsProvider (args [++i]);
					list.Add (populator);
				} else {
					Usage ();
					return 1;
				}
				break;
			
			default:
				Usage ();
				return 1;
			}
		}

		hs = new HelpSource (output, true);

		foreach (Provider p in list){
			p.PopulateTree (hs.Tree);
		}

		if (sort)
			hs.Tree.Sort ();
			      
		//
		// Flushes the EcmaProvider
		//
		foreach (Provider p in list)
			p.CloseTree (hs, hs.Tree);

		hs.Save ();
		return 0;
	}
Example #20
0
        public TOutput RenderUrl <TOutput> (string url, IDocGenerator <TOutput> generator, out Node node, HelpSource hintSource = null)
        {
            node = null;
            string internalId = null;
            Dictionary <string, string> context = null;
            HelpSource hs = GetHelpSourceAndIdForUrl(url, hintSource, out internalId, out context, out node);

            return(generator.Generate(hs, internalId, context));
        }
Example #21
0
		/// <summary>
		///    Tree creation and merged tree constructor
		/// </summary>
		public Tree (HelpSource hs, string caption, string url) : this (hs, null, caption, url)
		{
		}
Example #22
0
	public override void Run (IEnumerable<string> args)
	{
		bool replaceNTypes = false;
		var formats = new Dictionary<string, List<string>> ();
		string prefix = "tree";
		var formatOptions = CreateFormatOptions (this, formats);
		var options = new OptionSet () {
			formatOptions [0],
			{ "o|out=",
				"Provides the output file prefix; the files {PREFIX}.zip and " + 
					"{PREFIX}.tree will be created.\n" +
					"If not specified, `tree' is the default PREFIX.",
				v => prefix = v },
			formatOptions [1],
			{"dropns=","The namespace that has been dropped from this version of the assembly.", v => droppedNamespace = v },
			{"ntypes","Replace references to native types with their original types.", v => replaceNTypes=true },
		};
		List<string> extra = Parse (options, args, "assemble", 
				"[OPTIONS]+ DIRECTORIES",
				"Assemble documentation within DIRECTORIES for use within the monodoc browser.");
		if (extra == null)
			return;

		List<Provider> list = new List<Provider> ();
		EcmaProvider ecma = null;
		bool sort = false;
		
		foreach (string format in formats.Keys) {
			switch (format) {
			case "ecma":
				if (ecma == null) {
					ecma = new EcmaProvider ();
					list.Add (ecma);
					sort = true;
				}
				ecma.FileSource = new MDocFileSource(droppedNamespace, string.IsNullOrWhiteSpace(droppedNamespace) ? ApiStyle.Unified : ApiStyle.Classic) {
					ReplaceNativeTypes = replaceNTypes
				};
				foreach (string dir in formats [format])
					ecma.AddDirectory (dir);
				break;

			case "xhtml":
			case "hb":
				list.AddRange (formats [format].Select (d => (Provider) new XhtmlProvider (d)));
				break;

			case "man":
				list.Add (new ManProvider (formats [format].ToArray ()));
				break;

			case "error":
				list.AddRange (formats [format].Select (d => (Provider) new ErrorProvider (d)));
				break;

			case "ecmaspec":
				list.AddRange (formats [format].Select (d => (Provider) new EcmaSpecProvider (d)));
				break;

			case "addins":
				list.AddRange (formats [format].Select (d => (Provider) new AddinsProvider (d)));
				break;
			}
		}

		HelpSource hs = new HelpSource (prefix, true);
		hs.TraceLevel = TraceLevel;

		foreach (Provider p in list) {
			p.PopulateTree (hs.Tree);
		}

		if (sort && hs.Tree != null)
			hs.Tree.RootNode.Sort ();
			      
		//
		// Flushes the EcmaProvider
		//
		foreach (Provider p in list)
			p.CloseTree (hs, hs.Tree);

		hs.Save ();
	}
Example #23
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;
		}
Example #24
0
		public override void CloseTree (HelpSource hs, Tree tree)
		{
			Hashtable entries = config.Compile ();
			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 ();
		}
Example #25
0
	public Tree (HelpSource hs, Node parent, string caption, string element) : base (parent, caption, element)
	{
		HelpSource = hs;
	}
Example #26
0
	//
	// Packs a file with the summary data
	//
	public override void CloseTree (HelpSource hs, Tree tree)
	{
		foreach (DictionaryEntry de in class_summaries){
			XmlDocument doc = new XmlDocument ();
			string ns = (string) de.Key;
			
			ArrayList list = (ArrayList) de.Value;
			list.Sort();

			XmlElement elements = doc.CreateElement ("elements");
			doc.AppendChild (elements);
			
			if (namespace_summaries [ns] != null)
				elements.AppendChild (doc.ImportNode ((XmlNode)namespace_summaries [ns],true));
			else
				elements.AppendChild (doc.CreateElement("summary"));
			
			if (namespace_remarks [ns] != null)
				elements.AppendChild (doc.ImportNode ((XmlNode)namespace_remarks [ns],true));
			else
				elements.AppendChild (doc.CreateElement("remarks"));
			
			hs.Message (TraceLevel.Info, "Have {0} elements in the {1}", list.Count, ns);
			foreach (TypeInfo p in list){
				XmlElement e = null;
				
				switch (p.type_kind){
				case "Class":
					e = doc.CreateElement ("class"); 
					break;
					
				case "Enumeration":
					e = doc.CreateElement ("enum");
					break;
					
				case "Structure":
					e = doc.CreateElement ("struct");
					break;
					
				case "Delegate":
					e = doc.CreateElement ("delegate");
					break;
					
				case "Interface":
					e = doc.CreateElement ("interface");
					break;
				}
				
				e.SetAttribute ("name", p.type_name);
				e.SetAttribute ("fullname", p.type_full);
				e.SetAttribute ("assembly", p.type_assembly);
				XmlNode copy = doc.ImportNode (p.type_doc, true);
				e.AppendChild (copy);
				elements.AppendChild (e);
			}
			hs.PackXml ("xml.summary." + ns, doc,(string) namespace_realpath[ns]);
		}
		
		
		XmlDocument nsSummary = new XmlDocument ();
		XmlElement root = nsSummary.CreateElement ("elements");
		nsSummary.AppendChild (root);
		
		foreach (DictionaryEntry de in namespace_summaries) {
			XmlNode n = (XmlNode)de.Value;
			XmlElement summary = nsSummary.CreateElement ("namespace");
			summary.SetAttribute ("ns", (string)de.Key);
			root.AppendChild (summary);
			if (n != null)
				summary.AppendChild (nsSummary.ImportNode (n,true));
			else
				summary.AppendChild (nsSummary.CreateElement("summary"));
		}
		tree.HelpSource.PackXml ("mastersummary.xml", nsSummary, null);
		AddExtensionMethods (tree);
		AddImageFiles (hs, tree);
	}
Example #27
0
 public override void CloseTree(HelpSource hs, Tree tree)
 {
 }
Example #28
0
		internal void LoadUrl (string url, bool syncTreeView = false, HelpSource source = null, bool addToHistory = true)
		{
			if (url.StartsWith ("#")) {
				Console.WriteLine ("FIXME: Anchor jump");
				return;
			}
			var ts = Interlocked.Increment (ref loadUrlTimestamp);
			Task.Factory.StartNew (() => {
				Node node;
				var res = DocTools.GetHtml (url, source, out node);
				return new { Node = node, Html = res };
			}).ContinueWith (t => {
				var node = t.Result.Node;
				var res = t.Result.Html;
				if (res != null){
					BeginInvokeOnMainThread (() => {
						if (ts < loadUrlTimestamp)
							return;
						currentUrl = node == null ? url : node.PublicUrl;
						if (addToHistory)
							history.AppendHistory (new LinkPageVisit (this, currentUrl));
						LoadHtml (res);
						if (syncTreeView) {
							// When navigation occurs after a link on search result is clicked
							// we need to show the panel so that ShowNode work as expected
							tabSelector.SelectAt (0);
							this.match = node;
						}
						// Bookmark spinner management
						if (currentBookmarkIndex != -1) {
							bookmarkSelector.SelectItem (currentBookmarkIndex);
							currentBookmarkIndex = -1;
						} else {
						    bookmarkSelector.SelectItem (-1);
						}
					});
				}
			});
		}
Example #29
0
	public static string GetHtml (string url, HelpSource help_source, RootTree help_tree)
	{
		Node _;
		return GetHtml (url, help_source, help_tree, out _);
	}
Example #30
0
		public Tree (HelpSource hs, Node parent, string caption, string element)
		{
			HelpSource = hs;
			rootNode = parent == null ? new Node (this, caption, element) : new Node (parent, caption, element);
		}
Example #31
0
	// This should have a little cache or something.
	static XmlDocument GetDocument (HelpSource hs, string fname)
	{
		Stream s = hs.GetHelpStream (fname);
		if (s == null){
			Error ("Could not fetch document {0}", fname);
			return null;
		}
		
		XmlDocument doc = new XmlDocument ();

		doc.Load (s);
		
		return doc;
	}
Example #32
0
	public static string GetHtml (string url, HelpSource help_source, RootTree help_tree, out Node match)
	{
		match = null;
		string html_content = null;
		if (help_source != null)
			html_content = help_source.GetText (url, out match);
		if (html_content == null && help_tree != null) {
			html_content = help_tree.RenderUrl (url, out match);
			if (html_content != null && match != null && match.tree != null)
				help_source = match.tree.HelpSource;
		}

		if (html_content == null)
			return null;

		var html = new StringWriter ();
		html.Write ("<html>\n");
		html.Write ("  <head>\n");
		html.Write ("    <title>");
		html.Write (url);
		html.Write ("</title>\n");

		if (help_source != null && help_source.InlineCss != null) {
			html.Write ("    <style type=\"text/css\">\n");
			html.Write (help_source.InlineCss);
			html.Write ("    </style>\n");
		}
		if (help_source != null && help_source.InlineJavaScript != null) {
			html.Write ("    <script type=\"text/JavaScript\">\n");
			html.Write (help_source.InlineJavaScript);
			html.Write ("    </script>\n");
		}

		html.Write ("  </head>\n");
		html.Write ("  <body>\n");
		html.Write (html_content);
		html.Write ("  </body>\n");
		html.Write ("</html>");
		return html.ToString ();
	}
Example #33
0
	void AddImageFiles (HelpSource hs, Tree tree)
	{
		foreach (string asm in asm_dirs) {
			string path = Path.Combine (asm, "_images");
			if (!Directory.Exists (path))
				return;

#if NET_2_0
			foreach (var img in Directory.GetFiles (path))
#else
			foreach (var img in Directory.EnumerateFiles (path))
#endif
				hs.PackFile (img, Path.GetFileName (img));
		}
	}
	public override void CloseTree (HelpSource hs, Tree tree)
	{
	}
Example #35
0
		internal void LoadUrl (string url, bool syncTreeView = false, HelpSource source = null, bool addToHistory = true)
		{
			if (url.StartsWith ("#")) {
				Console.WriteLine ("FIXME: Anchor jump");
				return;
			}
			// In case user click on an external link e.g. [Android documentation] link at bottom of MonoDroid docs
			if (url.StartsWith ("http://")) {
				UrlLauncher.Launch (url);
				return;
			}
			Console.WriteLine ("Loading {0}", url);
			var ts = Interlocked.Increment (ref loadUrlTimestamp);
			Task.Factory.StartNew (() => {
				Node node;
				var res = DocTools.GetHtml (url, source, out node);
				return new { Node = node, Html = res };
			}).ContinueWith (t => {
				var node = t.Result.Node;
				var res = t.Result.Html;
				if (res != null){
					BeginInvokeOnMainThread (() => {
						if (ts < loadUrlTimestamp)
							return;
						currentUrl = node == null ? url : node.PublicUrl;
						InvalidateRestorableState ();
						if (addToHistory)
							history.AppendHistory (new LinkPageVisit (this, currentUrl));
						LoadHtml (res);
						this.match = node;
						if (syncTreeView) {
							// When navigation occurs after a link on search result is clicked
							// we need to show the panel so that ShowNode work as expected
							tabSelector.SelectAt (0);
						}
						// Bookmark spinner management
						var bookmarkIndex = AppDelegate.BookmarkManager.FindIndexOfBookmarkFromUrl (url);
						if (bookmarkIndex == -1 || bookmarkIndex < bookmarkSelector.ItemCount)
							bookmarkSelector.SelectItem (bookmarkIndex);
					});
				}
			});
		}
Example #36
0
        public bool AddSourceFile(string sourceFile)
        {
            if (this.loadedSourceFiles.Contains(sourceFile))
            {
                return(false);
            }

            Node        node        = this.LookupEntryPoint("various") ?? base.RootNode;
            XmlDocument xmlDocument = new XmlDocument();

            try {
                xmlDocument.Load(sourceFile);
            } catch {
                bool result = false;
                return(result);
            }

            XmlNodeList extra_nodes = xmlDocument.SelectNodes("/monodoc/node");

            if (extra_nodes.Count > 0)
            {
                this.Populate(node, extra_nodes);
            }

            XmlNodeList sources = xmlDocument.SelectNodes("/monodoc/source");

            if (sources == null)
            {
                Console.Error.WriteLine("Error: No <source> section found in the {0} file", sourceFile);
                return(false);
            }

            loadedSourceFiles.Add(sourceFile);
            foreach (XmlNode xmlNode in sources)
            {
                XmlAttribute a = xmlNode.Attributes["provider"];
                if (a == null)
                {
                    Console.Error.WriteLine("Error: no provider in <source>");
                    continue;
                }
                string provider = a.InnerText;
                a = xmlNode.Attributes["basefile"];
                if (a == null)
                {
                    Console.Error.WriteLine("Error: no basefile in <source>");
                    continue;
                }
                string basefile = a.InnerText;
                a = xmlNode.Attributes["path"];
                if (a == null)
                {
                    Console.Error.WriteLine("Error: no path in <source>");
                    continue;
                }
                string     path         = a.InnerText;
                string     basefilepath = Path.Combine(Path.GetDirectoryName(sourceFile), basefile);
                HelpSource helpSource   = RootTree.GetHelpSource(provider, basefilepath);
                if (helpSource != null)
                {
                    helpSource.RootTree = this;
                    this.helpSources.Add(helpSource);
                    this.nameToHelpSource[path] = helpSource;
                    Node node2 = this.LookupEntryPoint(path);
                    if (node2 == null)
                    {
                        Console.Error.WriteLine("node `{0}' is not defined on the documentation map", path);
                        node2 = node;
                    }
                    foreach (Node current in helpSource.Tree.RootNode.ChildNodes)
                    {
                        node2.AddNode(current);
                    }
                    node2.Sort();
                }
            }
            return(true);
        }