/RenderUrlRenderTask.cs Secret
Created
October 30, 2017 08:35
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
using System.Web; | |
using NewsletterStudio.Model; | |
using umbraco.BusinessLogic; | |
namespace NewsletterStudio.Services.RenderTasks.Tasks | |
{ | |
public class RenderUrlRenderTask : RenderTask | |
{ | |
public override void ProcessPreRender(RenderResult renderResult, RenderTaskParameters parameters) | |
{ | |
Regex regex = new Regex(@"\[RenderUrl:([^]]*)\]"); | |
renderResult.MessageBody = regex.Replace(renderResult.MessageBody, GetNiceUrl); | |
} | |
private static string GetNiceUrl(Match match) | |
{ | |
string urlToDownload = match.Groups[1].Value; | |
// Get the content | |
string strReturn; | |
try | |
{ | |
strReturn = Helper.DownloadWebPage(urlToDownload); | |
} | |
catch (Exception ex) | |
{ | |
strReturn = string.Format("<div style='padding:10px; border: 1px dotted red;'>Could not load \"{0}\". Is the address correct?</div>", urlToDownload); | |
Log.Add(LogTypes.Error, 0, string.Format("RenderUrlRenderTask: {0}. Is the url ok? Are you sure that the application is allowed to download content from the internet?", ex)); | |
} | |
return strReturn; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment