Scheduler library for DotNetNuke

Scheduler Library for DotNetNuke

How to develop a Scheduler library for DotNetNuke

1. Create a Visual Basic Class Library project, in project Properties, go to Application tab, and specify the Assembly Name (e.g. NWDS.TestScheduler) (we'll need this later), leave Root Namespace blank.

2. Add the following references:

  • Dotnetnuke.dll
  • Dotnetnuke.SqlDataProvider.dll
  • Microsoft.ApplicationBlocks.Data.dll

3. Delete all the default files from the project

4. Create "Components" folder

5. Go to any of your module folders in App_Code, and copy DataProvider, SqlDataProvider, and Controller classes -- paste those into the "Components" folder from Step 4. Modify methods as necessary. Do not catch any exceptions in your Controller class, let them bubble up to your Scheduler class, and log them there - this will make Debugging a lot easier.

6. Create your business object (if you need one)

7. Add Scheduler class, that inherits from

DotNetNuke.Services.Scheduling. SchedulerClient 

Imports System

Imports System.IO

Imports DotNetNuke

Imports DotNetNuke.Services.Exceptions 

Namespace NWDS.TestScheduler

Public Class Scheduler

        Inherits DotNetNuke.Services.Scheduling.SchedulerClient

        Public Sub New(ByVal objScheduleHistoryItem As DotNetNuke.Services.Scheduling.ScheduleHistoryItem)

            MyBase.new()

            Me.ScheduleHistoryItem = objScheduleHistoryItem

        End Sub

        Public Sub New() 

        End Sub

        Public Overrides Sub DoWork()

            Try

                Me.Progressing()

                Me.ScheduleHistoryItem.Succeeded = True 

                'do work here 

                If SUCCESS Then 

                    Me.ScheduleHistoryItem.AddLogNote("It worked") 

                Else 

                    Me.ScheduleHistoryItem.AddLogNote("Didn't work") 

                End If 

            Catch exc As Exception

                Me.ScheduleHistoryItem.Succeeded = False

                Me.ScheduleHistoryItem.AddLogNote("EXCEPTION: " + exc.ToString)

                Me.Errored(exc)

                LogException(exc)

            End Try 

        End Sub 

    End Class

End Namespace 

8. Build the project, and move .dll file to the /bin folder of your DotNetNuke install

9. Login as Host into your DNN, and go to Host > Schedule

10. In "Add Item to Schedule" form, the most important field is "Full Class Name and Assembly", if your scheduler doesn't run -- chances are you've made a mistake here.

Full Class Name -- name of your Scheduler class (including Namespace), in this example that would be NWDS.TestScheduler.Scheduler

Assembly -- name of the assembly from Step 1, in this example that would be NWDS.TestScheduler

Here's how your Full Class Name and Assembly field should look like:

NWDS.TestScheduler.Scheduler, NWDS.TestScheduler

The rest is easy, enable the schedule by checking the "YES" box, specify the frequency (Time Lapse) (I set this to 1 minute when I test), set "Retain Schedule History" to 10 (for debugging), and click UPDATE.

Check schedule history to see if your scheduler works -- if the history is empty, check Step 10 :)

Hope this helps.