Beispiel #1
0
        public void Write(DoxDocument dox, DoxFormattingContext outputContext)
        {
            var output = outputContext.Output;

            using (var hw = new HtmlTextWriter(output))
            {
                var html = new HtmlBuilder(hw);
                html.div().attCls("dox").att("dox:format", "sql");

                if (dox.DbElement != null)
                {
                    var context = new DatabaseContext
                    {
                        BookName = outputContext.BookName,
                        DbName = dox.DbElement.DbName
                    };

                    if (dox.DbElement.Database != null)
                        WriteDatabaseDocument(dox.DbElement.Database, html, context);

                    else if (dox.DbElement.Table != null)
                        WriteTableDocument(dox.DbElement.Table, html, context);

                    else if (dox.DbElement.View != null)
                        WriteViewDocument(dox.DbElement.View, html, context);

                    else if (dox.DbElement.StoredProcedure != null)
                        WriteStoredProcedureDocument(dox.DbElement.StoredProcedure, html, context);
                }

                html.c(); // dox div
            }
        }
Beispiel #2
0
        private void WriteViewDocument(View view, HtmlBuilder html, DatabaseContext context)
        {
            html.h1(String.Format("View: {0}", view.Name));

            html.e("table");
            html.tr().td().attCls("label").text("Database:").c().td();
            String relDoc = String.Format("{0}.{1}.{1}", context.BookName, context.DbName);
            html.internalLink(context.DbName, "db-entity-name", relDoc, view.Name);
            html.c().c();
            html.c(); //table

            RenderColumnsTable(view.Columns, html, context);
        }
        private void RenderColumnsTable(IEnumerable<Column> columns, HtmlBuilder html, DatabaseContext context)
        {
            html.h2("Columns");

            html.table(0, 0).att("width", "100%").attCls("members");

            html.dbColumnHeader();
            foreach (var c in columns)
            {
                html.tr();
                html.rowHeader(false);

                html.td();
                if (c.IsInPrimaryKey) html.attCls("key primary-key");
                else if (c.IsForeignKey) html.attCls("key foreign-key");
                else html.attCls("key");
                html.text(c.Name);
                if (!c.Descritpion.IsNullOrEmpty())
                {
                    html.div().attCls("summary");
                    html.text(c.Descritpion);
                    html.c(); // summary
                }
                html.c(); // td

                html.td();
                html.anchor(c.Name);
                html.dataType(c.DataType);
                html.c();

                html.td();

                if (c.ReferenceData != null)
                {
                    string relDoc = String.Format("{0}.{1}.Tables.{2}.{3}", context.BookName, context.DbName, c.ReferenceData.ReferencedTableSchema, c.ReferenceData.ReferencedTable);
                    html.internalLink(String.Format("{0}.{1}", c.ReferenceData.ReferencedTable, c.ReferenceData.ReferencedColumn), "db-entity-name", relDoc, c.ReferenceData.ReferencedColumn);
                }
                else
                    html.nbsp();

                html.c(); // td
                html.c(); // tr
            }

            html.c(); // table
        }
        private void WriteStoredProcedureDocument(StoredProcedure sp, HtmlBuilder html, DatabaseContext context)
        {
            html.h1(String.Format("Stored Procedure: {0}", sp.Name));

            html.e("table");
            html.tr().td().attCls("label").text("Database:").c().td();
            String relDoc = String.Format("{0}.{1}.{1}", context.BookName, context.DbName);
            html.internalLink(context.DbName, "db-entity-name", relDoc, sp.Name);
            html.c().c();
            html.c(); //table

            html.h2("Parameters");
            if (sp.Parameters != null && sp.Parameters.Count > 0)
            {
                html.table(0, 0).att("width", "100%").attCls("members");
                html.dbSpParamHeader();

                foreach (var p in sp.Parameters)
                {
                    html.tr()
                        .rowHeader(false)
                        .td()
                            .attCls(p.IsOutputParameter ? "sp-parameter output" : "sp-parameter input")
                            .att("title", p.IsOutputParameter ? "output" : "input")
                            .text(p.Name.TrimStart('@'))
                        .c()
                        .td()
                            .dataType(p.DataType)
                        .c()
                    .c();
                }

                html.c(); // table
            }
            else
                html.text("This stored procedure does not receive parameters.");
        }
        private void WriteDatabaseDocument(Database db, HtmlBuilder html, DatabaseContext context)
        {
            html.h1(String.Format("Database: {0}", db.Name));

            #region Tables

            html.e("a").attCls("tables").c();
            html.h2("Tables");
            if (db.Tables == null || db.Tables.Count == 0)
                html.text("This database has no tables.");
            else
            {
                html.table(0, 0).att("width", "100%").attCls("members");
                html.dbTableHeader();

                foreach (var t in db.Tables)
                {
                    html.tr().attCls("expandable");
                    html.td().attCls("micon").e("a").attCls("exi").att("href", "#expand").nbsp().c().c();
                    String relDoc = String.Format("{0}.{1}.Tables.{2}.{3}", context.BookName, context.DbName, t.SchemaName, t.Name);
                    html.td().internalLink(t.Name, "db-entity-name " + t.Name, relDoc); // Anchor and link in one element (e.g. <a class="db-entity-name Parties" ...>)
                    html.div().attCls("details");
                    RenderColumnsSection(t.Columns, html);
                    html.c(); // details
                    html.c(); // td
                    html.td().text(t.SchemaName).c();
                    html.c(); // tr
                }

                html.c(); // table
            }

            #endregion

            #region Views

            html.e("a").attCls("views").c();
            html.h2("Views");
            if (db.Views == null || db.Views.Count == 0)
                html.text("This database has no views.");
            else
            {
                html.table(0, 0).att("width", "100%").attCls("members");
                html.dbTableHeader();

                foreach (var v in db.Views)
                {
                    html.tr().attCls("expandable");
                    html.td().attCls("micon").e("a").attCls("exi").att("href", "#expand").nbsp().c().c();
                    String relDoc = String.Format("{0}.{1}.Views.{2}.{3}", context.BookName, context.DbName, v.SchemaName, v.Name);
                    html.td().internalLink(v.Name, "db-entity-name " + v.Name, relDoc);
                    html.div().attCls("details");
                    RenderColumnsSection(v.Columns, html);
                    html.c(); // details
                    html.c(); // td

                    html.td().text(v.SchemaName).c();

                    html.c(); // tr
                }

                html.c(); // table
            }

            #endregion

            #region Stored procedures

            html.e("a").attCls("stored-procedures").c();
            html.h2("Stored procedures");
            if (db.StoredProcedures == null || db.StoredProcedures.Count == 0)
                html.text("This database has no stored procedures.");
            else
            {
                html.table(0, 0).att("width", "100%").attCls("members");
                html.dbSpHeader();

                foreach (var sp in db.StoredProcedures)
                {
                    html.tr().attCls("expandable");
                    html.td().attCls("micon").e("a").attCls("exi").att("href", "#expand").nbsp().c().c();

                    String relDoc = String.Format("{0}.{1}.Procedures.{2}", context.BookName, context.DbName, sp.Name);
                    html.td().internalLink(sp.Name, "db-entity-name " + sp.Name, relDoc);

                    html.div().attCls("details");
                    RenderParametersSection(sp.Parameters, html);
                    html.c(); // details

                    html.c(); // td
                    html.c(); // tr
                }

                html.c(); // table
            }

            #endregion
        }