IAdmScheduledTask
The IAdmScheduledTask interface represents a scheduled task.
Inheritance: IAdmBusinessRule
Methods
-
Method
-
Description
-
GetActionLog()
-
Returns the Action Log of this scheduled task.
-
GetRecurrencePattern()
-
Returns the IAdmRecurrencePattern interface that represents the recurrence pattern, i.e. the execution schedule, of the scheduled task.
-
SetRecurrencePattern()
-
Sets the recurrence pattern, i.e. the execution schedule, for the scheduled task.
-
RunNow()
-
Initiates immediate asynchronous execution of the scheduled task regardless of the schedule.
-
Abort()
-
Aborts execution of the scheduled task.
Properties
-
Property
-
Description
-
TaskName
-
Gets the name of the scheduled task.
-
TaskID
-
Gets the globally unique identifier (GUID) of the scheduled task.
-
DeleteTaskAfterExecution
-
Gets or sets a value that indicates whether the scheduled task should be deleted after execution.
-
OwnerServiceDnsHostName
-
Gets or sets the DNS host name of the Adaxes service instance on which the scheduled task is executed.
-
IsOwnerServicePermanent
-
If the property is set to
true
, the scheduled task will always be run on the Adaxes service instance specified in theOwnerServiceDnsHostName
property and will never be reassigned to another instance. -
LastRunStartDateTime
-
Gets the date and time when execution of the scheduled task was last started.
-
LastRunFinishDateTime
-
Gets the date and time when the scheduled task was last completed.
Details
GetActionLog()
Returns the Action Log of this scheduled task. An Action Log of a scheduled task contains a list of records that describe the actions that were performed by the scheduled task. For more details, see Accessing log records.
IAdmActionLog GetActionLog()
Examples
The following code sample outputs all operations performed by a scheduled task.
- PowerShell
-
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") $taskName = "My Task" # Connect to the Adaxes service $ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $service = $ns.GetServiceDirectly("localhost") # Bind to the scheduled task $scheduledTasksPath = $service.Backend.GetConfigurationContainerPath( "ScheduledTasks") $scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" ` $scheduledTasksPath $myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( ` $taskName) $myScheduledTask = $service.OpenObject($myScheduledTaskAdsPath, $null, $null, 0) # Get action log $actionLog = $myScheduledTask.GetActionLog() $log = $actionLog.Log # Get all log records $pageCount = $log.PageCount for ($i = 0; $i -lt $pageCount; $i++) { # Get the current page of log records $logRecords = $log.GetPage($i) # Output information contained in each record foreach ($record in $logRecords) { Write-Host "Target object: " $record.TargetObjectName Write-Host "Target object type: " $record.TargetObjectType Write-Host "Description of operation: " $record.Description Write-Host "Start time: " $record.StartTime.DateTime Write-Host "Completion time: " $record.CompletionTime.DateTime Write-Host } }
- C#
-
using System; using Softerra.Adaxes.Adsi; using Softerra.Adaxes.Interop.Adsi.Logging; using Softerra.Adaxes.Interop.Adsi.PersistentObjects; using Softerra.Adaxes.Interop.Adsi.ScheduledTasks; class Program { static void Main(string[] args) { const string taskName = "My Task"; // Connect to the Adaxes service AdmNamespace ns = new AdmNamespace(); IAdmService service = ns.GetServiceDirectly("localhost"); // Bind to the scheduled task string scheduledTasksPath = service.Backend.GetConfigurationContainerPath( "ScheduledTasks"); AdsPath scheduledTasksPathObj = new AdsPath(scheduledTasksPath); AdsPath myScheduledTaskAdsPath = scheduledTasksPathObj.CreateChildPath("CN=" + taskName); IAdmScheduledTask myScheduledTask = (IAdmScheduledTask) service.OpenObject(myScheduledTaskAdsPath.ToString(), null, null, 0); // Get action log IAdmActionLog actionLog = myScheduledTask.GetActionLog(); IAdmLog log = actionLog.Log; // Get all log records int pageCount = log.PageCount; for (int i = 0; i < pageCount; i++) { // Get the current page of log records IAdmLogRecords logRecords = log.GetPage(i); // Output information contained in each record foreach (IAdmLogRecord record in logRecords) { IAdmLogRecord record2 = (IAdmLogRecord) record; Console.WriteLine("Target object: {0}", record2.TargetObjectName); Console.WriteLine("Target object type: {0}", record2.TargetObjectType); Console.WriteLine("Description of operation: {0}", record.Description); Console.WriteLine("Start time: {0}", record.StartTime); Console.WriteLine("Completion time: {0}", record.CompletionTime); Console.WriteLine(); } } } }
GetRecurrencePattern()
Returns the IAdmRecurrencePattern interface that represents the recurrence pattern, i.e. the execution schedule, of the scheduled task.
IAdmRecurrencePattern GetRecurrencePattern()
Examples
The following code sample outputs the date and time of the next scheduled execution of a scheduled task.
- PowerShell
-
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") $taskName = "My Task" # Connect to the Adaxes service $ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $service = $ns.GetServiceDirectly("localhost") # Bind to the scheduled task $scheduledTasksPath = $service.Backend.GetConfigurationContainerPath( "ScheduledTasks") $scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" ` $scheduledTasksPath $myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( ` "CN=$taskName") $myScheduledTask = $service.OpenObject($myScheduledTaskAdsPath, $null, $null, 0) # Get the recurrence pattern of the task $recurrencePattern = $myScheduledTask.GetRecurrencePattern() # Output the date and time of the next scheduled execution of the task $nextRunTime = $recurrencePattern.CalcNextRunTime($myScheduledTask.LastRunStartDateTime) Write-Host "The next run of the task is scheduled for " $nextRunTime.DateTime
- C#
-
using System; using Softerra.Adaxes.Adsi; using Softerra.Adaxes.Interop.Adsi.PersistentObjects; using Softerra.Adaxes.Interop.Adsi.ScheduledTasks; class Program { static void Main(string[] args) { const string taskName = "My Task"; // Connect to the Adaxes service AdmNamespace ns = new AdmNamespace(); IAdmService service = ns.GetServiceDirectly("localhost"); // Bind to the scheduled task string scheduledTasksPath = service.Backend.GetConfigurationContainerPath( "ScheduledTasks"); AdsPath scheduledTasksPathObj = new AdsPath(scheduledTasksPath); AdsPath myScheduledTaskAdsPath = scheduledTasksPathObj.CreateChildPath("CN=" + taskName); IAdmScheduledTask myScheduledTask = (IAdmScheduledTask) service.OpenObject(myScheduledTaskAdsPath.ToString(), null, null, 0); // Get the recurrence pattern of the task IAdmRecurrencePattern recurrencePattern = myScheduledTask.GetRecurrencePattern(); // Output the date and time of the next scheduled execution of the task DateTime nextRunTime = recurrencePattern.CalcNextRunTime(myScheduledTask.LastRunStartDateTime); Console.WriteLine("The next run of the task is scheduled for : {0}", nextRunTime); } }
SetRecurrencePattern()
Sets the recurrence pattern, i.e. the execution schedule, for the scheduled task.
void SetRecurrencePattern(IAdmRecurrencePattern recurrencePattern)
Remarks
This method does not persist the changes to the directory. Call IADs::SetInfo to update the recurrence pattern in the directory.
Examples
The following code sample configures a scheduled task to run every 12 hours.
- PowerShell
-
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") $taskName = "My Task" # Connect to the Adaxes service $ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $service = $ns.GetServiceDirectly("localhost") # Bind to the scheduled task $scheduledTasksPath = $service.Backend.GetConfigurationContainerPath( "ScheduledTasks") $scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" ` $scheduledTasksPath $myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( ` "CN=$taskName") $myScheduledTask = $service.OpenObject($myScheduledTaskAdsPath, $null, $null, 0) # Get the recurrence pattern of the task $recurrencePattern = $myScheduledTask.GetRecurrencePattern() # Change schedule - run every 12 hours $recurrencePattern.RecurrenceType = "ADM_RECURRENCEPATTERNTYPE_HOURLY" $recurrencePattern.Interval = 12 # Save changes $myScheduledTask.SetRecurrencePattern($recurrencePattern) $myScheduledTask.SetInfo()
- C#
-
using System; using Softerra.Adaxes.Adsi; using Softerra.Adaxes.Interop.Adsi.PersistentObjects; using Softerra.Adaxes.Interop.Adsi.ScheduledTasks; class Program { static void Main(string[] args) { const string taskName = "My Task"; // Connect to the Adaxes service AdmNamespace ns = new AdmNamespace(); IAdmService service = ns.GetServiceDirectly("localhost"); // Bind to the scheduled task string scheduledTasksPath = service.Backend.GetConfigurationContainerPath( "ScheduledTasks"); AdsPath scheduledTasksPathObj = new AdsPath(scheduledTasksPath); AdsPath myScheduledTaskAdsPath = scheduledTasksPathObj.CreateChildPath("CN=" + taskName); IAdmScheduledTask myScheduledTask = (IAdmScheduledTask) service.OpenObject(myScheduledTaskAdsPath.ToString(), null, null, 0); // Get the recurrence pattern of the task IAdmRecurrencePattern recurrencePattern = myScheduledTask.GetRecurrencePattern(); // Change schedule - run every 12 hours recurrencePattern.RecurrenceType = ADM_RECURRENCEPATTERNTYPE_ENUM.ADM_RECURRENCEPATTERNTYPE_HOURLY; recurrencePattern.Interval = 12; // Save changes myScheduledTask.SetRecurrencePattern(recurrencePattern); myScheduledTask.SetInfo(); } }
RunNow()
Initiates immediate asynchronous execution of the scheduled task regardless of the schedule.
void RunNow()
Examples
Abort()
Aborts execution of the scheduled task. If the scheduled task is not running at the moment, the method does nothing.
void Abort()
TaskName
Gets the name of the scheduled task.
- Type:
- string
- Access:
- Read-only
TaskID
Gets the globally unique identifier (GUID) of the scheduled task.
- Type:
- string
- Access:
- Read-only
DeleteTaskAfterExecution
Gets or sets a value that indicates whether the scheduled task should be deleted after execution.
- Type:
- bool
- Access:
- Read/Write
Remarks
This property takes effect only when the IAdmRecurrencePattern::RecurrenceType property of the task's recurrence pattern is set to ADM_RECURRENCEPATTERNTYPE_ONCE
.
OwnerServiceDnsHostName
Gets or sets the DNS host name of the Adaxes service instance on which the scheduled task is executed.
- Type:
- string
- Access:
- Read/Write
Remarks
If the property is set to null
, the Adaxes service instance will be selected automatically.
IsOwnerServicePermanent
If the property is set to true
, the scheduled task will always be run on the Adaxes service instance specified by the OwnerServiceDnsHostName
property and will never be reassigned to another instance.
- Type:
- bool
- Access:
- Read/Write
LastRunStartDateTime
Gets the date and time when execution of the scheduled task was last started.
- Type:
- DateTime
- Access:
- Read-only
Remarks
- If the scheduled task was never started, the property gets DateTime.MinValue.
- The property gets the date and time in the local time zone of the computer where Adaxes service is running.
LastRunFinishDateTime
Gets the date and time when the scheduled task was last completed.
- Type:
- DateTime
- Access:
- Read-only
Remarks
- If the scheduled task execution was started, but has not yet completed, the property gets DateTime.MinValue.
- The property gets the date and time in the local time zone of the computer where Adaxes service is running.
Requirements
Minimum required version: 2023