-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRazorWebControl.cs
93 lines (86 loc) · 3.44 KB
/
RazorWebControl.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
using System;
using System.IO;
using System.Web.UI;
using Connect.DNN.Modules.SkinControls.Razor;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
namespace Connect.DNN.Modules.SkinControls
{
public class RazorWebControl : UserControlBase
{
public string ControlName { get; set; }
public string ControlPath { get; set; }
private string ControlSource { get; set; }
public string LocalResourceFile
{
get
{
return string.IsNullOrEmpty(_localResourceFile) ? this.Parent.AppRelativeTemplateSourceDirectory + Localization.LocalResourceDirectory + "/SharedResources.resx" : _localResourceFile;
}
set { _localResourceFile = value; }
}
private RazorEngine _engine;
private string _localResourceFile;
public RazorEngine Engine
{
get { return _engine ?? (_engine = new RazorEngine(string.Format("~{0}{1}.cshtml", ControlPath, ControlSource), Attributes, PortalSettings, LocalResourceFile)); }
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
try
{
if (!(string.IsNullOrEmpty(ControlName)))
{
if (string.IsNullOrEmpty(ControlPath))
{
ControlPath = "/DesktopModules/Connect/SkinControls/Controls/";
}
if (ControlPath.ToLower() == "skin")
{
ControlPath = PortalSettings.ActiveTab.SkinPath.Substring(DotNetNuke.Common.Globals.ApplicationPath.Length) + "Controls/";
}
ControlSource = ControlName;
var writer = new StringWriter();
switch (ControlName.ToLower())
{
case "user":
if (Request.IsAuthenticated)
{
ControlSource = "UserAuthenticated";
Engine.Render(writer, UserController.Instance.GetCurrentUserInfo());
}
else
{
ControlSource = "UserUnauthenticated";
Engine.Render(writer);
}
break;
case "login":
if (Request.IsAuthenticated)
{
ControlSource = "LoginAuthenticated";
Engine.Render(writer, UserController.Instance.GetCurrentUserInfo());
}
else
{
ControlSource = "LoginUnauthenticated";
Engine.Render(writer);
}
break;
default:
Engine.Render(writer);
break;
}
Controls.Add(new LiteralControl(writer.ToString()));
}
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
}
}