Ejemplo n.º 1
0
 public static HtmlPage Parse(string html)
 {
     HtmlPage res = new HtmlPage();
     int i = 0;
     while (char.IsWhiteSpace(html[i])) i++;
     if (html[i] != '<')
         throw new ArgumentException("Invalid char.");
     i++;
     if (html[i] == '!')
     {
         while (html[i++] != '>') ;
         while (char.IsWhiteSpace(html[i++])) ;
     }
     i--;
     var temp = HtmlElement.Parse(html, ref i);
     if (temp.Name != "html")
         throw new ArgumentException("Invalid root tag.");
     res.Body = temp["body"];
     res.Head = temp["head"];
     if (res.Body == null || res.Head == null)
         throw new ArgumentException();
     if (temp.Subnodes.Count != 2)
         throw new ArgumentException();
     res.Subnodes = temp.Subnodes;
     res.Attributes = temp.Attributes;
     return res;
 }
Ejemplo n.º 2
0
        public static HtmlPage Parse(string html)
        {
            HtmlPage res = new HtmlPage();
            int      i   = 0;

            while (char.IsWhiteSpace(html[i]))
            {
                i++;
            }
            if (html[i] != '<')
            {
                throw new ArgumentException("Invalid char.");
            }
            i++;
            if (html[i] == '!')
            {
                while (html[i++] != '>')
                {
                    ;
                }
                while (char.IsWhiteSpace(html[i++]))
                {
                    ;
                }
            }
            i--;
            var temp = HtmlElement.Parse(html, ref i);

            if (temp.Name != "html")
            {
                throw new ArgumentException("Invalid root tag.");
            }
            res.Body = temp["body"];
            res.Head = temp["head"];
            if (res.Body == null || res.Head == null)
            {
                throw new ArgumentException();
            }
            if (temp.Subnodes.Count != 2)
            {
                throw new ArgumentException();
            }
            res.Subnodes   = temp.Subnodes;
            res.Attributes = temp.Attributes;
            return(res);
        }
Ejemplo n.º 3
0
        public override string ToString()
        {
            var page = new HtmlPage()
            { 
                new HtmlElement("div", "content")
                {
                    new HtmlElement("div", "title")
                    {
                        new Text(((int)Code).ToString())
                    },                
                    new HtmlElement("div", "bottomtext")
                    {
                        new Text(Message)
                    },
                }
            };
            page.Head.Add(new HtmlElement("style")
            {
                new Text(
@"
    html {
        height: 100%;
    }
    * {
        text-align: center;
        font-family: Verdana, sans-serif;
    }
    body {
        height: 100%;
    }
    #content {
        position: relative;
        top: 25%;
    }
    #title {
        font-size: 80px
    }
")
            });
            return page.ToString();
        }
Ejemplo n.º 4
0
        public override void Process(HttpRequest request, HttpResponse response, HttpApplication application)
        {
            var encoding = Encoding.UTF8;
            int visitCount = 0;
            var t = request.Cookies["visitcount"];
            if (t != null)
                int.TryParse(t.Value, out visitCount);
            visitCount++;
            var page = new HtmlPage()
            { 
                new HtmlElement("div", "content")
                {
                    new HtmlElement("div", "toptext") { new Text("if you see it, then") },
                    new HtmlElement("div", "title") { new Text("NiL.WBE") },
                    new HtmlElement("div", "bottomtext") { new Text("working") },
                    new Text("you was here " + visitCount + " times")
                }
            };
            page.Head.Add(new HtmlElement("style")
            {
                new Text(
@"
    html {
        height: 100%;
    }
    * {
        text-align: center;
        font-family: Lobster;
    }
    body {
        height: 100%;
    }
    #content {
        position: relative;
        top: 25%;
    }
    #title {
        font-size: 80px
    }
    @font-face {
        font-family: 'Lobster';
        font-style: normal;
        font-weight: 400;
        src: local('Lobster'), url(http://themes.googleusercontent.com/static/fonts/lobster/v5/9eID_a1kLfzp_BP9s4L15g.woff) format('woff');
    }
", false)
            });
            try
            {
                page.Head.Add(new HtmlElement("title") { new Text("NiL.WBE") });
                response.ContentType = page.ContentType;
                response.ContentEncoding = System.Text.Encoding.UTF8;
                response.Cookies.Add(new HttpCookie("visitcount", visitCount.ToString()));
                response.Status = "200 OK";
                response.BinaryWrite(encoding.GetBytes(page.ToString()));
                application.CompleteRequest();
            }
            catch(Exception e)
            {
                string text = e.ToString();
            }
        }