internal HtmlNode RecreateNode(LazyUri url, WebRequestOptions cookieDestination, string cachePath) { if (this.ExceptionType != null) { throw Caching.RebuildException(this, url); } if (this.RedirectUrl != null && this.Result == null) { return(null); } HtmlNode html; if (this.DataType == WebCacheDataType.Json) { html = FizzlerCustomSelectors.JsonToHtml(this.Result, 0, null); } else if (this.DataType == WebCacheDataType.Text) { var d = new HtmlDocument(); html = d.DocumentNode; html.SetAttributeValue("plain-text", "1"); html.AppendTextNode(this.Result); } else { html = this.Result.AsHtmlDocumentNode(); } var docnode = html.OwnerDocument.DocumentNode; docnode.SetAttributeValue("from-cache", "1"); if (this.Headers != null) { foreach (var header in this.Headers) { docnode.SetAttributeValue("header-" + header.Key, header.Value); } } if (this.Cookies != null) { foreach (var cookie in this.Cookies) { cookieDestination.AddCookie(cookie.Key, cookie.Value, PriorityCookie.PRIORITY_FromCache); } } #if DESKTOP if (this.DateRetrieved == default(DateTime)) { this.DateRetrieved = File.GetLastWriteTimeUtc(cachePath); } #endif docnode.SetAttributeValue("date-retrieved", this.DateRetrieved.ToString("o")); if (RedirectUrl != null) { docnode.SetAttributeValue("redirect-url", this.RedirectUrl.AbsoluteUri); } docnode.SetAttributeValue("requested-url", url.AbsoluteUri); html.OwnerDocument.SetPageUrl(this.PageUrl ?? this.Url); return(html); }
private HtmlNode RehydrateHtml(HtmlNode page) { foreach (var code in page.FindAll("code")) { var comment = code.FirstChild; if (comment != null && comment.NodeType == HtmlNodeType.Comment) { var c = ((HtmlCommentNode)comment).Comment; var doc = FizzlerCustomSelectors.CreateDocument(page.OwnerDocument); doc.LoadHtml(c.SubstringValue(4, c.Length - 3 - 4).Trim().ToString()); var prev = code; for (int i = 1; i < doc.DocumentNode.ChildNodes.Count; i++) { prev = code.ParentNode.InsertAfter(doc.DocumentNode.ChildNodes[i], prev); } code.ParentNode.RemoveChild(code); } } return(page); }