void GenerateCache(string basePath, string treeFile, string outDir) { Tree tree = new Tree(null, treeFile); RootTree docRoot = RootTree.LoadTree(); string helpSourceName = Path.GetFileName(basePath); HelpSource hs = docRoot.HelpSources.Cast <HelpSource> () .FirstOrDefault(h => h.Name == helpSourceName); if (hs == null) { throw new Exception("Only installed .tree and .zip files are supported."); } foreach (Node node in tree.TraverseDepthFirst <Node, Node> (t => t, t => t.Nodes.Cast <Node> ())) { var url = node.URL; Message(TraceLevel.Info, "\tProcessing URL: {0}", url); if (string.IsNullOrEmpty(url)) { continue; } var file = XmlDocUtils.GetCachedFileName(outDir, url); using (var o = File.AppendText(file)) { Node _; // Sometimes the HelpSource won't directly support a url. // Case in point: the Tree will contain N:Enter.Namespace.Here nodes // which aren't supported by HelpSource.GetText. // If this happens, docRoot.RenderUrl() works. // (And no, we can't always use docRoot.RenderUrl() for URLs like // "ecma:0#Foo/", as that'll just grab the 0th stream contents from // the first EcmaHelpSource found... string contents = hs.GetText(url, out _) ?? docRoot.RenderUrl(url, out _); o.Write(contents); } } }
void GenerateCache(Options opts, string basePath, string format, string outDir) { var hs = RootTree.GetHelpSource(format, basePath); if (hs == null) { Error("Unable to find a HelpSource for provider '{0}' and file '{1}.tree'.", format, basePath); } var tree = hs.Tree; RootTree docRoot = null; if (!opts.UseSystemSources) { docRoot = RootTree.LoadTree(null, null, opts.Sources); } else { docRoot = RootTree.LoadTree(); foreach (var source in opts.Sources) { docRoot.AddSourceFile(source); } } hs.RootTree = docRoot; string helpSourceName = Path.GetFileName(basePath); foreach (Node node in tree.TraverseDepthFirst <Node, Node> (t => t, t => t.Nodes.Cast <Node> ())) { var url = node.URL; Message(TraceLevel.Info, "\tProcessing URL: {0}", url); if (string.IsNullOrEmpty(url)) { continue; } var file = XmlDocUtils.GetCachedFileName(outDir, url); using (var o = File.AppendText(file)) { Node _; string contents = hs.GetText(url, out _) ?? hs.RenderNamespaceLookup(url, out _); o.Write(contents); } } }