public static int Main(string[] args) { CommandLine commandLine; if (!CommandLine.TryParseArguments(args, out commandLine)) { CommandLine.ShowHelp(); return(1); } try { DocCompiler docCompiler = new DocCompiler(); return(docCompiler.Run(commandLine)); } catch (Exception e) { Console.Error.WriteLine(e.Message); #if DEBUG throw; #else return(1); #endif } }
public static int Main(string[] args) { CommandLine commandLine; if (!CommandLine.TryParseArguments(args, out commandLine)) { CommandLine.ShowHelp(); return 1; } try { DocCompiler docCompiler = new DocCompiler(); return docCompiler.Run(commandLine); } catch (Exception e) { Console.Error.WriteLine(e.Message); #if DEBUG throw; #else return 1; #endif } }
/// <summary> /// Run the application. /// </summary> /// <param name="commandLine">The command line arguments.</param> /// <returns>The error code for the application.</returns> private int Run(CommandLine commandLine) { Uri outputUri = new Uri(commandLine.OutputFolder); List <IndexedDocument> indexedDocs = new List <IndexedDocument>(); // Build up a list of directories to ignore when processing documents. var ignored = commandLine.Ignored.Select(dir => Path.Combine(commandLine.InputFolder, dir)); foreach (string documentPath in Directory.GetFiles(commandLine.InputFolder, "*.*", SearchOption.AllDirectories)) { // Skip processing if the document path is ignored. if (ignored.Any(str => documentPath.StartsWith(str, StringComparison.OrdinalIgnoreCase))) { break; } Document doc = Document.Create(documentPath, commandLine.InputFolder); string documentOutputPath = Path.Combine(commandLine.OutputFolder, doc.RelativeOutputPath); string content = doc.Content; List <string> defines = new List <string>(); defines.Add(String.Concat("content=", content)); // ensure "content" variable is first so it always wins. string layout; if (doc.Meta.TryGetValue("layout", out layout)) { string layoutContent; if (!this.TryLoadLayout(commandLine.LayoutsFolder, layout, out layoutContent)) { throw new ArgumentException(String.Format("Error could not find layout: {0} in the layout folder: {1} while processing document: {2}", layout, commandLine.LayoutsFolder, doc.RelativePath)); } content = layoutContent; // replace the content with the layout, hopefully the layout has "{{content}}" in it somewhere. } defines.AddRange(commandLine.Variables); // command-line variables trump document meta. defines.AddRange(doc.Meta.Select(meta => String.Concat(meta.Key, "=", meta.Value))); // document meta is last. content = SubstituteVariables(defines, content); content = DocCompiler.FixRelativePaths(content, new Uri(documentOutputPath), outputUri); var indexedDoc = new IndexedDocument(doc, commandLine.OutputFolder); indexedDocs.Add(indexedDoc); if (!indexedDoc.ChmIgnored) { Output(content, documentOutputPath); } } List <IndexedDocument> ordered = OrderIndexedDocuments(indexedDocs); // Useful context when debugging. //DumpIndex(rootDoc); //Console.WriteLine("------"); //DumpOrderedIndexedDocuments(ordered); if (!String.IsNullOrEmpty(commandLine.AppendMarkdownTableOfContentsFile)) { AppendMarkdownTableOfContents(ordered, commandLine.AppendMarkdownTableOfContentsFile, commandLine.IgnoreXsdSimpleTypeInTableOfContents); } if (!String.IsNullOrEmpty(commandLine.HtmlHelpProjectFile)) { GenerateHtmlHelpProject(ordered, commandLine.HtmlHelpProjectFile, commandLine.OutputFolder); } return(0); }