コード例 #1
0
        void GetStaticFileListing(WebData data)
        {
            string url     = Uri.UnescapeDataString(data.Request.DecodedUrl).Trim('/');
            string path    = FileSystem.Combine(StaticFilesPath, url);
            var    entries = new List <WebDirectoryEntry>();
            string root    = FileSystem.Combine(path, "..");

            if (FileSystem.IsRelative(root, StaticFilesPath))
            {
                FileSystemInfo info  = new DirectoryInfo(root);
                var            entry = new WebDirectoryEntry()
                {
                    DateTime = info.LastWriteTime,
                    Name     = "..",
                    Type     = WebDirectoryEntryType.Directory,
                    Link     = "/" + url + "/..",
                };
                entries.Add(entry);
            }
            if (FileSystem.IsRelative(path, StaticFilesPath))
            {
                foreach (string dir in Directory.GetDirectories(path))
                {
                    FileSystemInfo info  = new DirectoryInfo(dir);
                    var            entry = new WebDirectoryEntry()
                    {
                        DateTime = info.LastWriteTime,
                        Name     = info.Name,
                        Type     = WebDirectoryEntryType.Directory,
                        Link     = "/" + FileSystem.Combine('/', url, info.Name),
                    };
                    entries.Add(entry);
                }
                foreach (string file in Directory.GetFiles(path))
                {
                    var info  = new FileInfo(file);
                    var entry = new WebDirectoryEntry()
                    {
                        DateTime = info.LastWriteTime,
                        Size     = info.Length,
                        Name     = info.Name,
                        Type     = WebDirectoryEntryType.File,
                        Link     = "/" + FileSystem.Combine('/', url, info.Name),
                    };
                    entries.Add(entry);
                }
            }
            var pb = new HtmlPageBuilder(data.Request);

            pb.Content.CardOpenText($"File Listing:");
            pb.Content.ParagraphText($"{entries.Count} entries");
            pb.Content.TableOpen(new string[] { "Type", "Size", "Name" }, "table-striped table-responsive");
            foreach (WebDirectoryEntry entry in entries)
            {
                pb.Content.TableRowOpen();
                pb.Content.TableHtmlCell(Bootstrap4.GetBadge(entry.Type.ToString(), "badge-default"));
                pb.Content.TableCell(entry.Type == WebDirectoryEntryType.Directory ? string.Empty : entry.Size.FormatBinarySize());
                pb.Content.TableHtmlCell(Bootstrap4.GetLink(entry.Name, entry.Link));
                pb.Content.TableRowClose();
            }
            pb.Content.TableClose();
            pb.Content.CardClose();
            pb.Content.AddHtml("&nbsp;");
            data.Answer = pb.ToAnswer(WebMessage.Create("FileListing", "File listing retrieved."));
        }
コード例 #2
0
        void DocumentHtml(Bootstrap4 content, XNetDocItem xNetDocItem, string defaultSummary)
        {
            string summary = (xNetDocItem?.Summary != null) ? xNetDocItem.Summary : defaultSummary;

            if (summary != null)
            {
                int cdata = summary.IndexOf("<![CDATA[");
                if (cdata > -1)
                {
                    int    cdataEnd = summary.IndexOf("]]>", cdata + 9);
                    string code     = summary.Substring(cdata + 9, cdataEnd - cdata - 9);
                    Paragraph(null, content, summary.Substring(0, cdata), "primary");
                    Paragraph(null, content, "<code>" + code + "</code>", "code");
                    summary = summary.Substring(cdataEnd + 3);
                    if (summary.Trim().Length > 0)
                    {
                        Paragraph(null, content, summary, "primary");
                    }
                }
                else
                {
                    Paragraph(null, content, summary, "primary");
                }
            }
            if (xNetDocItem == null)
            {
                return;
            }

            if (xNetDocItem.Remarks != null)
            {
                Paragraph(null, content, xNetDocItem.Remarks, "info");
            }

            if (xNetDocItem.Returns != null)
            {
                Paragraph(null, content, xNetDocItem.Returns, "success");
            }

            if (xNetDocItem.Exceptions != null)
            {
                content.ParagraphOpen("text-danger");
                bool first = true;
                foreach (string line in xNetDocItem.Exceptions)
                {
                    if (line.StartsWith("<see"))
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            content.AddHtml("<br />");
                        }

                        string code = line.GetString(-1, "CaveWebError", "\"", false);
                        if (code == null)
                        {
                            content.Text(line);
                        }
                        else
                        {
                            content.AddHtml($"<strong>{Bootstrap4.GetLink("CaveWebError" + code, "/Explain?type=Cave.Web.CaveWebError", "text-danger")}</strong>: ");
                        }
                    }
                    else
                    {
                        content.Text(line);
                    }
                }
                content.ParagraphClose();
            }
        }