コード例 #1
0
ファイル: MstInfoHttpController.cs プロジェクト: poup/MST
        private void OnGetMstInfoJsonHttpRequestHandler(HttpRequestEventArgs eventArgs)
        {
            var response = eventArgs.Response;

            HtmlDocument html = new HtmlDocument();

            html.Title = "MST Info";
            html.AddMeta(new KeyValuePair <string, string>("charset", "utf-8"));
            html.AddMeta(new KeyValuePair <string, string>("name", "viewport"), new KeyValuePair <string, string>("content", "width=device-width, initial-scale=1"));

            html.Links.Add(new HtmlLinkElement()
            {
                Href        = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
                Rel         = "stylesheet",
                Integrity   = "sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl",
                Crossorigin = "anonymous"
            });

            html.Scripts.Add(new HtmlScriptElement()
            {
                Src         = "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js",
                Integrity   = "sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0",
                Crossorigin = "anonymous"
            });

            html.Body.AddClass("body");

            var container = html.CreateElement("div");

            container.AddClass("container-fluid pt-5");
            html.Body.AppendChild(container);

            var h1 = html.CreateElement("h1");

            h1.InnerText = $"{Mst.Name} {Mst.Version}";
            container.AppendChild(h1);

            var row = html.CreateElement("div");

            row.AddClass("row");
            container.AppendChild(row);

            var col1 = html.CreateElement("div");

            col1.AddClass("col-md-4");
            row.AppendChild(col1);

            var col2 = html.CreateElement("div");

            col2.AddClass("col-md-8");
            row.AppendChild(col2);

            GenerateMachineInfo(html, col1);

            GenerateListOfModules(html, col2);

            byte[] contents = Encoding.UTF8.GetBytes(html.ToString());

            response.ContentType     = "text/html";
            response.ContentEncoding = Encoding.UTF8;
            response.ContentLength64 = contents.LongLength;
            response.Close(contents, true);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected virtual string DefaultIndexPageHtml()
        {
            HtmlDocument html = new HtmlDocument
            {
                Title = "Home | Master Server Toolkit"
            };

            html.AddMeta(new KeyValuePair <string, string>("charset", "utf-8"));
            html.AddMeta(new KeyValuePair <string, string>("name", "viewport"), new KeyValuePair <string, string>("content", "width=device-width, initial-scale=1"));
            html.AddMeta(new KeyValuePair <string, string>("name", "description"), new KeyValuePair <string, string>("content", "Master Server Toolkit is designed to kickstart your back-end server development. It contains solutions to some of the common problems."));
            html.AddMeta(new KeyValuePair <string, string>("name", "author"), new KeyValuePair <string, string>("content", "Master Server Toolkit"));

            html.Links.Add(new HtmlLinkElement()
            {
                Href        = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
                Rel         = "stylesheet",
                Integrity   = "sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl",
                Crossorigin = "anonymous"
            });

            html.Scripts.Add(new HtmlScriptElement()
            {
                Src         = "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js",
                Integrity   = "sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0",
                Crossorigin = "anonymous"
            });

            html.Body.AddClass("vh-100");

            var container = html.CreateElement("div");

            container.AddClass("container h-100");
            html.Body.AppendChild(container);

            var row = html.CreateElement("div");

            row.AddClass("row h-100");
            container.AppendChild(row);

            var col = html.CreateElement("div");

            col.AddClass("col align-self-center text-center");
            row.AppendChild(col);

            var h2 = html.CreateElement("h2");

            h2.InnerText = $"{Mst.Name} {Mst.Version}";
            col.AppendChild(h2);

            var h3 = html.CreateElement("h3");

            h3.AddClass("display-3");
            h3.InnerText = "Home Page";
            col.AppendChild(h3);

            var p1 = html.CreateElement("p");

            p1.InnerText = "This is default Index page. You can override it by overloading DefaultIndexPageHtml() method in HttpServerModule";
            col.AppendChild(p1);

            var p2 = html.CreateElement("p");

            col.AppendChild(p2);

            var href1 = html.CreateElement("a");

            href1.InnerText = "Open 404 page...";
            href1.SetAttribute("href", "somewhere");
            p2.AppendChild(href1);

            return(html.ToString());
        }