You can set up a custom Scheduled Task by downloading this template file Custom_Template_ScheduledTask.cs and moving it into the Master /Root/App_Code/Custom directory.
The attribute name [ScheduledTask("MyTaskSystemName")] should match the system name of the Scheduled Task.
You would not need to register this task in ExecuteMyTask method like in implementation
using Centralpoint.Web;
using System;
using System.Web;
namespace Centralpoint.Master.Custom
{
public class MyTemplateTask
{
[ScheduledTask("MyTaskSystemName")]
public static void MyTaskSystemName(Guid scheduledTaskId, string name, CpCollection collection)
{
HttpContext.Current.Trace.Write("MyTaskSystemName", $"{name}");
TemplateScheduledTask templateScheduledTask = new TemplateScheduledTask(collection, scheduledTaskId, Guid.NewGuid());
templateScheduledTask.Execute();
}
}
public class TemplateScheduledTask
{
private CpCollection Properties { get; set; }
private Guid ScheduledTaskId { get; set; }
private string ScheduledTaskName { get; set; }
private Guid ProcessGuid { get; set; }
private Process Process { get; set; }
private Centralpoint.Master.Common.WebSite WebSite { get; set; }
private string ReadConnectionString { get; set; }
private string ExecuteConnectionString { get; set; }
public TemplateScheduledTask(CpCollection properties, Guid scheduledTaskId, Guid processGuid)
{
this.Properties = properties;
this.ScheduledTaskId = scheduledTaskId;
this.ProcessGuid = processGuid;
WebSite = Common.WebSite.NewCached(new Guid(Properties.Get("WebSiteId")));
}
public void Execute()
{
Process process = Centralpoint.Web.ProcessMonitor.StartProcess(Guid.NewGuid(),
ProcessTypes.ScheduledTask, "Starting Template Scheduled Task");
try
{
ReadConnectionString = WebSite.SelectConnectionString;
ExecuteConnectionString = WebSite.ExecuteConnectionString;
process.Status = $"Execute TemplateScheduledTask";
Centralpoint.Web.ProcessMonitor.StopProcess(process, $"Template Scheduled Task completed.");
}
catch (Exception ex)
{
process.Status = ex.Message;
process.Status = ex.StackTrace;
Centralpoint.Web.ProcessMonitor.StopProcess(process, "Template Scheduled Task Failed.");
Management.Error(ex, false);
}
}
}
}
Then create custom Scheduled Task properties. downloading this template Create_Scheduled_Template_Job.sql
INSERT INTO cpsys_Jobs (JobId, SystemName, Name, Description, Properties, Roles, IsEnabled, CreateDate, ModifyDate)
VALUES (NEWID(), 'MyTaskSystemName', 'Template Scheduled Task', 'This application will execute Template Scheduled Task.',
'
', NULL, 1, GETDATE(), NULL)
Keywords: Scheduled, master console, Scheduled task
Related CodeSamples Records