示例#1
0
        private string GetMainPage(User.User curUser = null)
        {
            if (curUser == null)
            {
                curUser = anonymous;
            }
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(System.IO.File.ReadAllText("mainpage.html"));
            if (doc.DocumentNode.DescendantsAndSelf().Any(n => n.HasAttributes && n.Attributes.Any(m => m.Name == "class" && m.Value == "threadtable")))
            {
                GetThreadsHTML(doc, curUser);
            }
            else
            {
                Console.WriteLine("Invalid Mainpage HTML");
            }
            if (doc.DocumentNode.DescendantsAndSelf().Any(n => n.HasAttributes && n.Attributes.Any(m => m.Name == "class" && m.Value == "threadbox")))
            {
                var      messagebox = doc.DocumentNode.DescendantsAndSelf().First(n => n.Attributes.Any(m => m.Name == "class" && m.Value == "threadbox"));
                HtmlNode form       = doc.CreateElement("form");
                form.Attributes.Add("action", $"/");
                form.Attributes.Add("method", "POST");

                HtmlNode output = doc.CreateElement("output");
                output.Attributes.Add("for", "content");

                HtmlNode title = doc.CreateElement("input");
                title.Attributes.Add("id", "title");
                title.Attributes.Add("name", "title");
                title.Attributes.Add("type", "text");

                HtmlNode content = doc.CreateElement("textarea");
                content.Attributes.Add("rows", "5");
                content.Attributes.Add("cols", "80");
                content.Attributes.Add("id", "content");
                content.Attributes.Add("name", "content");
                content.Attributes.Add("type", "text");

                HtmlNode submit = doc.CreateElement("input");
                submit.Attributes.Add("type", "submit");
                submit.Attributes.Add("value", "Add Thread");

                var div1 = doc.CreateElement("div");
                var div2 = doc.CreateElement("div");
                var div3 = doc.CreateElement("div");
                var div4 = doc.CreateElement("div");
                div1.AppendChild(HtmlTextNode.CreateNode("Title"));
                div2.AppendChild(title);
                div3.AppendChild(HtmlTextNode.CreateNode("Content"));
                div4.AppendChild(content);

                form.AppendChild(div1);
                form.AppendChild(div2);
                form.AppendChild(div3);
                form.AppendChild(div4);
                form.AppendChild(submit);
                form.AppendChild(output);

                messagebox.AppendChild(form);
            }
            else
            {
                Console.WriteLine("Invalid ThreadPage HTML");
            }
            if (curUser.username != "anonymous" && doc.DocumentNode.DescendantsAndSelf().Any(n => n.HasAttributes && n.Attributes.Any(m => m.Name == "class" && m.Value == "loggedin")))
            {
                var messagebox = doc.DocumentNode.DescendantsAndSelf().First(n => n.Attributes.Any(m => m.Name == "class" && m.Value == "loggedin"));
                messagebox.RemoveAllChildren();
                messagebox.AppendChild(HtmlTextNode.CreateNode(curUser.username) ?? HtmlTextNode.CreateNode("bad"));
            }
            else
            {
            }
            MemoryStream memoryStream = new MemoryStream();

            doc.Save(memoryStream);
            return(doc.Encoding.GetString(memoryStream.ToArray()));
        }