forked from sachatrauwaen/OpenContent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenderModule.ascx.cs
116 lines (111 loc) · 4.63 KB
/
RenderModule.ascx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.UI.Skins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Satrabel.OpenContent.Components.Render;
using Satrabel.OpenContent.Components.Logging;
using Satrabel.OpenContent.Components.Json;
namespace Satrabel.OpenContent
{
public partial class RenderModule : SkinObjectBase
{
public int ModuleId { get; set; }
public int TabId { get; set; }
public string HideOnTabIds { get; set; }
public bool ShowOnAdminTabs { get; set; }
public bool ShowOnHostTabs { get; set; }
private void InitializeComponent()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
int[] hideTabs = new int[1] { TabId };
if (string.IsNullOrEmpty(HideOnTabIds))
{
try
{
hideTabs = HideOnTabIds.Split(',', ' ', ';').Select(s => int.Parse(s)).ToArray();
}
catch (Exception)
{
}
}
var activeTab = PortalSettings.ActiveTab;
if (hideTabs.Contains(activeTab.TabID)) return;
if (!ShowOnAdminTabs && activeTab.ParentId == PortalSettings.AdminTabId) return;
if (!ShowOnHostTabs && activeTab.IsSuperTab) return;
ModuleController mc = new ModuleController();
var module = mc.GetModule(ModuleId, TabId, false);
if (module == null)
{
DotNetNuke.UI.Skins.Skin.AddPageMessage(Page, "OpenContent RenderModule SkinObject", string.Format("No module exist for TabId {0} and ModuleId {1} ", TabId, module), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
return;
}
var engine = new RenderEngine(module);
try
{
engine.Render(Page);
}
catch (TemplateException ex)
{
RenderTemplateException(ex, module);
}
catch (InvalidJsonFileException ex)
{
RenderJsonException(ex, module);
}
catch (Exception ex)
{
LoggingUtils.ProcessModuleLoadException(this, module, ex);
}
if (engine.Info.Template != null && !string.IsNullOrEmpty(engine.Info.OutputString))
{
//Rendering was succesful.
var lit = new LiteralControl(Server.HtmlDecode(engine.Info.OutputString));
Controls.Add(lit);
try
{
engine.IncludeResourses(Page, this);
}
catch (Exception ex)
{
DotNetNuke.UI.Skins.Skin.AddPageMessage(Page, "OpenContent RenderModule SkinObject", ex.Message, DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
}
}
}
private void RenderTemplateException(TemplateException ex, ModuleInfo module)
{
DotNetNuke.UI.Skins.Skin.AddPageMessage(Page,"OpenContent RenderModule SkinObject", "<p><b>Template error</b></p>" + ex.MessageAsHtml, DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
if (LogContext.IsLogActive)
{
var logKey = "Error in tempate";
LogContext.Log(module.ModuleID, logKey, "Error", ex.MessageAsList);
LogContext.Log(module.ModuleID, logKey, "Model", ex.TemplateModel);
LogContext.Log(module.ModuleID, logKey, "Source", ex.TemplateSource);
}
LoggingUtils.ProcessLogFileException(this, module, ex);
}
private void RenderJsonException(InvalidJsonFileException ex, ModuleInfo module)
{
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Page,"OpenContent RenderModule SkinObject", "<p><b>Json error</b></p>" + ex.MessageAsHtml, DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
if (LogContext.IsLogActive)
{
var logKey = "Error in json";
LogContext.Log(module.ModuleID, logKey, "Error", ex.MessageAsList);
LogContext.Log(module.ModuleID, logKey, "Filename", ex.Filename);
}
LoggingUtils.ProcessLogFileException(this, module, ex);
}
}
}