Select the search type
  • Site
  • Web
Search
You are here:  Company/News

Blog2mind

Proposal for new IEventEnabled interface in DNN

Summary

Module developers sometimes have the need to be able to detect important events that occur in the DNN Core. Until now the only way is to try and detect changes during code execution, but typically code execution happens during a page hit, so this would impede performance. The proposal outlines a way for the core to call modules’ business controllers to notify them of particular events.

ICoreEvent

I’ve dubbed the interface IEventEnabled. It would follow implementation similar to other ‘supported features’ for modules such as ISearchable, IPortable, and IUpgradeable. Central in the interface is a method (CoreEvent) that takes as parameters:

  1. EventType. An enumeration of a set of event types such as PortalCreated, PageDeleted, etc.
  2. obj As Object. The object in question. This can be used by the module to retrieve a PortalInfo object for instance.
  3. Parameters() As String. A parameter array of anything that might still come in handy.

Implementation

IEventEnabled.vb

 

Namespace DotNetNuke.Entities.Modules

 Public Interface IEventEnabled

  Sub CoreEvent(ByVal EventType As CoreEventTypes, ByVal obj As Object, ByVal ParamArray Parameters As String())

 End Interface

 

 Public Enum CoreEventTypes

  PortalCreated

  PortalDeleted

  PageCreated

  PageDeleted

  ModuleInstantiated

  ModuleRemoved

  UserAdded

  UserDeleted

  RoleAdded

  RoleDeleted

 End Enum

End Namespace

 

CoreEvents.vb

 

Imports DotNetNuke.Entities.Modules

 

Namespace DotNetNuke.Services.Events

 Public Class CoreEvents

 

  Public Shared Sub CallEvents(ByVal EventType As CoreEventTypes, ByVal obj As Object, ByVal ParamArray Parameters As String())

   Dim objModCtrl As New DesktopModuleController, objModule As DesktopModuleInfo

   For Each objModule In objModCtrl.GetDesktopModules

    If (objModule.SupportedFeatures And DesktopModuleSupportedFeature.IsEventEnabled) = DesktopModuleSupportedFeature.IsEventEnabled Then

     Try

      Dim objController As IEventEnabled = CType(Framework.Reflection.CreateObject(objModule.BusinessControllerClass, objModule.BusinessControllerClass), IEventEnabled)

      objController.CoreEvent(EventType, obj, Parameters)

     Catch ex As Exception

      LogException(ex)

     End Try

    End If

   Next

  End Sub

 

 End Class

End Namespace

 

DesktopModuleInfo addition

 

Public Enum DesktopModuleSupportedFeature

  IsPortable = 1

  IsSearchable = 2

  IsEventEnabled = 4

 End Enum

 

Use in Controllers

e.g. PortalController.CreatePortal

     ' clear roles cache

     DataCache.RemoveCache("GetRoles")

 

     'Create Portal Alias

     AddPortalAlias(intPortalId, PortalAlias)

 

     DotNetNuke.Services.Events.CoreEvents.CallEvents(CoreEventTypes.PortalCreated, objportal)

 

    Else    ' clean up

     DeletePortalInfo(intPortalId)

     intPortalId = -1

    End If

 

And in PortalController.DeletePortal

   'delete portal users

   Dim objUsers As New UserController

   objUsers.DeleteAllUsers(PortalId)

 

   'delete portal

   DataProvider.Instance().DeletePortalInfo(PortalId)

 

   DotNetNuke.Services.Events.CoreEvents.CallEvents(CoreEventTypes.PortalDeleted, PortalId)

 

   ' clear portal alias cache and entire portal

   DataCache.ClearHostCache(True)

Archive