-
Notifications
You must be signed in to change notification settings - Fork 2
/
HtmlTextModuleController.cs
116 lines (101 loc) · 5.37 KB
/
HtmlTextModuleController.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
// <copyright file="HtmlTextModuleController.cs" company="Engage Software">
// Engage: F3
// Copyright (c) 2004-2013
// 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.F3
{
using System;
using System.Collections.Generic;
using System.Reflection;
using DotNetNuke.Framework;
/// <summary>
/// Implements <see cref="IHtmlTextModuleController"/> by wrapping a <see cref="DotNetNuke.Modules.Html.HtmlTextController"/> instance created via reflection
/// </summary>
/// <remarks>Need to use reflection because type could be in <c>DotNetNuke.Modules.Html</c> assembly or in <c>DotNetNuke.Professional.HtmlPro</c> assembly.</remarks>
public class HtmlTextModuleController : IHtmlTextModuleController
{
/// <summary>
/// The type of the <c>HtmlTextController</c> that the module is using (CE or PE)
/// </summary>
private static readonly Type HtmlTextControllerType =
Reflection.CreateType("DotNetNuke.Professional.HtmlPro.HtmlTextController") // DNN 7.0 Professional
?? Reflection.CreateType("DotNetNuke.Modules.HtmlPro.HtmlTextController") // DNN 5.6 Professional
?? Reflection.CreateType("DotNetNuke.Modules.Html.HtmlTextController");
/// <summary>
/// The type of the <c>WorkflowStateController</c> that the module is using (CE or PE)
/// </summary>
private static readonly Type WorkflowStateControllerType =
Reflection.CreateType("DotNetNuke.Professional.HtmlPro.Components.WorkflowStateController") // DNN 5.6 Professional
?? Reflection.CreateType("DotNetNuke.Modules.HtmlPro.WorkflowStateController") // DNN 5.6 Professional
?? Reflection.CreateType("DotNetNuke.Modules.Html.WorkflowStateController");
/// <summary>
/// An <c>HtmlTextController</c> instance, of the <see cref="HtmlTextControllerType"/>
/// </summary>
private readonly object htmlTextController;
/// <summary>
/// A <c>WorkflowStateController</c> instance, of the <see cref="WorkflowStateControllerType"/>
/// </summary>
private readonly object workflowStateController;
/// <summary>
/// Initializes a new instance of the <see cref="HtmlTextModuleController"/> class.
/// </summary>
public HtmlTextModuleController()
{
this.htmlTextController = Reflection.CreateInstance(HtmlTextControllerType);
this.workflowStateController = Reflection.CreateInstance(WorkflowStateControllerType);
}
public int GetWorkflowId(int moduleId, int tabId, int portalId)
{
var getWorkflowId = HtmlTextControllerType.GetMethod("GetWorkflowID");
if (getWorkflowId != null)
{
// DNN 5.2
return (int)getWorkflowId.Invoke(
this.htmlTextController,
BindingFlags.InvokeMethod,
null,
new object[] { moduleId, portalId },
null);
}
// DNN 5.4
var workflowPair = (KeyValuePair<string, int>)HtmlTextControllerType.InvokeMember(
"GetWorkflow",
BindingFlags.InvokeMethod,
null,
this.htmlTextController,
new object[] { moduleId, tabId, portalId },
null);
return workflowPair.Value;
}
public IHtmlTextInfo GetTopHtmlText(int moduleId, bool isPublished, int workflowId)
{
return new HtmlTextInfo(HtmlTextControllerType.InvokeMember("GetTopHtmlText", BindingFlags.InvokeMethod, null, this.htmlTextController, new object[] { moduleId, isPublished, workflowId }, null));
}
public IHtmlTextInfo CreateNewHtmlTextInfo()
{
return new HtmlTextInfo();
}
public void UpdateHtmlText(IHtmlTextInfo htmlTextInfo, int maximumVersionHistory)
{
if (htmlTextInfo == null)
{
throw new ArgumentNullException("htmlTextInfo");
}
Reflection.InvokeMethod(HtmlTextControllerType, "UpdateHtmlText", this.htmlTextController, new object[] { htmlTextInfo.HtmlTextInfoInstance, maximumVersionHistory });
}
public int GetFirstWorkflowStateId(int workflowId)
{
return (int)WorkflowStateControllerType.InvokeMember("GetFirstWorkflowStateID", BindingFlags.InvokeMethod, null, this.workflowStateController, new object[] { workflowId }, null);
}
public int GetMaximumVersionHistory(int portalId)
{
return (int)HtmlTextControllerType.InvokeMember("GetMaximumVersionHistory", BindingFlags.InvokeMethod, null, this.htmlTextController, new object[] { portalId }, null);
}
}
}