• Decrease Text SizeIncrease Text Size

Setup Custom Scheduled Task * Updated

Posted Date: 5/8/2023
    Printer Friendly Version   Email A Friend   Add This   Increase Text Size   Decrease Text Size
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.', 
	'<cpCollection>
		  <group id="General" name="General">
				<property id="WebSiteId">
					  <value></value>
					  <attribute name="Web Site">
							<control type="Centralpoint.Web.UI.Controls.CpListBox">
								  <controlProperty name="TableName" value="cpsys_WebSites" />
								  <controlProperty name="TextField" value="dbo.cpsys_WebSites.[Name] + '' ('' + dbo.cpsys_WebSites.Path + dbo.cpsys_WebSites.SystemName + '')''" />
								  <controlProperty name="ValueField" value="dbo.cpsys_WebSites.WebSiteId" />
								  <controlProperty name="PrefixFields" value="false" />
							</control>
							<validator id="CpRequiredFieldValidator" type="Centralpoint.Web.UI.Controls.CpRequiredFieldValidator" />
					  </attribute>
				</property>
		  </group>
	</cpCollection>', NULL, 1, GETDATE(), NULL)





Keywords: Scheduled, master console, Scheduled task



Related CodeSamples Records
Related Taxonomy

Comments:

Be the first to leave a comment.
Please Login to post comments.