Creating the task

To create a task, perform the following:

  1. Open Sitefinity Project Manager.

  2. Select your Sitefinity project.

  3. Click Edit in Visual Studio.

  4. From the context menu of the project, click Add » New Item...

  5. In the left pane, select Visual C# » Code.

  6. Click Class.

  7. In the Name input field, enter PipeScheduledTask.cs.

  8. Open the newly created file.

  9. Include the following namespaces:

    using Telerik.Sitefinity.Publishing;
    using Telerik.Sitefinity.Scheduling;

  10. Inherit the class from the Telerik.Sitefinity.Scheduling.ScheduledTask class:

    public class PipeScheduledTask : ScheduledTask
    {
    }

  11. Add the following methods:

    public override void ExecuteTask()
    {
        PublishingManager pubManager = PublishingManager.GetManager();
        var point = pubManager.GetPublishingPoints().Where((w) => w.Name == "Competitors Newsletters").FirstOrDefault();
        if (point != null)
        {
            PublishingManager.InvokeInboundPushPipes(point.Id, null);
        }
     
        SchedulingManager schedulingManager = SchedulingManager.GetManager();
     
        PipeScheduledTask newTask = new PipeScheduledTask()
        {
            Key = this.Key,
            ExecuteTime = DateTime.UtcNow.AddHours(1)
        };
     
        schedulingManager.AddTask(newTask);
        schedulingManager.SaveChanges();
    }
     
    public override string TaskName
    {
        get
        {
            return "SitefinityWebApp.PipeScheduledTask";
        }
    }

In the ExecuteTask method you get the feed from the publishing system and execute it. You must also set the TaskName to reflect the full class name so that the system can properly instantiate the task from the factory and execute it at a specified point. Once the task is executed you must invoke the scheduling manager and queue a new task of the same type.

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK