Esempio n. 1
0
        void Paragraph(string className, Bootstrap4 content, string data, string textType = null)
        {
            if (data == null)
            {
                return;
            }

            if (textType != null)
            {
                className = ($"{className} " + textType == null ? string.Empty : "text-" + textType).Trim();
            }

            foreach (XNode n in XElement.Parse($"<data>{data}</data>").Nodes())
            {
                string s = n.ToString();
                if (s.StartsWith("<see"))
                {
                    s = s.GetString(-1, ":", "/>").TrimEnd(' ', '"');
                    bool done = false;
                    try
                    {
                        Type t = AppDom.FindType(s, AppDom.LoadMode.NoException);
                        if (t != null && t.IsValueType && !t.IsEnum && !t.IsPrimitive)
                        {
                            var layout = RowLayout.CreateTyped(t);
                            content.Link($"Table {layout.Name}", "/Explain?type=" + s, textType == null ? null : "btn btn-sm btn-outline-" + textType);
                            done = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Error explaining type {0}. {1} Falling back to simple description.", s, ex);
                    }
                    if (!done)
                    {
                        content.Link(s.AfterLast('.'), "/Explain?type=" + s, textType == null ? null : "btn btn-sm btn-outline-" + textType);
                    }
                    continue;
                }
                content.AddHtml(s);
            }
        }
Esempio n. 2
0
        void ExplainFunction(WebData data, WebServerMethod function)
        {
            var html = new HtmlPageBuilder(data.Request);
            {
                string   path  = string.Empty;
                string[] parts = function.FullPaths.First().Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                int      last  = parts.Length - 1;
                for (int n = 0; n < parts.Length; n++)
                {
                    path += "/" + parts[n];
                    html.Breadcrump.Add(new WebLink()
                    {
                        Text = parts[n], Link = (n != last) ? $"/Explain?functions={path}" : $"/Explain?function={path}"
                    });
                }
            }

            Bootstrap4        content  = html.Content;
            WebServerAuthType authType = function.PageAttribute?.AuthType ?? WebServerAuthType.None;
            {
                string link = function.FullPaths.First();
                var    head = new Bootstrap4();
                if (authType != WebServerAuthType.None)
                {
                    // head.DivOpen(Bootstrap4.Item.float_right);
                    head.DivOpen(Bootstrap4.Item.float_right);
                    AddBadges(head, function.PageAttribute);
                    head.DivClose(Bootstrap4.Item.float_right);

                    // head.AddHtml("<br/>");
                }
                head.AddHtml("<h2>");
                head.AddHtml(function.Method.Name.SplitCamelCase().Join("&nbsp;"));
                if (function.Parameters.Length > 0)
                {
                    head.AddHtml(" (");
                    head.AddHtml(function.ParameterString());
                    head.AddHtml(")");
                }
                head.AddHtml("</h2>");

                head.DivOpen(Bootstrap4.Item.float_right);
                head.Link("html", link + ".html", "btn btn-sm btn-outline-primary");
                head.Link("json", link + ".json", "btn btn-sm btn-outline-primary");
                head.Link("xml", link + ".xml", "btn btn-sm btn-outline-primary");
                head.Link("plain", link + ".txt", "btn btn-sm btn-outline-primary");
                head.DivClose(Bootstrap4.Item.float_right);

                head.AddHtml(function.Method.DeclaringType.AssemblyQualifiedName);
                content.CardOpen(head.ToString());
            }
            XNetDocItem doc = documentation.GetMethod(function.Method);

            DocumentHtml(content, doc, function.IsAction ? "Generic action" : function.Method.ToString());
            content.ListGroupOpen();
            int i = 0;

            foreach (ParameterInfo parameter in function.Parameters)
            {
                if (parameter.ParameterType == typeof(WebData))
                {
                    continue;
                }

                ParameterHtml(content, i++, parameter, doc);
            }
            content.ListGroupClose();
            content.CardClose();
            content.AddHtml("&nbsp;");
            var message = WebMessage.Create("Explain " + function.Name, string.Format("Explain function {0}", function));

            data.Answer = html.ToAnswer(message);
        }
Esempio n. 3
0
        void ExplainFunctionList(WebData data)
        {
            var html = new HtmlPageBuilder(data.Request);

            IEnumerable <KeyValuePair <string, WebServerMethod> > paths = data.Server.RegisteredPaths;

            if (data.Request.Parameters.TryGetValue("functions", out string functions))
            {
                string   path  = string.Empty;
                string[] parts = functions.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                for (int n = 0; n < parts.Length; n++)
                {
                    path += "/" + parts[n];
                    html.Breadcrump.Add(new WebLink()
                    {
                        Text = parts[n], Link = $"/Explain?functions={path}"
                    });
                }
                paths = paths.Where(p => p.Key.StartsWith(functions));
            }

            Bootstrap4 content = html.Content;

            content.ListGroupOpen();
            int i = 0;

            ILookup <WebServerMethod, string> lookup = paths.ToLookup(p => p.Value, p => p.Key);

            foreach (IGrouping <WebServerMethod, string> item in lookup)
            {
                WebServerMethod function = item.Key;

                // if (item.Key == "/") continue;
                content.ListGroupItemOpen(i++ % 2 == 0 ? " list-group-item-info" : null);
                XNetDocItem doc = documentation.GetMethod(function.Method);

                content.AddHtml("<div style=\"width:100%\">");
                content.DivOpen(Bootstrap4.Item.row);
                WebServerAuthType authType = function.PageAttribute?.AuthType ?? WebServerAuthType.None;
                if (authType != WebServerAuthType.None)
                {
                    content.DivOpen(Bootstrap4.Item.col, "col-12 col-sm-auto flex-sm-last");
                    AddBadges(content, function.PageAttribute);
                    content.DivClose(Bootstrap4.Item.col);
                }
                content.DivOpen(Bootstrap4.Item.col);
                content.AddHtml("<h4>");
                content.AddHtml(function.Method.Name.SplitCamelCase().Join(" "));
                if (function.Parameters.Length > 0)
                {
                    content.AddHtml(" (");
                    content.AddHtml(function.ParameterString());
                    content.AddHtml(")");
                }
                content.AddHtml("</h4>");
                content.DivClose(Bootstrap4.Item.col);
                content.DivClose(Bootstrap4.Item.row);

                foreach (string path in item)
                {
                    content.DivOpen(Bootstrap4.Item.row);
                    content.DivOpen(Bootstrap4.Item.col);
                    content.Link(path, $"Explain?function={path}");
                    content.DivClose(Bootstrap4.Item.col);

                    content.DivOpen(Bootstrap4.Item.col, "col-12 col-sm-auto");
                    content.Link("html", path + ".html", "btn btn-sm btn-outline-primary");
                    content.Link("json", path + ".json", "btn btn-sm btn-outline-primary");
                    content.Link("xml", path + ".xml", "btn btn-sm btn-outline-primary");
                    content.Link("plain", path + ".txt", "btn btn-sm btn-outline-primary");
                    content.DivClose(Bootstrap4.Item.col);
                    content.DivClose(Bootstrap4.Item.row);
                }

                if (doc?.Summary != null)
                {
                    content.DivOpen(Bootstrap4.Item.row);
                    content.DivOpen(Bootstrap4.Item.col);
                    content.AddHtml("<strong>Description:</strong>");
                    int cdata = doc.Summary.IndexOf("<![CDATA[");
                    if (cdata > -1)
                    {
                        content.Text(doc.Summary.Substring(0, cdata));
                        content.AddHtml("<br/><code>");
                        string code     = doc.Summary.Substring(cdata + 9);
                        int    cdataEnd = code.IndexOf("]]>");
                        content.AddHtml(code.Substring(0, cdata));
                        content.AddHtml("</code>");
                        content.Text(doc.Summary.Substring(cdata + cdataEnd + 9 + 3));
                    }
                    else
                    {
                        content.Text(doc.Summary);
                    }
                    content.DivClose(Bootstrap4.Item.col);
                    content.DivClose(Bootstrap4.Item.row);
                }
                content.AddHtml("</div>");
                content.ListGroupItemClose();
            }
            content.ListGroupClose();
            content.AddHtml("&nbsp;");
            var message = WebMessage.Create("Explain", functions == null ? "Explain functions." : $"Explain {functions} functions.");

            data.Answer = html.ToAnswer(message);
        }