Skip to content

IAdmScheduledTask

The IAdmScheduledTask interface represents a Scheduled Task.

Inheritance: The IAdmScheduledTask interface inherits from the IAdmBusinessRule2 interface.

Methods

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.

[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
    }
}
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.

[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
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.

[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()
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

Executing Scheduled Tasks


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

See also