コード例 #1
0
        /// <summary>
        /// Export the initial conditions table to markdown format.
        /// </summary>
        /// <returns></returns>
        public string ToMarkdown()
        {
            DataTable scalarsTable = new DataTable();
            DataTable vectorsTable = new DataTable();

            scalarsTable.Columns.Add("Name");
            scalarsTable.Columns.Add("Value");
            foreach (InitialCondition condition in Conditions)
            {
                if (condition.TypeName.Contains("[]"))
                {
                    string columnName = condition.Name;
                    if (!string.IsNullOrEmpty(condition.Units))
                    {
                        columnName += $" ({condition.Units})";
                    }

                    string[] value = condition.Value.Split(',');
                    if (condition.TypeName == "Double[]")
                    {
                        if (string.IsNullOrEmpty(condition.DisplayFormat))
                        {
                            DataTableUtilities.AddColumn(vectorsTable, columnName, MathUtilities.StringsToDoubles(value));
                        }
                        else
                        {
                            value = value.Select(x => double.Parse(x).ToString(condition.DisplayFormat)).ToArray();
                            DataTableUtilities.AddColumn(vectorsTable, columnName, value);
                        }
                    }
                    else
                    {
                        DataTableUtilities.AddColumn(vectorsTable, columnName, value);
                    }
                }
                else
                {
                    string value = condition.Value;
                    if (!string.IsNullOrEmpty(condition.Units))
                    {
                        value += $" ({condition.Units})";
                    }
                    scalarsTable.Rows.Add(condition.Description, value);
                }
            }

            StringBuilder markdown = new StringBuilder();

            markdown.AppendLine($"### {relativePath}");
            markdown.AppendLine();
            if (scalarsTable.Rows.Count > 0)
            {
                markdown.AppendLine(DataTableUtilities.ToMarkdown(scalarsTable, true));
            }
            if (vectorsTable.Rows.Count > 0)
            {
                markdown.AppendLine(DataTableUtilities.ToMarkdown(vectorsTable, true));
            }
            return(markdown.ToString());
        }
コード例 #2
0
        /// <summary>
        /// Write the specified table to the TextWriter.
        /// </summary>
        /// <param name="writer">The writer to write to</param>
        /// <param name="table">The table to write</param>
        /// <param name="outtype">Indicates the format to be produced</param>
        /// <param name="className">The class name of the generated html table</param>
        /// <param name="document">Document object if using MigraDoc to generate output, null otherwise </param>
        private static void WriteTable(TextWriter writer, DataTable table, OutputType outtype, string className, Document document)
        {
            bool showHeadings = className != "PropertyTable";

            if (outtype == OutputType.html)
            {
                if (showHeadings)
                {
                    writer.WriteLine("<table class='headered'>");
                    writer.Write("<tr>");
                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        writer.Write("<th");
                        if (i == 0)
                        {
                            writer.Write(" class='col1'");
                        }
                        writer.Write(">" + table.Columns[i].ColumnName + "</th>");
                    }
                    writer.WriteLine();
                }
                else
                {
                    writer.WriteLine("<table>");
                }

                foreach (DataRow row in table.Rows)
                {
                    bool titleRow = Convert.IsDBNull(row[0]);
                    if (titleRow)
                    {
                        writer.Write("<tr class='total'>");
                    }
                    else
                    {
                        writer.Write("<tr>");
                    }

                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        string st;
                        if (titleRow && i == 0)
                        {
                            st = "Total";
                        }
                        else
                        {
                            st = row[i].ToString();
                        }

                        writer.Write("<td");
                        if (i == 0)
                        {
                            writer.Write(" class='col1'");
                        }
                        writer.Write(">");
                        writer.Write(st);
                        writer.Write("</td>");
                    }
                    writer.WriteLine("</tr>");
                }
                writer.WriteLine("</table><br/>");
            }
            else if (outtype == OutputType.rtf)
            {
                MigraDoc.DocumentObjectModel.Tables.Table tabl = new MigraDoc.DocumentObjectModel.Tables.Table();
                tabl.Borders.Width = 0.75;

                foreach (DataColumn col in table.Columns)
                {
                    Column column = tabl.AddColumn(Unit.FromCentimeter(18.0 / table.Columns.Count));
                }

                if (showHeadings)
                {
                    MigraDoc.DocumentObjectModel.Tables.Row row = tabl.AddRow();
                    row.Shading.Color  = Colors.PaleGoldenrod;
                    tabl.Shading.Color = new Color(245, 245, 255);
                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        Cell      cell      = row.Cells[i];
                        Paragraph paragraph = cell.AddParagraph();
                        if (i == 0)
                        {
                            paragraph.Format.Alignment = ParagraphAlignment.Left;
                        }
                        else
                        {
                            paragraph.Format.Alignment = ParagraphAlignment.Right;
                        }
                        paragraph.AddText(table.Columns[i].ColumnName);
                    }
                }

                foreach (DataRow row in table.Rows)
                {
                    bool   titleRow = Convert.IsDBNull(row[0]);
                    string st;
                    MigraDoc.DocumentObjectModel.Tables.Row newRow = tabl.AddRow();

                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        if (titleRow && i == 0)
                        {
                            st = "Total";
                            newRow.Format.Font.Color = Colors.DarkOrange;
                            newRow.Format.Font.Bold  = true;
                        }
                        else
                        {
                            st = row[i].ToString();
                        }

                        Cell      cell      = newRow.Cells[i];
                        Paragraph paragraph = cell.AddParagraph();
                        if (!showHeadings)
                        {
                            cell.Borders.Style         = BorderStyle.None;
                            paragraph.Format.Alignment = ParagraphAlignment.Left;
                        }
                        else if (i == 0)
                        {
                            paragraph.Format.Alignment = ParagraphAlignment.Left;
                        }
                        else
                        {
                            paragraph.Format.Alignment = ParagraphAlignment.Right;
                        }

                        if (showHeadings && i == 0)
                        {
                            paragraph.AddFormattedText(st, TextFormat.Bold);
                        }
                        else
                        {
                            paragraph.AddText(st);
                        }
                    }
                }

                document.LastSection.Add(tabl);
                document.LastSection.AddParagraph(); // Just to give a bit of spacing
            }
            else if (outtype == OutputType.Markdown)
            {
                writer.WriteLine("```");
                writer.WriteLine(DataTableUtilities.ToMarkdown(table, true));
                writer.WriteLine("```");
                writer.WriteLine();
            }
            else
            {
                DataTableUtilities.DataTableToText(table, 0, "  ", showHeadings, writer);
            }
        }
コード例 #3
0
        private string DocumentModel(IModel model)
        {
            StringBuilder markdown = new StringBuilder();

            markdown.AppendLine($"# {model.Name} Description");
            markdown.AppendLine();
            markdown.AppendLine("## General Description");
            markdown.AppendLine();
            string summary = AutoDocumentation.GetSummary(model.GetType()).Replace("            ", "");

            markdown.AppendLine(summary);
            markdown.AppendLine();

            string remarks = AutoDocumentation.GetRemarks(model.GetType());

            if (!string.IsNullOrEmpty(remarks))
            {
                markdown.AppendLine("## Remarks");
                markdown.AppendLine();
                markdown.AppendLine(remarks);
                markdown.AppendLine();
            }

            string typeName = model.GetType().Name;

            markdown.AppendLine($"# {model.Name} Configuration");
            markdown.AppendLine();
            markdown.AppendLine("## Inputs");
            markdown.AppendLine();
            //html.AppendLine($"<h3>Fixed Parameters</h3>");
            //html.AppendLine("<p>todo - requires GridView</p>");

            markdown.AppendLine("### Variable Parameters");
            markdown.AppendLine();
            DataTable functionTable = GetDependencies(model, m => typeof(IFunction).IsAssignableFrom(GetMemberType(m)));

            markdown.AppendLine(DataTableUtilities.ToMarkdown(functionTable, true));

            markdown.AppendLine("### Other dependencies");
            DataTable depsTable = GetDependencies(model, m => !typeof(IFunction).IsAssignableFrom(GetMemberType(m)));

            markdown.AppendLine(DataTableUtilities.ToMarkdown(depsTable, true));
            markdown.AppendLine();

            DataTable publicMethods = GetPublicMethods(model);

            if (publicMethods.Rows.Count > 0)
            {
                markdown.AppendLine("## Public Methods");
                markdown.AppendLine();
                markdown.AppendLine(DataTableUtilities.ToMarkdown(publicMethods, true));
                markdown.AppendLine();
            }

            DataTable events = GetEvents(model);

            if (events.Rows.Count > 0)
            {
                markdown.AppendLine("## Events");
                markdown.AppendLine();
                markdown.AppendLine(DataTableUtilities.ToMarkdown(events, true));
                markdown.AppendLine();
            }

            DataTable outputs = GetOutputs(model);

            if (outputs.Rows.Count > 0)
            {
                markdown.AppendLine("## Model Outputs");
                markdown.AppendLine();
                markdown.AppendLine(DataTableUtilities.ToMarkdown(outputs, true));
                markdown.AppendLine();
            }

            return(markdown.ToString());
        }
コード例 #4
0
        /// <summary>
        /// Write the specified table to the TextWriter.
        /// </summary>
        /// <param name="writer">The writer to write to</param>
        /// <param name="table">The table to write</param>
        /// <param name="outtype">Indicates the format to be produced</param>
        /// <param name="className">The class name of the generated html table</param>
        private static void WriteTable(TextWriter writer, DataTable table, OutputType outtype, string className)
        {
            bool showHeadings = className != "PropertyTable";

            if (outtype == OutputType.html)
            {
                if (showHeadings)
                {
                    writer.WriteLine("<table class='headered'>");
                    writer.Write("<tr>");
                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        writer.Write("<th");
                        if (i == 0)
                        {
                            writer.Write(" class='col1'");
                        }
                        writer.Write(">" + table.Columns[i].ColumnName + "</th>");
                    }
                    writer.WriteLine();
                }
                else
                {
                    writer.WriteLine("<table>");
                }

                foreach (DataRow row in table.Rows)
                {
                    bool titleRow = Convert.IsDBNull(row[0]);
                    if (titleRow)
                    {
                        writer.Write("<tr class='total'>");
                    }
                    else
                    {
                        writer.Write("<tr>");
                    }

                    for (int i = 0; i < table.Columns.Count; i++)
                    {
                        string st;
                        if (titleRow && i == 0)
                        {
                            st = "Total";
                        }
                        else
                        {
                            st = row[i].ToString();
                        }

                        writer.Write("<td");
                        if (i == 0)
                        {
                            writer.Write(" class='col1'");
                        }
                        writer.Write(">");
                        writer.Write(st);
                        writer.Write("</td>");
                    }
                    writer.WriteLine("</tr>");
                }
                writer.WriteLine("</table><br/>");
            }
            else if (outtype == OutputType.Markdown)
            {
                writer.WriteLine(DataTableUtilities.ToMarkdown(table, true));
                writer.WriteLine();
            }
            else
            {
                DataTableUtilities.DataTableToText(table, 0, "  ", showHeadings, writer);
            }
        }
コード例 #5
0
        private string DocumentModel(IModel model)
        {
            StringBuilder markdown = new StringBuilder();

            string summary = AutoDocumentation.GetSummary(model.GetType());

            markdown.AppendLine($"# {model.Name} Description");
            markdown.AppendLine();
            markdown.AppendLine(summary);
            markdown.AppendLine();

            string remarks = AutoDocumentation.GetRemarks(model.GetType());

            if (!string.IsNullOrEmpty(remarks))
            {
                markdown.AppendLine($"# Remarks");
                markdown.AppendLine();
                markdown.AppendLine(remarks);
                markdown.AppendLine();
            }

            string    typeName      = model.GetType().Name;
            DataTable functionTable = GetDependencies(model, m => typeof(IFunction).IsAssignableFrom(GetMemberType(m)));
            DataTable depsTable     = GetDependencies(model, m => !typeof(IFunction).IsAssignableFrom(GetMemberType(m)));
            DataTable publicMethods = GetPublicMethods(model);
            DataTable events        = GetEvents(model);
            DataTable outputs       = GetOutputs(model);

            if (functionTable.Rows.Count > 0 ||
                depsTable.Rows.Count > 0 ||
                publicMethods.Rows.Count > 0 ||
                events.Rows.Count > 0 ||
                outputs.Rows.Count > 0)
            {
                markdown.AppendLine($"# {model.Name} Configuration");
                markdown.AppendLine();

                if (functionTable.Rows.Count > 0 || depsTable.Rows.Count > 0)
                {
                    markdown.AppendLine("## Inputs");
                    markdown.AppendLine();

                    if (functionTable.Rows.Count > 0)
                    {
                        markdown.AppendLine("### Variable Dependencies");
                        markdown.AppendLine();
                        markdown.AppendLine(DataTableUtilities.ToMarkdown(functionTable, true));
                        markdown.AppendLine();
                    }

                    if (depsTable.Rows.Count > 0)
                    {
                        markdown.AppendLine("### Fixed Dependencies");
                        markdown.AppendLine();
                        markdown.AppendLine(DataTableUtilities.ToMarkdown(depsTable, true));
                        markdown.AppendLine();
                    }
                }

                if (publicMethods.Rows.Count > 0)
                {
                    markdown.AppendLine("## Public Methods");
                    markdown.AppendLine();
                    markdown.AppendLine(DataTableUtilities.ToMarkdown(publicMethods, true));
                    markdown.AppendLine();
                }

                if (events.Rows.Count > 0)
                {
                    markdown.AppendLine("## Public Events");
                    markdown.AppendLine();
                    markdown.AppendLine(DataTableUtilities.ToMarkdown(events, true));
                    markdown.AppendLine();
                }

                if (outputs.Rows.Count > 0)
                {
                    markdown.AppendLine("## Outputs");
                    markdown.AppendLine();
                    markdown.AppendLine(DataTableUtilities.ToMarkdown(outputs, true));
                    markdown.AppendLine();
                }
            }

            return(markdown.ToString());
        }