PublishedContent - ensure exceptions don't corrupt InPreviewMode

This commit is contained in:
Stephan
2013-09-30 13:55:37 +02:00
parent 77777c8007
commit 5a15c93195
2 changed files with 28 additions and 17 deletions

View File

@@ -35,19 +35,25 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
UmbracoContext.Current.InPreviewMode = preview;
var sb = new StringBuilder();
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
MacroTagParser.ParseMacros(
source,
//callback for when text block is found
textBlock => sb.Append(textBlock),
//callback for when macro syntax is found
(macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro(
macroAlias,
//needs to be explicitly casted to Dictionary<string, object>
macroAttributes.ConvertTo(x => (string)x, x => x)).ToString()));
// restore
UmbracoContext.Current.InPreviewMode = inPreviewMode;
try
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
MacroTagParser.ParseMacros(
source,
//callback for when text block is found
textBlock => sb.Append(textBlock),
//callback for when macro syntax is found
(macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro(
macroAlias,
//needs to be explicitly casted to Dictionary<string, object>
macroAttributes.ConvertTo(x => (string) x, x => x)).ToString()));
}
finally
{
// restore
UmbracoContext.Current.InPreviewMode = inPreviewMode;
}
return sb.ToString();
}

View File

@@ -21,10 +21,15 @@ namespace Umbraco.Web.Templates
var inPreviewMode = UmbracoContext.Current.InPreviewMode;
UmbracoContext.Current.InPreviewMode = preview;
text = ParseInternalLinks(text);
// restore
UmbracoContext.Current.InPreviewMode = inPreviewMode;
try
{
text = ParseInternalLinks(text);
}
finally
{
// restore
UmbracoContext.Current.InPreviewMode = inPreviewMode;
}
return text;
}