public override PagePart Execute(PagePart thisPart) { int counter = 0; List<string> domainsToRemove = Settings["removeDomains"].Split(new Char[] {','}).ToList<string>(); if (thisPart.ParsedContent.SelectNodes(".//a") == null) { return thisPart; } foreach (HtmlNode link in thisPart.ParsedContent.SelectNodes(".//a")) { if (link.Attributes["href"] == null) { continue; } foreach (string domainToRemove in domainsToRemove) { if (link.Attributes["href"].Value.Contains(domainToRemove)) { counter++; link.Attributes["href"].Value = link.Attributes["href"].Value.Replace(String.Concat("http://", domainToRemove), ""); link.Attributes["href"].Value = link.Attributes["href"].Value.Replace(String.Concat("https://", domainToRemove), ""); } } } thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Removed {0} domain(s)", counter.ToString())); return thisPart; }
public override PagePart Execute(PagePart thisPart) { int counter = 0; string pattern = Settings["pattern"]; string attribute = Settings["attribute"]; string value = null; if (Settings.ContainsKey("value")) { value = Settings["value"]; } if (thisPart.ParsedContent.SelectNodes(pattern) != null) { foreach (HtmlNode thisNode in thisPart.ParsedContent.SelectNodes(pattern)) { if (thisNode.Attributes[attribute] != null) { //If we have a value, and this attribute doesn't match that value, skip it if (value != null && value.ToLowerInvariant() != thisNode.Attributes[attribute].Value.ToLowerInvariant()) { continue; } counter++; thisNode.Attributes[attribute].Remove(); } } } thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format(" Pattern: {0}; Attribute: {1}; Removed {2} attribute(s).", pattern, attribute, counter.ToString())); return thisPart; }
public PageLayout GetLayout(IDocument document) { var bodyPart = new PagePart { Name = "Body", Renderer = "Body" }; var mainSection = new PageSection { Name = "Main" }; mainSection.Parts.Add(bodyPart); var twitterPart = new PagePart() { Name = "Twitter", Renderer = "Twitter" }; var sidebarSection = new PageSection { Name = "Sidebar" }; sidebarSection.Parts.Add(twitterPart); var layout = new PageLayout { Name = "BaseDocumentLayout" }; layout.Sections.Add(mainSection); layout.Sections.Add(sidebarSection); return(layout); }
public ActionResult WithDiscount(string courseTC) { var groups = GroupService.GetGroupsForCourse(courseTC) .Where(x => x.Discount.HasValue && !x.IsOpenLearning).ToList(); var prices = PriceService.GetAllPricesForCourse(courseTC, null); var course = CourseService.GetByPK(courseTC); var actionBlock = new PagePart(string.Empty); if (groups.Any(x => x.Discount == CommonConst.GoldFallDiscount)) { actionBlock = new PagePart( Htmls.HtmlBlock(HtmlBlocks.GoldFallLarge)); } return(BaseView( new PagePart(H.h3[Html.CourseLink(course)].ToString()), actionBlock, new PagePart( Views.Shared.Education.NearestGroupList, new GroupsWithDiscountVM(groups, true) { Course = course, Prices = prices }))); }
public override PagePart Execute(PagePart thisPart) { int counter = 0; HtmlNode thisContent = thisPart.ParsedContent; string pattern = Settings["pattern"]; string attribute = Settings["attribute"]; string value = Settings["value"]; if (thisContent.SelectNodes(pattern) == null) { //No such pattern. Return the part with no changes. return thisPart; } foreach (HtmlNode thisNode in thisContent.SelectNodes(pattern)) { counter++; if (thisNode.Attributes[attribute] != null) { thisNode.Attributes[attribute].Value = value; } else { thisNode.Attributes.Add(attribute, value); } } thisPart.ParsedContent = thisContent; thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Pattern: {0}; Attribute: {1}; Value: {2} Set attribute on (3) element(s)", pattern, attribute, value, counter.ToString())); return thisPart; }
public override PagePart Execute(PagePart thisPart) { int counter = 0; string pattern = Settings["pattern"]; pattern = pattern.Replace("&", "&"); if (thisPart.ParsedContent.SelectNodes(pattern) != null) { foreach (HtmlNode nodeToRemove in thisPart.ParsedContent.SelectNodes(pattern)) { // Only remove nodes with nothing but whitespace in them if (nodeToRemove.InnerHtml.Trim().Length == 0) { counter++; nodeToRemove.ParentNode.RemoveChild(nodeToRemove); } } } thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Pattern: {0}; Removed {1} element(s).", pattern, counter.ToString())); return thisPart; }
public override PagePart Execute(PagePart thisPart) { int lengthBeforeStripping = thisPart.Content.Length; string content = thisPart.Content; thisPart.Content = content.Trim(); thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Length before: {0}; Length after: {1}", lengthBeforeStripping.ToString(), thisPart.Content.Length.ToString())); return thisPart; }
public override PagePart Execute(PagePart thisPart) { int counter = 0; string pattern = "img"; string directory = String.Empty; if (Settings.Exists("directory")) { directory = Settings["directory"]; } else { directory = ArtifactManager.GetArtifactPath("downloaded-assets"); } //Have any images? if (thisPart.ParsedContent.SelectNodes(pattern) != null) { //Loop through them foreach(HtmlNode image in thisPart.ParsedContent.SelectNodes(pattern)) { //If they're remote, skip it if (image.Attributes["src"].Value.StartsWith("http")) { continue; } counter++; //Get the corrected path with the domain (to make the request) string assetPathWithDomain = thisPart.Page.GetContextualUrl(image.Attributes["src"].Value, true); //Get the corrected path without the domain (to save the file) string assetPathWithoutDomain = thisPart.Page.GetContextualUrl(image.Attributes["src"].Value, false); //Add the directory from the settings string newImagePath = String.Concat(directory, "/", assetPathWithoutDomain); //Get the file data Byte[] fileData = Utils.MakeBinaryHttpRequest(assetPathWithDomain); //Save the file ArtifactManager.SaveFileData(fileData, newImagePath); //Correct the reference to the image image.Attributes["src"].Value = newImagePath; thisPart.Meta.Add(String.Concat("Downloaded Asset ", counter.ToString()), assetPathWithoutDomain); } } thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Saved {0} image(s) locally.", counter.ToString())); return thisPart; }
public override PagePart Execute(PagePart thisPart) { int lengthBeforeStripping = thisPart.Content.Length; string content = thisPart.Content; thisPart.Content = Regex.Replace(content, @"<!--.*?-->", String.Empty, RegexOptions.Singleline); thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Length before: {0}; Length after: {1}; Comment characters removed: {2}", lengthBeforeStripping.ToString(), thisPart.Content.Length.ToString(), (lengthBeforeStripping - thisPart.Content.Length).ToString())); return thisPart; }
public void CachePart(PagePart part) { lock (passiveActiveLock) { // If cache too big, remove and recycle MakeAFreeSpace(); // Then add part activeCache.Add(part); } }
private static PagePart Find(IEnumerable <PagePart> vector, PagePart fakePart) { foreach (var part in vector) { if (part.Equals(fakePart)) { return(part); } } return(null); }
public override PagePart Execute(PagePart thisPart) { string content = thisPart.Content; int lengthBefore = content.Length; string newString = Settings.Exists("newString") ? Settings["newString"] : String.Empty; string oldString = Settings["oldString"]; thisPart.Content = content.Replace(oldString, newString); thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Length before: {0}; Length after: {1}", lengthBefore.ToString(), thisPart.Content.Length.ToString())); return thisPart; }
public void CacheThumbnail(PagePart part) { lock (thumbnails) { // If cache too big, remove and recycle if (thumbnails.Count >= Constants.Cache.ThumbnailsCacheSize) { thumbnails[0].RenderedBitmap.Recycle(); thumbnails.RemoveAt(0); } // Then add thumbnail thumbnails.Add(part); } }
public bool ContainsThumbnail(int page, RectF pageRelativeBounds) { var fakePart = new PagePart(page, null, pageRelativeBounds, true, 0); lock (thumbnails) { foreach (var part in thumbnails) { if (part.Equals(fakePart)) { return(true); } } return(false); } }
public override PagePart Execute(PagePart thisPart) { if (!thisPart.Content.Contains(Settings["character"])) { thisPart.AddMessage(this, StandardMessageTypes.Notice, String.Format("Character \"{0}\" not found.", Settings["character"])); } int lengthBefore = thisPart.Content.Length; var parts = thisPart.Content.Split(Settings["character"].ToCharArray()); thisPart.Content = String.Join(String.Empty, parts.Take(parts.Length - 1).ToArray()); thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Length before: {0}; Length after: {1}", lengthBefore.ToString(), thisPart.Content.Length.ToString())); return thisPart; }
public override PagePart Execute(PagePart thisPart) { int counter = 0; string pattern = Settings.Exists("tag") ? Settings["tag"] : "*"; string className = Settings.Exists("class") ? Settings["class"] : "*"; if (thisPart.ParsedContent.SelectNodes(pattern) != null) { foreach (HtmlNode matchingNode in thisPart.ParsedContent.SelectNodes(pattern)) { if (matchingNode.Attributes["class"] == null) { continue; } counter++; if (className == "*") { matchingNode.Attributes["class"].Remove(); continue; } List<string> currentClasses = matchingNode.Attributes["class"].Value.Split(new Char[] { ' ' }).ToList<string>(); currentClasses.Remove(className); //If we now have no classes, just remove the whole thing if (currentClasses.Count == 0) { matchingNode.Attributes["class"].Remove(); } else { //Otherwise, set it back to what's left matchingNode.Attributes["class"].Value = String.Join(" ", currentClasses.ToArray()); } } } thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format(" Pattern: {0}; Class: {1}; Removed classes from {2} tag(s).", pattern, className, counter.ToString())); return thisPart; }
public bool UpPartIfContained(int page, RectF pageRelativeBounds, int toOrder) { var fakePart = new PagePart(page, null, pageRelativeBounds, false, 0); lock (passiveActiveLock) { PagePart found; if ((found = Find(passiveCache, fakePart)) != null) { passiveCache.Remove(found); found.CacheOrder = toOrder; activeCache.Add(found); return(true); } return(Find(activeCache, fakePart) != null); } }
public override PagePart Execute(PagePart thisPart) { string pattern = Settings["pattern"]; string result = String.Empty; if (thisPart.ParsedContent.SelectSingleNode(pattern) != null) { thisPart.Content = thisPart.ParsedContent.SelectSingleNode(pattern).InnerHtml; result = "Found and inflated"; } else { result = "Not found"; } thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format(" Pattern: {0}; Result: {1}", pattern, result )); return thisPart; }
public override PagePart Execute(PagePart thisPart) { using (Document doc = new Document(thisPart.Content)) { doc.ShowWarnings = false; doc.Quiet = true; doc.IndentBlockElements = AutoBool.Yes; doc.OutputXhtml = true; doc.OutputBodyOnly = AutoBool.Yes; doc.WrapAt = 10000; doc.CleanAndRepair(); string parsed = doc.Save(); thisPart.Content = parsed; thisPart.AddMessage(this, StandardMessageTypes.Executed, "Processed by HTMLTidy"); } return thisPart; }
public void OnBitmapRendered(PagePart part) { // when it is first rendered part if (state == State.Loaded) { state = State.Shown; Callbacks.CallOnRender(this, new RenderedEventArgs(PdfFile.PagesCount)); } if (part.Thumbnail) { CacheManager.CacheThumbnail(part); } else { CacheManager.CachePart(part); } Redraw(); }
public override PagePart Execute(PagePart thisPart) { int counter = 0; string oldTag = Settings["old"].TrimStart('/'); string newTag = Settings["new"].TrimStart('/'); if (thisPart.ParsedContent.SelectNodes("//" + oldTag) == null) { return thisPart; } foreach (HtmlNode matchingNode in thisPart.ParsedContent.SelectNodes("//" + oldTag)) { counter++; matchingNode.Name = newTag; } thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Old tag: {0}; New tag: {1}; Swapped {2} tag(s).", oldTag, newTag, counter.ToString())); return thisPart; }
public override PagePart Execute(PagePart thisPart) { int counter = 0; string pattern = Settings["pattern"]; pattern = pattern.Replace("&", "&"); bool preserveContents = Settings.Exists("preserveContents") ? Convert.ToBoolean(Settings["preserveContents"]) : false; if (thisPart.ParsedContent.SelectNodes(pattern) != null) { foreach (HtmlNode nodeToRemove in thisPart.ParsedContent.SelectNodes(pattern)) { counter++; nodeToRemove.ParentNode.RemoveChild(nodeToRemove, preserveContents); } } thisPart.AddMessage(this, StandardMessageTypes.Executed, String.Format("Pattern: {0}; Removed {1} element(s).", pattern, counter.ToString())); return thisPart; }
public abstract PagePart Execute(PagePart pagePart);
public override PagePart Execute(PagePart thisPart) { thisPart.Content = thisPart.ParsedContent.InnerText; return thisPart; }
private void DrawPart(Canvas canvas, PagePart part) { // Can seem strange, but avoid lot of calls var pageRelativeBounds = part.PageRelativeBounds; var renderedBitmap = part.RenderedBitmap; if (renderedBitmap.IsRecycled) { return; } // Move to the target page float localTranslationX = 0; float localTranslationY = 0; var size = PdfFile.GetPageSize(part.Page); if (IsSwipeVertical) { localTranslationY = PdfFile.GetPageOffset(part.Page, Zoom); var maxWidth = PdfFile.MaxPageWidth; localTranslationX = ToCurrentScale(maxWidth - size.Width) / 2; } else { localTranslationX = PdfFile.GetPageOffset(part.Page, Zoom); var maxHeight = PdfFile.MaxPageHeight; localTranslationY = ToCurrentScale(maxHeight - size.Height) / 2; } canvas.Translate(localTranslationX, localTranslationY); var srcRect = new Rect(0, 0, renderedBitmap.Width, renderedBitmap.Height); var offsetX = ToCurrentScale(pageRelativeBounds.Left * size.Width); var offsetY = ToCurrentScale(pageRelativeBounds.Top * size.Height); var width = ToCurrentScale(pageRelativeBounds.Width() * size.Width); var height = ToCurrentScale(pageRelativeBounds.Height() * size.Height); // If we use float values for this rectangle, there will be // a possible gap between page parts, especially when // the zoom level is high. var dstRect = new RectF((int)offsetX, (int)offsetY, (int)(offsetX + width), (int)(offsetY + height)); // Check if bitmap is in the screen var translationX = CurrentXOffset + localTranslationX; var translationY = CurrentYOffset + localTranslationY; if (translationX + dstRect.Left >= Width || translationX + dstRect.Right <= 0 || translationY + dstRect.Top >= Height || translationY + dstRect.Bottom <= 0) { canvas.Translate(-localTranslationX, -localTranslationY); return; } canvas.DrawBitmap(renderedBitmap, srcRect, dstRect, paint); if (Constants.DebugMode) { debugPaint.Color = part.Page % 2 == 0 ? Color.Red : Color.Blue; canvas.DrawRect(dstRect, debugPaint); } // Restore the canvas position canvas.Translate(-localTranslationX, -localTranslationY); }