public void Any(HttpListenerContext Context) { Console.WriteLine($"Request sent to {Context.Request.Url}"); var Body = new StreamReader(Context.Request.InputStream).ReadToEnd(); Console.WriteLine($"Request body:\r\n{Body}"); API.Respond("{\"ok\": true}", Context); }
public void Index(HttpListenerContext Context) { var HTML = GetPage(); var Articles = GetArticles(); var Elements = GetElements(); var Page = 1; if (Context.Request.QueryString.AllKeys.Contains("page")) { int.TryParse(Context.Request.QueryString["page"], out Page); } //var ArticleHTML = ""; //foreach (var Article in Articles.Skip((Page - 1) * 10).Take(10)) //{ // foreach (var Element in GetHashTags(HTML)) // { // var iHTMLTemp = Elements.Where(x => x.Name.ToLower().Contains(Element.ToLower())); // if (iHTMLTemp.Any()) // { // var iHTML = iHTMLTemp.First().RawHTML; // var DeclaredMembers = Article.GetType().GetFields(); // foreach (var Member in DeclaredMembers) // { // if (Member.MemberType == MemberTypes.Field) // { // var Field = Article.GetType().GetField(Member.Name); // if (Field != null) // HTML = HTML.Replace($"##{Element.ToUpper()}##", iHTML.Replace($"##{Member.Name.ToUpper()}##", Field.GetValue(Article).ToString())); // } // } // } // } //} var SideBarHTML = ""; foreach (var Article in Articles) { var iHTML = Elements.First(x => x.Name.Contains("sidebar")).RawHTML; var SmallTitle = Article.Title; if (SmallTitle.Length > 19) { SmallTitle = $"{SmallTitle.Substring(0, 20).TrimEnd()}...".Replace("......", "..."); } iHTML = iHTML.Replace("##TITLE##", SmallTitle); iHTML = iHTML.Replace("##URL##", Article.URL); SideBarHTML += iHTML; } HTML = HTML.Replace("##SIDEBAR.ITEM##", SideBarHTML); //HTML = HTML.Replace("##ARTICLE.ITEM##", ArticleHTML); for (int i = 0; i < Emojis.Count(); i++) { HTML = HTML.Replace($":{Emojis.Keys.ToList()[i]}:", Emojis.Values.ToList()[i]); } API.Respond(HTML, "text/html", Context); }