Пример #1
0
 public void CreateThread(User.User requestuser, Header header)
 {
     Thread.Thread thread = new Thread.Thread
     {
         author = requestuser,
         id     = NextId(),
         header = header,
     };
     Threads.Add(thread);
 }
Пример #2
0
        private void GetThreadMessages(Thread.Thread thread, HtmlDocument doc)
        {
            var messagetable = doc.DocumentNode.DescendantsAndSelf().First(n => n.HasAttributes && n.Attributes.Any(m => m.Name == "class" && m.Value == "messagetable"));

            foreach (var message in thread.messages)
            {
                HtmlNode div = doc.CreateElement("div");
                div.Attributes.Add("style", "border: 1px solid black; margin: 5px; padding: 5px;");
                HtmlNode content = doc.CreateElement("div");
                content.Attributes.Add("style", "padding-right: 5%; padding-left: 10px; font-size: 20px");

                HtmlNode dateandauthor = doc.CreateElement("div");
                dateandauthor.Attributes.Add("style", "display: block; font-size: 30px;");
                HtmlNode authordiv = doc.CreateElement("div");
                HtmlNode datediv   = doc.CreateElement("div");
                authordiv.Attributes.Add("style", "display: inline-block; width: 50%;");
                datediv.Attributes.Add("style", "display: inline-block; width: 50%;");
                HtmlNode author = doc.CreateElement("strong");
                HtmlNode date   = doc.CreateElement("p");
                date.Attributes.Add("style", "text-align: right; margin: 0;");
                date.AppendChild(HtmlTextNode.CreateNode($"{message.creationTime.ToString("MM/dd/yy HH:mm")}"));
                author.AppendChild(HtmlTextNode.CreateNode(message.author.username) ?? HtmlTextNode.CreateNode("bad"));
                authordiv.AppendChild(author);
                datediv.AppendChild(date);
                dateandauthor.AppendChild(authordiv);
                dateandauthor.AppendChild(datediv);
                div.AppendChild(dateandauthor);
                foreach (var a in message.contents.Replace("\r", "").Split('\n'))
                {
                    //var p = doc.CreateElement("p");
                    //p.Attributes.Add("style", "margin: 0");
                    //p.AppendChild(HtmlTextNode.CreateNode(a) ?? HtmlTextNode.CreateNode("bad"));
                    //content.AppendChild(p);
                    HtmlNode p;
                    if (a.Length > 0)
                    {
                        p = doc.CreateElement("p");
                        p.Attributes.Add("style", "margin: 0");
                        p.AppendChild(HtmlTextNode.CreateNode(a));
                    }
                    else
                    {
                        p = doc.CreateElement("p");
                    }
                    content.AppendChild(p);
                }
                //div.AppendChild(author);
                div.AppendChild(content);
                messagetable.AppendChild(div);
            }
        }
Пример #3
0
        private void SendThreadPage(Thread.Thread thread, TcpClient client)
        {
            HttpResponse httpResponse = new HttpResponse
            {
                Content = new HTTP_Server.HTTP.Message.Content
                {
                    Buffer = Encoding.UTF8.GetBytes(GetThreadPage(thread))
                },
                Header = new HTTP_Server.HTTP.Message.Header()
            };

            Console.WriteLine($"{(int)httpResponse.Header.StatusCode} {httpResponse.Header.StatusCode}");
            client.Client.Send(httpResponse.Serialize());
        }
Пример #4
0
        public IEnumerable <Thread.Thread> GetThreads(JArray threads)
        {
            List <Thread.Thread> threadsList = new List <Thread.Thread>();

            foreach (var value in threads)
            {
                try
                {
                    Thread.Thread thread = new Thread.Thread();
                    thread.id       = (int)value["id"];
                    thread.messages = GetMessages(value["comments"].Value <JArray>()).ToList();
                    thread.author   = GetUser(value["author"].Value <JObject>());
                    thread.header   = GetHeader(value["header"].Value <JObject>());
                    threadsList.Add(thread);
                }
                catch (Exception)
                {
                    Console.WriteLine("Could not retrieve thread from database");
                }
            }
            return(threadsList);
        }
Пример #5
0
 public void AppendThread(Thread.Thread thread, Thread.Message.Message message)
 {
     GetThread(thread.id).messages.Add(message);
 }
Пример #6
0
        private string GetThreadPage(Thread.Thread thread)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(System.IO.File.ReadAllText("threadpage.html"));
            if (doc.DocumentNode.DescendantsAndSelf().Any(n => n.HasAttributes && n.Attributes.Any(m => m.Name == "class" && m.Value == "threadhead")))
            {
                var      messagebox = doc.DocumentNode.DescendantsAndSelf().First(n => n.Attributes.Any(m => m.Name == "class" && m.Value == "threadhead"));
                HtmlNode form       = doc.CreateElement("div");
                form.Attributes.Add("style", "border: 5px dashed blue; padding: 5px;");

                HtmlNode dateandauthor = doc.CreateElement("div");
                dateandauthor.Attributes.Add("style", "display: block; font-size: 30px;");

                HtmlNode author = doc.CreateElement("div");
                author.Attributes.Add("style", "display: inline-block; width: 50%;");
                var smg = doc.CreateElement("strong");
                smg.AppendChild(HtmlTextNode.CreateNode($"{thread.author.username}"));
                author.AppendChild(smg);
                dateandauthor.AppendChild(author);

                HtmlNode ddddd = doc.CreateElement("div");
                ddddd.Attributes.Add("style", "display: inline-block; width: 50%;");
                HtmlNode date = doc.CreateElement("p");
                date.AppendChild(HtmlTextNode.CreateNode($"{thread.creationTime.ToString("MM/dd/yy HH:mm")}"));
                date.Attributes.Add("style", "text-align: right; margin: 0;");
                ddddd.AppendChild(date);
                dateandauthor.AppendChild(ddddd);

                form.AppendChild(dateandauthor);

                HtmlNode title = doc.CreateElement("p");
                title.Attributes.Add("style", "font-size: 40px; margin: 1%;");
                title.AppendChild(HtmlTextNode.CreateNode(thread.header.title.Replace("\r", "").Replace("\n", "<br>")) ?? HtmlTextNode.CreateNode("bad"));
                form.AppendChild(title);

                HtmlNode content = doc.CreateElement("div");
                content.Attributes.Add("style", "padding-left: 10px; padding-right: 5%; font-size: 20px;");
                //content.AppendChild(HtmlTextNode.CreateNode(thread.header.content.Replace("\r", "").Replace("\n", "<br>")) ?? HtmlTextNode.CreateNode("bad"));



                foreach (var a in thread.header.content.Replace("\r", "").Split('\n'))
                {
                    HtmlNode p;
                    if (a.Length > 0)
                    {
                        p = doc.CreateElement("p");
                        p.Attributes.Add("style", "margin: 0");
                        p.AppendChild(HtmlTextNode.CreateNode(a) ?? HtmlTextNode.CreateNode("bad"));
                    }
                    else
                    {
                        p = doc.CreateElement("p");
                    }
                    content.AppendChild(p);
                }
                form.AppendChild(content);

                messagebox.AppendChild(form);
            }
            if (doc.DocumentNode.DescendantsAndSelf().Any(n => n.HasAttributes && n.Attributes.Any(m => m.Name == "class" && m.Value == "messagetable")))
            {
                GetThreadMessages(thread, doc);
            }
            else
            {
                Console.WriteLine("Invalid ThreadPage HTML");
            }
            if (doc.DocumentNode.DescendantsAndSelf().Any(n => n.HasAttributes && n.Attributes.Any(m => m.Name == "class" && m.Value == "messagebox")))
            {
                var      messagebox = doc.DocumentNode.DescendantsAndSelf().First(n => n.Attributes.Any(m => m.Name == "class" && m.Value == "messagebox"));
                HtmlNode form       = doc.CreateElement("form");
                form.Attributes.Add("action", $"thread&{thread.id}");
                form.Attributes.Add("method", "POST");
                //form.Attributes.Add("enctype", "multipart/form-data");

                HtmlNode output = doc.CreateElement("output");
                output.Attributes.Add("for", "content datafile");
                //enctype=multipart/form-data
                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 Comment");

                //HtmlNode addfile = doc.CreateElement("input");
                //addfile.Attributes.Add("type", "file");
                //addfile.Attributes.Add("name", "datafile");
                //addfile.Attributes.Add("id", "datafile");
                //addfile.Attributes.Add("value", "Attach File");
                var div1 = doc.CreateElement("div");
                div1.AppendChild(content);
                form.AppendChild(div1);

                var div2 = doc.CreateElement("div");
                div2.AppendChild(submit);
                //form.AppendChild(addfile);
                form.AppendChild(div2);
                form.AppendChild(output);

                messagebox.AppendChild(form);
            }
            else
            {
                Console.WriteLine("Invalid ThreadPage HTML");
            }
            MemoryStream memoryStream = new MemoryStream();

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