-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainContainer.ascx.cs
105 lines (96 loc) · 4.5 KB
/
MainContainer.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
// <copyright file="MainContainer.ascx.cs" company="Engage Software">
// Engage: Dashboard - http://www.engagemodules.com
// Copyright (c) 2004-2008
// by Engage Software ( http://www.engagesoftware.com )
// </copyright>
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
namespace Engage.Dnn.Dashboard
{
using System;
using System.Globalization;
using System.IO;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
/// <summary>
/// The main container that is used by the Engage: Dashboard module.
/// This control is registered with DNN, and is in charge of loading other requested control.
/// </summary>
public partial class MainContainer : ModuleBase
{
/// <summary>
/// The default control to load when none is indicated
/// </summary>
private const string DefaultControl = "Home.ascx";
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (PortalSecurity.HasNecessaryPermission(SecurityAccessLevel.Edit, this.PortalSettings, this.ModuleConfiguration, this.UserInfo.Username))
{
this.LoadChildControl(this.GetControlToLoad());
}
else
{
this.GlobalNavigation.Visible = false;
this.NoPermissionMessage.Visible = true;
}
}
/// <summary>
/// Gets the control to load, based on the key (or lack thereof) that is passed on the querystring.
/// </summary>
/// <returns>A relative path to the control that should be loaded into this container</returns>
private string GetControlToLoad()
{
string keyParam = string.Empty;
string[] modIdParams = this.Request.QueryString["modId"] == null ? new string[] { } : this.Request.QueryString["modId"].Split(';');
string[] keyParams = this.Request.QueryString["key"] == null ? new string[] { } : this.Request.QueryString["key"].Split(';');
for (int i = 0; i < modIdParams.Length && i < keyParams.Length; i++)
{
int modId;
if (int.TryParse(modIdParams[i], NumberStyles.Integer, CultureInfo.InvariantCulture, out modId) && modId == this.ModuleId)
{
keyParam = keyParams[i];
break;
}
}
if (Engage.Utility.HasValue(keyParam) && Enum.IsDefined(typeof(ControlKey), keyParam) && (this.UserInfo.IsSuperUser || (ControlKey)Enum.Parse(typeof(ControlKey), keyParam) != ControlKey.Host))
{
return keyParam + ".ascx";
}
else
{
return DefaultControl;
}
}
/// <summary>
/// Loads the child control to be displayed in this container.
/// </summary>
/// <param name="controlToLoad">The control to load.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Catching Exception at highest level as a safeguard")]
private void LoadChildControl(string controlToLoad)
{
try
{
if (controlToLoad == null)
{
return;
}
ModuleBase currentControl = (ModuleBase)this.LoadControl(controlToLoad);
currentControl.ModuleConfiguration = this.ModuleConfiguration;
currentControl.ID = Path.GetFileNameWithoutExtension(controlToLoad);
this.ControlPlaceholder.Controls.Add(currentControl);
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
}
}