Developer forum

Forum » Development » Performing a save on a scheduled task add-in

Performing a save on a scheduled task add-in

Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Hello,

I would like to make a property change at runtime in a method that is inheriting from BatchIntegrationScheduledTaskAddin. The goal is to sometimes reset one of the persisted settings.

It appears that I need to get a handle on the current Dynamicweb.Scheduling.Task to be able to do a Save(). What's the best way to do that?

Thanks,

Scott


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Scott,
here is an example of how that could be done usning VB.NET:
If Not String.IsNullOrEmpty(currentTask.Assembly) Then
                Dim t As Type = AddInManager.GetAddInTypeByName(currentTask.Assembly)
                If Not IsNothing(t) AndAlso t.IsSubclassOf(GetType(Dynamicweb.DataIntegration.BatchIntegrationScheduledTaskAddin)) Then
                    Dim addInInstance As DataIntegration.BatchIntegrationScheduledTaskAddin = CType(AddInManager.CreateAddInInstance(t), DataIntegration.BatchIntegrationScheduledTaskAddin)
                    addInInstance.LoadParametersFromXml(currentTask.AddInSettings)
                    addInInstance.NotificationEmail = "test@test.com" 'change some property
                    currentTask.AddInSettings = addInInstance.GetParametersToXml()
                    currentTask.Save()
                End If
            End If
Hope this will help.
Kind regards, Dmitrij

 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Thanks Dmitriy. That looks promising. How do I get a handle on the currentTask from a class that is implementing BatchIntegrationScheduledTaskAddin? 

Thanks,

Scott

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Scott,
you need to have the task id to get the task instance:
currentTask = New Task(taskId)
Or if you already have the task object of type BatchIntegrationScheduledTaskAddin then there is a property ScheduledTaskName which can be then used to find the task by calling Task.GetTaskByName:
currentTask = Task.GetTaskByName(yourTaskObject.ScheduledTaskName)
Kind regards, Dmitrij

 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Hi Dmitriy,

Perfect, that's the direction that I needed. Thanks!

Scott

 

You must be logged in to post in the forum