Skip to content

Commit

Permalink
Add support for Evoq 8
Browse files Browse the repository at this point in the history
The APIs for the HTML Pro module changed in Evoq 8, this reflects this changes
Fixes EngageSoftware#10
  • Loading branch information
bdukes committed Sep 17, 2015
1 parent 801e34e commit 3074b82
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 30 deletions.
82 changes: 72 additions & 10 deletions HtmlTextModuleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Engage.Dnn.F3
using System;
using System.Collections.Generic;
using System.Reflection;

using DotNetNuke.Entities.Modules;
using DotNetNuke.Framework;

/// <summary>
Expand Down Expand Up @@ -57,7 +59,7 @@ public HtmlTextModuleController()
this.workflowStateController = Reflection.CreateInstance(WorkflowStateControllerType);
}

public int GetWorkflowId(int moduleId, int tabId, int portalId)
private int? GetWorkflowId(int moduleId, int tabId, int portalId)
{
var getWorkflowId = HtmlTextControllerType.GetMethod("GetWorkflowID");
if (getWorkflowId != null)
Expand All @@ -72,25 +74,85 @@ public int GetWorkflowId(int moduleId, int tabId, int portalId)
}

// DNN 5.4
var workflowPair = (KeyValuePair<string, int>)HtmlTextControllerType.InvokeMember(
"GetWorkflow",
var getWorkflow = HtmlTextControllerType.GetMethod("GetWorkflow");
if (getWorkflow != null)
{
var workflowPair = (KeyValuePair<string, int>)HtmlTextControllerType.InvokeMember(
"GetWorkflow",
BindingFlags.InvokeMethod,
null,
this.htmlTextController,
new object[] { moduleId, tabId, portalId },
null);

return workflowPair.Value;
}

return null;
}

public IHtmlTextInfo GetTopHtmlText(int moduleId, int tabId, int portalId)
{
var workflowId = this.GetWorkflowId(moduleId, tabId, portalId);
if (workflowId != null)
{
return
new HtmlTextInfo(
HtmlTextControllerType.InvokeMember(
"GetTopHtmlText",
BindingFlags.InvokeMethod,
null,
this.htmlTextController,
new object[] { moduleId, false, workflowId.Value },
null));
}

var serviceLocatorType = Reflection.CreateType("DotNetNuke.Framework.ServiceLocator`2");
var versionControllerInterface = Reflection.CreateType("DotNetNuke.Professional.HtmlPro.Components.IVersionController");
var versionControllerClass = Reflection.CreateType("DotNetNuke.Professional.HtmlPro.Components.VersionController");
var versionControllerLocatorType = serviceLocatorType.MakeGenericType(versionControllerInterface, versionControllerClass);
var versionControllerInstance = versionControllerLocatorType.InvokeMember(
"Instance",
BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty,
null,
null,
new object[0],
null);

var htmlInfo = versionControllerInterface.InvokeMember(
"GetLatestVersion",
BindingFlags.InvokeMethod,
null,
this.htmlTextController,
new object[] { moduleId, tabId, portalId },
versionControllerInstance,
new object[] { moduleId },
null);

return workflowPair.Value;
return htmlInfo == null ? null : new HtmlTextInfo(htmlInfo);
}

public IHtmlTextInfo GetTopHtmlText(int moduleId, bool isPublished, int workflowId)
public IHtmlTextInfo CreateNewHtmlTextInfo()
{
return new HtmlTextInfo(HtmlTextControllerType.InvokeMember("GetTopHtmlText", BindingFlags.InvokeMethod, null, this.htmlTextController, new object[] { moduleId, isPublished, workflowId }, null));
return new HtmlTextInfo();
}

public IHtmlTextInfo CreateNewHtmlTextInfo()
public void SaveHtmlContent(IHtmlTextInfo htmlTextInfo, int moduleId, int tabId, int portalId)
{
return new HtmlTextInfo();
if (htmlTextInfo == null)
{
throw new ArgumentNullException("htmlTextInfo");
}

var workflowId = this.GetWorkflowId(moduleId, tabId, portalId);
if (workflowId != null)
{
htmlTextInfo.WorkflowId = workflowId.Value;
htmlTextInfo.StateId = this.GetFirstWorkflowStateId(workflowId.Value);
this.UpdateHtmlText(htmlTextInfo, this.GetMaximumVersionHistory(portalId));
return;
}

var module = new ModuleController().GetModule(moduleId, tabId, true);
Reflection.InvokeMethod(HtmlTextControllerType, "SaveHtmlContent", this.htmlTextController, new object[] { htmlTextInfo.HtmlTextInfoInstance, module, });
}

public void UpdateHtmlText(IHtmlTextInfo htmlTextInfo, int maximumVersionHistory)
Expand Down
10 changes: 2 additions & 8 deletions IHtmlTextModuleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ namespace Engage.Dnn.F3
/// </summary>
public interface IHtmlTextModuleController
{
int GetWorkflowId(int moduleId, int tabId, int portalId);

IHtmlTextInfo GetTopHtmlText(int moduleId, bool isPublished, int workflowId);
IHtmlTextInfo GetTopHtmlText(int moduleId, int tabId, int portalId);

IHtmlTextInfo CreateNewHtmlTextInfo();

int GetFirstWorkflowStateId(int workflowId);

void UpdateHtmlText(IHtmlTextInfo htmlTextInfo, int maximumVersionHistory);

int GetMaximumVersionHistory(int portalId);
void SaveHtmlContent(IHtmlTextInfo htmlTextInfo, int moduleId, int tabId, int portalId);
}
}
14 changes: 2 additions & 12 deletions ViewLinks.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,10 @@ protected override void OnInit(EventArgs e)
private static void CreateNewTextHtmlVersion(string searchValue, string replacementValue, int moduleId, int tabId, int portalId, string content)
{
var htmlTextController = CreateHtmlTextController();
var workflowId = htmlTextController.GetWorkflowId(moduleId, tabId, portalId);
var htmlInfo = htmlTextController.GetTopHtmlText(moduleId, false, workflowId) ?? htmlTextController.CreateNewHtmlTextInfo();
var htmlInfo = htmlTextController.GetTopHtmlText(moduleId, tabId, portalId) ?? htmlTextController.CreateNewHtmlTextInfo();
htmlInfo.ModuleId = moduleId;
htmlInfo.Content = content.Replace(HttpUtility.HtmlEncode(searchValue), HttpUtility.HtmlEncode(replacementValue));
htmlInfo.WorkflowId = workflowId;
htmlInfo.StateId = htmlTextController.GetFirstWorkflowStateId(workflowId);

// TODO: allow direct publish
////if (canDirectlyPublish)
////{
//// htmlInfo.StateID = workflowStateController.GetNextWorkflowStateID(workflowId, htmlInfo.StateID);
////}

htmlTextController.UpdateHtmlText(htmlInfo, htmlTextController.GetMaximumVersionHistory(portalId));
htmlTextController.SaveHtmlContent(htmlInfo, moduleId, tabId, portalId);
}

/// <summary>
Expand Down

0 comments on commit 3074b82

Please sign in to comment.