public static int Main(string[] args) { bool errorsFound = false; try { Gtk.Application.Init(); var apsimDirectory = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..")); // Set the current directory to the bin directory so that APSIM can find sqlite3.dll var binDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Directory.SetCurrentDirectory(binDirectory); // Determine where we are going to put the documentation. var destinationFolder = Path.Combine(Path.GetTempPath(), "ApsimX", "AutoDoc"); Directory.CreateDirectory(destinationFolder); // Create a string builder for writing the html index file. var htmlBuilder = new StringBuilder(); htmlBuilder.AppendLine("<html>"); htmlBuilder.AppendLine("<body>"); // Was a title for the generated html file given as argument 1? var version = GetVersion(); var serverFtpFolder = "ftp://apsimdev.apsim.info/ApsimX/Releases/" + version; var serverHttpFolder = "https://apsimdev.apsim.info/ApsimX/Releases/" + version; htmlBuilder.AppendLine("<h1>Documentation for version " + version + "</h1>"); // Read the documentation instructions file. var documentationFileName = Path.Combine(apsimDirectory, "Docs", "CreateDocumentation", "Documentation.json"); var instructions = JObject.Parse(File.ReadAllText(documentationFileName)); // Keep track of all exceptions so that we can show them at the end. var exceptions = new List <Exception>(); // Loop through all "Tables" element in the input json file. foreach (JObject tableInstruction in instructions["Tables"] as JArray) { // Write html heading for table. htmlBuilder.AppendLine("<h2>" + tableInstruction["Title"].ToString() + "</h2>"); // Create a data table. var documentationTable = CreateTable(tableInstruction, apsimDirectory, destinationFolder, serverHttpFolder); if (documentationTable == null) { errorsFound = true; } else { // Write table to html. htmlBuilder.AppendLine(DataTableUtilities.ToHTML(documentationTable, writeHeaders: true)); } } // Close the open html tags. htmlBuilder.AppendLine("</body>"); htmlBuilder.AppendLine("</html>"); // Write the html to file. var htmlFileName = Path.Combine(destinationFolder, "index.html"); File.WriteAllText(htmlFileName, htmlBuilder.ToString()); // Upload to server Upload(destinationFolder, serverFtpFolder); } catch (Exception err) { Console.WriteLine(err.ToString()); errorsFound = true; } if (errorsFound) { Console.WriteLine("Errors were found creating documentation"); return(1); } else { return(0); } }
private string DocumentModel(IModel model) { StringBuilder html = new StringBuilder(); html.AppendLine("<html><body>"); html.AppendLine($"<h1>{model.Name} Description</h1>"); html.AppendLine("<h2>General Description</h2>"); string summary = markdown.Transform(AutoDocumentation.GetSummary(model.GetType())); html.Append($"<p>{summary}</p>"); string remarks = markdown.Transform(AutoDocumentation.GetRemarks(model.GetType())); if (!string.IsNullOrEmpty(remarks)) { html.AppendLine("<h2>Remarks</h2>"); html.AppendLine($"<p>{remarks}</p>"); } string typeName = model.GetType().Name; html.AppendLine($"<h1>{model.Name} Configuration</h1>"); html.AppendLine($"<h2>Inputs</h2>"); //html.AppendLine($"<h3>Fixed Parameters</h3>"); //html.AppendLine("<p>todo - requires GridView</p>"); html.AppendLine("<h3>Variable Parameters</h2>"); DataTable functionTable = GetDependencies(model, m => typeof(IFunction).IsAssignableFrom(GetMemberType(m))); html.AppendLine(DataTableUtilities.ToHTML(functionTable, true)); html.AppendLine("<h3>Other dependencies"); DataTable depsTable = GetDependencies(model, m => !typeof(IFunction).IsAssignableFrom(GetMemberType(m))); html.AppendLine(DataTableUtilities.ToHTML(depsTable, true)); DataTable publicMethods = GetPublicMethods(model); if (publicMethods.Rows.Count > 0) { html.AppendLine("<h2>Public Methods</h2>"); html.AppendLine(DataTableUtilities.ToHTML(publicMethods, true)); } DataTable events = GetEvents(model); if (events.Rows.Count > 0) { html.AppendLine("<h2>Events</h2>"); html.AppendLine(DataTableUtilities.ToHTML(events, true)); } DataTable outputs = GetOutputs(model); if (outputs.Rows.Count > 0) { html.AppendLine("<h2>Model Outputs</h2>"); html.AppendLine(DataTableUtilities.ToHTML(outputs, true)); } html.Append("</body></html>"); return(html.ToString()); }