Exemple #1
0
        public HtmlCssData()
        {
            sb.AppendLine("<!DOCTYPE html>");
            sb.AppendLine("<html>");
            doc.LoadHtml(sb.ToString());
            HtmlAgilityPack.HtmlNode[] root = doc.DocumentNode.Descendants().ToArray();

            HtmlAgilityPack.HtmlNode head = doc.CreateElement("head");
            HtmlAgilityPack.HtmlNode body = doc.CreateElement("body");

            root[2].AppendChild(head);

            root[2].AppendChild(body);
            doc.OptionFixNestedTags = true;
        }
Exemple #2
0
        public string ParseAndPopulate(string input)
        {
            string output = input;

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(input);
            if (doc.DocumentNode.SelectNodes("//datasource") != null)
            {
                foreach (HtmlAgilityPack.HtmlNode ds in doc.DocumentNode.SelectNodes("//datasource"))
                {
                    HtmlAgilityPack.HtmlAttribute att = ds.Attributes["name"];
                    if (att != null)
                    {
                        try
                        {
                            HtmlAgilityPack.HtmlNode hn = HtmlAgilityPack.HtmlNode.CreateNode(string.Format("", LoadContent(att.Value)));
                            var temp = doc.CreateElement("temp");
                            temp.InnerHtml = LoadContent(att.Value);
                            var current = ds;
                            foreach (var child in temp.ChildNodes)
                            {
                                ds.ParentNode.InsertAfter(child, current);
                                current = child;
                            }
                            ds.Remove();
                        }
                        catch { }
                    }
                }
            }
            output = doc.DocumentNode.OuterHtml;
            return(output);
        }
Exemple #3
0
        public HtmlAgilityPack.HtmlDocument Write(HtmlAgilityPack.HtmlNode parent)
        {
            foreach (var task in tasks)
            {
                HtmlAgilityPack.HtmlNode child = doc.CreateElement("div");
                child.Attributes.Add("class", "task");
                task.Write(child);
                parent.AppendChild(child);
            }

            return(doc);
        }
Exemple #4
0
        /// <summary>
        /// Creates OneNote page
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        private static Page OpenOrCreatePage(Document document)
        {
            Console.WriteLine("Loading pages ...");

            string title = "Microsoft Graph API example";

            var pageFactory = new GraphPageFactory();
            var allPages    = pageFactory.GetAllItems(document.Id);
            var page        = allPages.FirstOrDefault(p => p.Title.Equals(title));

            if (page != null)
            {
                return(pageFactory.GetItem(page.Id));
            }


            // create sample html page document and add some fields
            var sampleDoc = new HtmlAgilityPack.HtmlDocument();

            sampleDoc.LoadHtml(Resources.SamplePageHtml);
            var body      = sampleDoc.DocumentNode.SelectSingleNode("//body");
            var textField = sampleDoc.CreateElement("div");

            textField.SetAttributeValue("id", "dynamicElement");
            textField.InnerHtml = "Dynamically added DIV element #";
            body.AppendChild(textField);

            //save html document as HTML
            string htmlContent;

            using (var htmlStream = new MemoryStream())
            {
                sampleDoc.Save(htmlStream, Encoding.UTF8);
                htmlStream.Position = 0;

                byte[] buffer = new byte[htmlStream.Length];
                htmlStream.Read(buffer, 0, buffer.Length);
                htmlContent = Encoding.UTF8.GetString(buffer);
            }


            //MemoryStream stream = ReadImage();
            //page = pageFactory.AddItem(new Page { Content = htmlContent, StreamContent = stream, Title = title }, section.Id);

            Console.WriteLine("Created page 'Microsoft Graph API example'...");

            return(page);
        }
Exemple #5
0
        private string monDetailPg(HtmlAgilityPack.HtmlNode monNode)
        {
            HtmlAgilityPack.HtmlDocument _doc   = new HtmlAgilityPack.HtmlDocument();
            HtmlAgilityPack.HtmlDocument subdoc = new HtmlAgilityPack.HtmlDocument();
            var monN = monNode.SelectSingleNode("td[1]/a").InnerText;

            var suburl = monNode.SelectSingleNode("td[1]/a").GetAttributeValue("href", "");

            if (!monUrlSet.Contains(suburl) && suburl.StartsWith("/cn/"))
            {
                monUrlSet.Add(suburl);
                Uri monLink  = new Uri(DBsettings.monURL + suburl);
                var monCrawl = WebRequest.RequestAction(new RequestOptions()
                {
                    Uri = monLink, Method = "Get"
                });
                subdoc.LoadHtml(monCrawl);
                var monName   = subdoc.DocumentNode.SelectSingleNode("//h4");
                var detailTab = subdoc.DocumentNode.SelectSingleNode("//div[@class = 'tab-content'][1]/div[1]/table");
                if (detailTab.SelectNodes("tr").Count > 16)
                {
                    //todo: add td according to th
                    var monTd = detailTab.SelectNodes("tr[position() = 1 or position() > 2 and position() < 15]/td");

                    //new element
                    var _tr = _doc.CreateElement("tr");
                    _tr.InnerHtml += "<td>" + monName.InnerHtml + "</td>";
                    foreach (var td in monTd)
                    {
                        _tr.AppendChild(td);
                    }
                    //final add tr outerhtml to montable
                    return(_tr.OuterHtml);
                }
                Console.Out.WriteLine("Getting " + monN + " page failed");
            }
            return("");
        }
        public ActionResult Index(string url, bool?preview)
        {
            Post PPM = db.Posts.FirstOrDefault(t => t.URL.ToLower() == url.ToLower().Trim() && (t.Status == Models.PostStatus.Publish || (preview.HasValue && preview.Value)));

            if (PPM != null)
            {
                #region Replace Custom Data Source
                DataSourceManager dsm = new DataSourceManager(db);

                if (PPM.TemplateName != string.Empty)
                {
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    string templateHTML = dsm.LoadContent(PPM.TemplateName);
                    doc.LoadHtml(templateHTML);

                    if (doc.DocumentNode.SelectNodes("//datasource") != null)
                    {
                        foreach (HtmlAgilityPack.HtmlNode ds in doc.DocumentNode.SelectNodes("//datasource"))
                        {
                            try
                            {
                                HtmlAgilityPack.HtmlAttribute att = ds.Attributes["name"];

                                if (att != null)
                                {
                                    var temp    = doc.CreateElement("temp");
                                    var current = ds;
                                    if (att.Value == "articletext")
                                    {
                                        temp.InnerHtml = PPM.Article;
                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                    else if (att.Value == "articleimg")
                                    {
                                        if (PPM.OGImage != string.Empty)
                                        {
                                            temp.InnerHtml = string.Format("<img src='{0}' alt='' />", PPM.OGImage);
                                        }
                                        else
                                        {
                                            temp.InnerHtml = "";
                                        }

                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                    else if (att.Value == "articletitle")
                                    {
                                        temp.InnerHtml = PPM.Title;
                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                    else if (att.Value == "articledate")
                                    {
                                        temp.InnerHtml = PPM.DateCreated.ToShortDateString();
                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                    else if (att.Value == "articleviewcount")
                                    {
                                        temp.InnerHtml = PPM.Viewed.ToString();
                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                    else if (att.Value == "articletag")
                                    {
                                        temp.InnerHtml = PPM.Tag;
                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                    else if (att.Value == "articlewritername")
                                    {
                                        temp.InnerHtml = PPM.WriterName;
                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                    else if (att.Value == "articlewriteremail")
                                    {
                                        temp.InnerHtml = PPM.WriterEmail;
                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                    else if (att.Value == "articlecategory")
                                    {
                                        temp.InnerHtml = PPM.Category.Name;
                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                    else if (att.Value == "articledescription")
                                    {
                                        temp.InnerHtml = PPM.OGDescription;
                                        foreach (var child in temp.ChildNodes)
                                        {
                                            ds.ParentNode.InsertAfter(child, current);
                                            current = child;
                                        }
                                        ds.Remove();
                                    }
                                }
                            }
                            catch { }
                        }
                    }

                    PPM.Article = doc.DocumentNode.OuterHtml;
                }
                PPM.Article = dsm.ParseAndPopulate(PPM.Article);
                #endregion
            }
            else
            {
                PPM = new Post();
            }
            return(View(PPM));
        }
        /// <summary>
        /// Updates the preview.
        /// </summary>
        protected void UpdatePreview()
        {
            var templateDoc = new HtmlAgilityPack.HtmlDocument();

            templateDoc.LoadHtml(ceEmailTemplate.Text);

            // only show the template logo uploader if there is a div with id='template-logo'
            // then update the help-message on the loader based on the template-logo's data-instructions attribute and width and height
            // this gets called when the codeeditor is done initializing and when the cursor blurs out of the template code editor
            var templateLogoNode = templateDoc.GetElementbyId("template-logo");

            if (templateLogoNode != null)
            {
                string helpText = null;
                if (templateLogoNode.Attributes.Contains("data-instructions"))
                {
                    helpText = templateLogoNode.Attributes["data-instructions"].Value;
                }

                if (helpText.IsNullOrWhiteSpace())
                {
                    helpText = "The Logo that can be included in the contents of the message";
                }

                string helpWidth  = null;
                string helpHeight = null;
                if (templateLogoNode.Attributes.Contains("width"))
                {
                    helpWidth = templateLogoNode.Attributes["width"].Value;
                }

                if (templateLogoNode.Attributes.Contains("height"))
                {
                    helpHeight = templateLogoNode.Attributes["height"].Value;
                }

                if (helpWidth.IsNotNullOrWhiteSpace() && helpHeight.IsNotNullOrWhiteSpace())
                {
                    helpText += string.Format(" (Image size: {0}px x {1}px)", helpWidth, helpHeight);
                }

                imgTemplateLogo.Help = helpText;
            }

            pnlTemplateLogo.Visible = templateLogoNode != null;

            // take care of the lava fields stuff
            var lavaFieldsNode = templateDoc.GetElementbyId("lava-fields");

            if (lavaFieldsNode == null)
            {
                lavaFieldsNode = templateDoc.CreateElement("noscript");
                lavaFieldsNode.Attributes.Add("id", "lava-fields");
            }
            else if (lavaFieldsNode.ParentNode.Name == "body")
            {
                // if the lava-fields is a in the body (from pre-v9 template), remove it from body, and let it get added to head instead
                lavaFieldsNode.Attributes.Remove("style");
                lavaFieldsNode.Remove();
                lavaFieldsNode.Name = "noscript";
            }

            var templateDocLavaFieldLines = lavaFieldsNode.InnerText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).Select(a => a.Trim()).Where(a => a.IsNotNullOrWhiteSpace()).ToList();

            // dictionary of keys and default values from Lava Fields KeyValueList control
            var lavaFieldsDefaultDictionary = kvlMergeFields.Value.AsDictionary();

            // add any new lava fields that were added to the KeyValueList editor
            foreach (var keyValue in lavaFieldsDefaultDictionary)
            {
                string pattern = string.Format(@"{{%\s+assign\s+{0}.*\s+=\s", keyValue.Key);
                if (!templateDocLavaFieldLines.Any(a => Regex.IsMatch(a, pattern)))
                {
                    templateDocLavaFieldLines.Add("{% assign " + keyValue.Key + " = '" + keyValue.Value + "' %}");
                }
            }

            // remove any lava fields that are not in the KeyValueList editor
            foreach (var templateDocLavaFieldLine in templateDocLavaFieldLines.ToList())
            {
                var found = false;
                foreach (var keyValue in lavaFieldsDefaultDictionary)
                {
                    var pattern = string.Format(@"{{%\s+assign\s+{0}.*\s+=\s", keyValue.Key);
                    if (!Regex.IsMatch(templateDocLavaFieldLine, pattern))
                    {
                        continue;
                    }

                    found = true;
                    break;
                }

                // if not found, delete it
                if (!found)
                {
                    templateDocLavaFieldLines.Remove(templateDocLavaFieldLine);
                }
            }

            // dictionary of keys and values from the lava fields in the 'lava-fields' div
            var lavaFieldsTemplateDictionary = new Dictionary <string, string>();

            foreach (var templateDocLavaFieldLine in templateDocLavaFieldLines)
            {
                var match = Regex.Match(templateDocLavaFieldLine, @"{% assign (.*)\=(.*) %}");
                if (match.Groups.Count != 3)
                {
                    continue;
                }

                var key   = match.Groups[1].Value.Trim().RemoveSpaces();
                var value = match.Groups[2].Value.Trim().Trim('\'');

                // If this is a postback, there will be a control that holds the value
                var lavaValueControl = phLavaFieldsControls.FindControl("lavaValue_" + key) as RockTextBox;
                if (lavaValueControl != null && lavaValueControl.Text != value)
                {
                    value = lavaValueControl.Text;
                }

                lavaFieldsTemplateDictionary.Add(key, value);
            }

            if (lavaFieldsTemplateDictionary.Any())
            {
                var lavaAssignsHtml = new StringBuilder();
                lavaAssignsHtml.AppendLine();
                lavaAssignsHtml.AppendLine("    {% comment %}  Lava Fields: Code-Generated from Template Editor {% endcomment %}");
                foreach (var lavaFieldsTemplateItem in lavaFieldsTemplateDictionary)
                {
                    lavaAssignsHtml.AppendLine(string.Format("    {{% assign {0} = '{1}' %}}", lavaFieldsTemplateItem.Key, lavaFieldsTemplateItem.Value));
                }

                lavaAssignsHtml.Append("  ");

                lavaFieldsNode.InnerHtml = lavaAssignsHtml.ToString();

                if (lavaFieldsNode.ParentNode == null)
                {
                    var headNode = templateDoc.DocumentNode.SelectSingleNode("//head");
                    if (headNode != null)
                    {
                        // prepend a linefeed so that it is after the lava node (to make it pretty printed)
                        headNode.PrependChild(templateDoc.CreateTextNode("\r\n"));

                        headNode.PrependChild(lavaFieldsNode);

                        // prepend a indented linefeed so that it ends up prior the lava node (to make it pretty printed)
                        headNode.PrependChild(templateDoc.CreateTextNode("\r\n  "));
                    }
                }
            }
            else if (lavaFieldsNode.ParentNode != null)
            {
                if (lavaFieldsNode.NextSibling != null && lavaFieldsNode.NextSibling.Name == "#text")
                {
                    // remove the extra line endings
                    lavaFieldsNode.NextSibling.InnerHtml = lavaFieldsNode.NextSibling.InnerHtml.TrimStart(' ', '\r', '\n');
                }

                lavaFieldsNode.Remove();
            }

            hfLavaFieldsState.Value = lavaFieldsTemplateDictionary.ToJson(Newtonsoft.Json.Formatting.None);

            ceEmailTemplate.Text = templateDoc.DocumentNode.OuterHtml;

            CreateDynamicLavaValueControls();

            var mergeFields         = Rock.Lava.LavaHelper.GetCommonMergeFields(RockPage);
            var resolvedPreviewHtml = ceEmailTemplate.Text.ResolveMergeFields(mergeFields);

            if (cbCssInliningEnabled.Checked)
            {
                resolvedPreviewHtml = resolvedPreviewHtml.ConvertHtmlStylesToInlineAttributes();
            }

            ifEmailPreview.Attributes["srcdoc"] = resolvedPreviewHtml;
            pnlEmailPreview.Visible             = true;
            upnlEmailPreview.Update();
        }
Exemple #8
0
        public string monPage()
        {
            Uri    uri  = new Uri(DBsettings.DBURL + "mon.php");
            string resp = null;

            //monster list doc
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            //monster detail doc
            //HtmlAgilityPack.HtmlDocument subdoc = new HtmlAgilityPack.HtmlDocument();
            //tempary doc
            HtmlAgilityPack.HtmlDocument _doc = new HtmlAgilityPack.HtmlDocument();
            //create empty table
            monTable  = null;
            outHtml   = "";
            monUrlSet = new HashSet <string>();
            monTable  = _doc.CreateElement("table");
            //monTable.AddClass("table table-striped table-bordered");
            monTable.AppendChild(_doc.CreateElement("thead"));
            monTable.AppendChild(_doc.CreateElement("tbody"));
            var theadNode = monTable.SelectSingleNode(".//thead");


            var monList           = new HtmlAgilityPack.HtmlNode[] { };
            var simpleCrawlResult = WebRequest.RequestAction(new RequestOptions()
            {
                Uri = uri, Method = "Get"
            });

            //load monster list
            doc.LoadHtml(simpleCrawlResult);
            var monSpan = doc.DocumentNode.SelectSingleNode("//h5[@class='card-header']").InnerHtml;

            resp         = monSpan;
            areaTab_Main = doc.DocumentNode.SelectSingleNode("//div[@id = 'Monstermon_list15']");
            string tableClass = areaTab_Main.SelectSingleNode(".//table").GetAttributeValue("class", "");

            monTable.AddClass(tableClass);
            HtmlAgilityPack.HtmlNode[] mons = areaTab_Main.SelectNodes(".//tbody/tr[position() < 5]").ToArray();
            Console.Out.WriteLine("Total " + mons.Count() + " monster fetched");
            //var _thead = monTable.SelectSingleNode(".//thead");
            //add thead
            if (_thead == "")
            {
                string[] monTh = DBsettings.monTableHead;
                foreach (var th in monTh)
                {
                    _thead += "<th>" + th + "</th>";
                }
                theadNode.InnerHtml = _thead;
            }
            if (theadNode.InnerHtml == "")
            {
                theadNode.InnerHtml = _thead;
            }

            foreach (var mon in mons)
            {
                outHtml += monDetailPg(mon);
            }

            monTable.SelectSingleNode(".//tbody").InnerHtml += outHtml;
            resp += monTable.OuterHtml;
            return(resp);
        }
        public static string ReplaceSliderAndAddons(ControllerContext controllerContext, string activeThemePath, string ContentText)
        {
            var context = getDbContextObject();

            string HTMLContent = HttpUtility.HtmlDecode(ContentText);

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

            doc.OptionFixNestedTags = false;
            doc.OptionCheckSyntax   = false;
            doc.LoadHtml(HTMLContent);

            var Sliders = doc.DocumentNode.SelectNodes("//slider");

            if (Sliders != null)
            {
                foreach (var item in Sliders)
                {
                    var HTMLSlider = "";
                    int sliderid   = 0;
                    if (Int32.TryParse(item.InnerText, out sliderid))
                    {
                        List <CL_Slide> slides = context.Slides.Where(x => x.SliderId == sliderid).Select(x =>
                                                                                                          new CL_Slide {
                            Image = x.Image, Link = x.Link, Text = x.Text, Title = x.Title, DisplayOrder = x.DisplayOrder
                        }
                                                                                                          ).ToList();
                        HTMLSlider = RenderRazorViewToString(controllerContext, activeThemePath + "slider.cshtml", slides);
                    }
                    //HtmlAgilityPack.HtmlNode newNode = HtmlAgilityPack.HtmlNode.CreateNode(HTMLSlider);
                    //item.ParentNode.ReplaceChild(newNode, item);

                    HtmlAgilityPack.HtmlNode newNode = doc.CreateElement("div");
                    newNode.Attributes.Add("class", "divNTS");
                    newNode.InnerHtml = HTMLSlider;
                    item.ParentNode.ReplaceChild(newNode, item);
                }
            }
            var Addons = doc.DocumentNode.SelectNodes("//addon");

            if (Addons != null)
            {
                foreach (var addonTag in Addons)
                {
                    var            HTMLAddon  = "";
                    string         strAddonId = addonTag.InnerText.ToLower();
                    List <Content> addonsList = new List <Content>();
                    if (strAddonId == "all")
                    {
                        string addonType = addonTag.Attributes["name"].Value.ToLower();
                        addonsList = context.Content.Where(x => x.Type.ToLower() == addonType && x.isPublished == true && x.IsDeleted == false).OrderBy(x => x.ContentOrder).ToList();
                    }
                    else
                    {
                        int addonid = 0;
                        if (Int32.TryParse(strAddonId, out addonid))
                        {
                            Content addon = context.Content.Where(x => x.ID == addonid && x.isPublished == true && x.IsDeleted == false).FirstOrDefault();
                            if (addon != null)
                            {
                                addonsList.Add(addon);
                            }
                        }
                    }
                    foreach (var item in addonsList)
                    {
                        string itemHTMLAddon = item.AddonSubLayout;
                        itemHTMLAddon = itemHTMLAddon.Replace("{{Title}}", item.Title);
                        itemHTMLAddon = itemHTMLAddon.Replace("{{URL}}", (string.IsNullOrEmpty(item.URL) ? "#" : item.URL));
                        itemHTMLAddon = itemHTMLAddon.Replace("{{Description}}", item.Description);

                        HTMLAddon += itemHTMLAddon;
                    }

                    //var newNode = HtmlAgilityPack.HtmlNode.CreateNode(HTMLAddon);
                    //addonTag.ParentNode.ReplaceChild(newNode, addonTag);
                    HtmlAgilityPack.HtmlNode newNode = doc.CreateElement("div");
                    newNode.Attributes.Add("class", "divNTS");
                    newNode.InnerHtml = HTMLAddon;
                    addonTag.ParentNode.ReplaceChild(newNode, addonTag);
                }
            }
            HTMLContent = doc.DocumentNode.OuterHtml;
            return(HTMLContent);
        }
Exemple #10
0
        public HtmlNode CreateElement(string name)
        {
            var newElement = _htmlDocument.CreateElement(name);

            return(newElement == null ? null : new HtmlNode(newElement));
        }
Exemple #11
0
        public ActionResult Forgot(FormCollection collection)
        {
            try
            {
                var model = new Models.Passwords.Forgot {
                    Username = collection["Username"], Email = collection["Email"]
                };
                if (!TryValidateModel(model))
                {
                    return(View(model));
                }

                using (var ctx = new Models.Ao3TrackEntities())
                {
                    var user = (from users in ctx.Users
                                where users.username == model.Username
                                select users).FirstOrDefault();

                    if (user == null)
                    {
                        ModelState.AddModelError("Username", "Unknown Username");
                        return(View(model));
                    }

                    if (user.email != model.Email)
                    {
                        ModelState.AddModelError("Email", "Email address does not match database");
                        return(View(model));
                    }

                    var pwrequest = new Models.PWReset {
                        id = Guid.NewGuid(), expires = DateTime.Now.AddDays(1), user = user.id, oldhash = user.hash, complete = false
                    };
                    ctx.PWResets.Add(pwrequest);
                    ctx.SaveChanges();

                    var uri = new Uri(Request.Url, Url.Action("Reset", new { id = pwrequest.id.ToString("N") }));

                    MailMessage message = new MailMessage(new MailAddress("*****@*****.**", "Archive Track Reader"), new MailAddress(user.email));
                    message.Subject = "Archive Track Reader Password Reset Request";

                    var doc  = new HtmlAgilityPack.HtmlDocument();
                    var html = doc.CreateElement("html");
                    doc.DocumentNode.AppendChild(html);

                    var head = doc.CreateElement("head");
                    html.AppendChild(head);

                    var title = doc.CreateElement("title");
                    title.AppendChild(doc.CreateTextNode("Archive Track Reader Password Reset Request"));
                    head.AppendChild(title);


                    var style = doc.CreateElement("style");
                    style.AppendChild(doc.CreateTextNode(@"body {
    color: #191919;
    background: #CCCCCC;
}

h1, h2, h3, h4, h5, h6, h7, h8, a {
    color: #A50000;
}

details p {
    color: #656565;
}"));
                    head.AppendChild(style);

                    var body = doc.CreateElement("body");
                    html.AppendChild(body);

                    var heading = doc.CreateElement("h1");
                    heading.AppendChild(doc.CreateTextNode("Archive Track Reader Password Reset Request"));
                    body.AppendChild(heading);

                    var para = doc.CreateElement("p");
                    para.AppendChild(doc.CreateTextNode("A Password Reset Request was made for the account: " + System.Net.WebUtility.HtmlEncode(user.username)));
                    body.AppendChild(para);

                    para = doc.CreateElement("p");
                    para.AppendChild(doc.CreateTextNode("Follow this link "));
                    var link = doc.CreateElement("a");
                    link.Attributes.Add(doc.CreateAttribute("href", System.Net.WebUtility.HtmlEncode(uri.AbsoluteUri)));
                    link.AppendChild(doc.CreateTextNode(System.Net.WebUtility.HtmlEncode(uri.AbsoluteUri)));
                    para.AppendChild(link);
                    para.AppendChild(doc.CreateTextNode(" to change the account's password."));

                    body.AppendChild(para);
                    para.AppendChild(doc.CreateTextNode("The link will expire at " + pwrequest.expires.ToString("r") + "."));
                    para = doc.CreateElement("p");

                    body.AppendChild(para);

                    var writer = new System.IO.StringWriter();
                    doc.Save(writer);

                    message.Body       = "<!DOCTYPE html>\n" + writer.ToString();
                    message.IsBodyHtml = true;

                    SmtpClient client = new SmtpClient("127.0.0.1");
                    client.Send(message);

                    return(View("ForgotDone", user));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.ToString());

                return(View());
            }
        }