-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMainContainer.ascx.cs
141 lines (126 loc) · 5.99 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// <copyright file="MainContainer.ascx.cs" company="Engage Software">
// Engage: Events - http://www.EngageSoftware.com
// Copyright (c) 2004-2011
// 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.Events
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using Engage.Dnn.Framework;
/// <summary>
/// The main container that is used by the Engage: Events module.
/// This control is registered with DNN, and is in charge of loading other requested control.
/// </summary>
public partial class MainContainer : ModuleBase
{
/// <summary>
/// The control key for the <see cref="DefaultSubControl"/>
/// </summary>
protected internal const string DefaultControlKey = "EventListing";
/// <summary>
/// The default sub-control to load when no control key is provided
/// </summary>
private static readonly SubControlInfo DefaultSubControl = new SubControlInfo("Display/EventDisplay.ascx", false);
/// <summary>
/// The sub-control to load when there is an error with the license
/// </summary>
private static readonly SubControlInfo LicenseErrorControl = new SubControlInfo("Admin/LicenseError.ascx", false);
/// <summary>
/// A dictionary mapping control keys to user controls.
/// </summary>
private static readonly IDictionary<string, SubControlInfo> ControlKeys = FillControlKeys();
/// <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)
{
SubControlInfo controlToLoad;
try
{
base.OnInit(e);
controlToLoad = this.GetControlToLoad();
}
catch (LicenseException)
{
controlToLoad = LicenseErrorControl;
}
if (!controlToLoad.RequiresEditPermission || PortalSecurity.HasNecessaryPermission(SecurityAccessLevel.Edit, this.PortalSettings, this.ModuleConfiguration, this.UserInfo.Username))
{
this.LoadChildControl(controlToLoad);
}
else
{
this.DenyAccess();
}
}
/// <summary>
/// Fills <see cref="ControlKeys"/>.
/// </summary>
/// <returns>A dictionary mapping control keys to user controls.</returns>
private static IDictionary<string, SubControlInfo> FillControlKeys()
{
return new Dictionary<string, SubControlInfo>(11, StringComparer.OrdinalIgnoreCase)
{
{ "EventEdit", new SubControlInfo("EventEdit.ascx", false) },
{ DefaultControlKey, DefaultSubControl },
{ "EventListingAdmin", new SubControlInfo("Display/EventListingItem.ascx", false) },
{ "ResponseSummary", new SubControlInfo("ResponseSummaryDisplay.ascx", false) },
{ "ResponseDetail", new SubControlInfo("ResponseDetail.ascx", false) },
{ "Response", new SubControlInfo("Respond.ascx", false) },
{ "EmailAFriend", new SubControlInfo("EmailAFriend.ascx", false) },
{ "Register", new SubControlInfo("Register.ascx", false) },
{ "EventDetail", new SubControlInfo("Display/EventDetail.ascx", false) },
{ "ChooseDisplay", new SubControlInfo("ChooseDisplay.ascx", false) },
{ "ManageCategories", new SubControlInfo("ManageCategories.ascx", false) }
};
}
/// <summary>
/// Gets the control to load, based on the key (or lack thereof) that is passed on the query-string.
/// </summary>
/// <returns>A relative path to the control that should be loaded into this container</returns>
private SubControlInfo GetControlToLoad()
{
if (!this.IsConfigured)
{
return new SubControlInfo("Admin/NotConfigured.ascx", false);
}
var keyParam = this.GetCurrentControlKey();
SubControlInfo control;
if (Engage.Utility.HasValue(keyParam) && ControlKeys.TryGetValue(keyParam, out control))
{
return control;
}
return DefaultSubControl;
}
/// <summary>
/// Loads the child control to be displayed in this container.
/// </summary>
/// <param name="controlToLoad">The control to load.</param>
private void LoadChildControl(SubControlInfo controlToLoad)
{
try
{
PortalModuleBase mb = (PortalModuleBase)this.LoadControl(controlToLoad.ControlPath);
mb.ModuleConfiguration = this.ModuleConfiguration;
mb.ID = Path.GetFileNameWithoutExtension(controlToLoad.ControlPath);
this.ControlsPlaceholder.Controls.Add(mb);
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
}
}