public HtmlString Render()
{
var renderHelp = new RenderingHelpers(this);
try
{
string innerContent = null;
#region do pre-check to see if system is stable & ready
var notReady = new InstallationController().CheckUpgradeMessage(PortalSettings.Current.UserInfo.IsSuperUser);
if (!string.IsNullOrEmpty(notReady))
innerContent = renderHelp.DesignErrorMessage(new Exception(notReady), true, "Error - needs admin to fix this", false, false);
#endregion
#region check if the content-group exists (sometimes it's missing if a site is being imported and the data isn't in yet
if (innerContent == null)
{
if (ContentBlock.DataIsMissing)
{
if (Environment.Permissions.UserMayEditContent)
{
innerContent = ""; // stop further processing
}
else // end users should see server error as no js-side processing will happen
{
var ex =
new Exception(
"Data is missing - usually when a site is copied but the content / apps have not been imported yet - check 2sxc.org/help?tag=export-import");
innerContent = renderHelp.DesignErrorMessage(ex, true,
"Error - needs admin to fix", false, true);
}
}
}
#endregion
#region try to render the block or generate the error message
if (innerContent == null)
try
{
if (Template != null) // when a content block is still new, there is no definition yet
{
var engine = GetRenderingEngine(InstancePurposes.WebView);
innerContent = engine.Render();
}
else innerContent = "";
}
catch (Exception ex)
{
innerContent = renderHelp.DesignErrorMessage(ex, true, "Error rendering template", false, true);
}
#endregion
#region Wrap it all up into a nice wrapper tag
var editInfos = JsonConvert.SerializeObject(renderHelp.GetClientInfosAll());
var startTag = (RenderWithDiv
? $"<div class=\"sc-viewport sc-content-block\" data-cb-instance=\"{ContentBlock.ParentId}\" " +
$" data-cb-id=\"{ContentBlock.ContentBlockId}\""
+
(RenderWithEditMetadata
? " data-edit-context=\'" + editInfos + "'"
: "")
+ ">\n"
: "");
var endTag = (RenderWithDiv ? "\n</div>" : "");
string result = startTag + innerContent + endTag;
#endregion
return new HtmlString(result);
}
catch (Exception ex)
{
// todo: i18n
return new HtmlString(renderHelp.DesignErrorMessage(ex, true, null, true, true));
}
}