IAdmScheduledTask
The IAdmScheduledTask interface represents a scheduled task.
Inheritance: IAdmBusinessRule2
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.
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.
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 $admNS = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $admService = $admNS.GetServiceDirectly("localhost") # Bind to the scheduled task $scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath( "ScheduledTasks") $scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" ` $scheduledTasksPath $myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( ` $taskName) $myScheduledTask = $admService.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 adsNS = new AdmNamespace(); IAdmService admService = adsNS.GetServiceDirectly("localhost"); // Bind to the scheduled task string scheduledTasksPath = admService.Backend.GetConfigurationContainerPath( "ScheduledTasks"); AdsPath scheduledTasksPathObj = new AdsPath(scheduledTasksPath); AdsPath myScheduledTaskAdsPath = scheduledTasksPathObj.CreateChildPath("CN=" + taskName); IAdmScheduledTask myScheduledTask = (IAdmScheduledTask) admService.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) { IAdmLogRecord2 record2 = (IAdmLogRecord2) 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 $admNS = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $admService = $admNS.GetServiceDirectly("localhost") # Bind to the scheduled task $scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath( "ScheduledTasks") $scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" ` $scheduledTasksPath $myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( ` "CN=$taskName") $myScheduledTask = $admService.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 adsNS = new AdmNamespace(); IAdmService admService = adsNS.GetServiceDirectly("localhost"); // Bind to the scheduled task string scheduledTasksPath = admService.Backend.GetConfigurationContainerPath( "ScheduledTasks"); AdsPath scheduledTasksPathObj = new AdsPath(scheduledTasksPath); AdsPath myScheduledTaskAdsPath = scheduledTasksPathObj.CreateChildPath("CN=" + taskName); IAdmScheduledTask2 myScheduledTask = (IAdmScheduledTask2) admService.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 $admNS = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $admService = $admNS.GetServiceDirectly("localhost") # Bind to the scheduled task $scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath( "ScheduledTasks") $scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" ` $scheduledTasksPath $myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath( ` "CN=$taskName") $myScheduledTask = $admService.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 adsNS = new AdmNamespace(); IAdmService admService = adsNS.GetServiceDirectly("localhost"); // Bind to the scheduled task string scheduledTasksPath = admService.Backend.GetConfigurationContainerPath( "ScheduledTasks"); AdsPath scheduledTasksPathObj = new AdsPath(scheduledTasksPath); AdsPath myScheduledTaskAdsPath = scheduledTasksPathObj.CreateChildPath("CN=" + taskName); IAdmScheduledTask2 myScheduledTask = (IAdmScheduledTask2) admService.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
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:
- Boolean
- 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.
Requirements
Minimum required version: 2011.2