How to Manage Staging Schedules

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

The CReplicationSchedule object provides the functionality to manage staging schedules. This functionality works with the Windows Task Scheduler to create a scheduled task.

Note

You must have Commerce Server Staging (CSS) administrator rights to add schedules to a staging project. Also, you must be a member of the Administrators, Backup Operators, or Server Operators group on the local server to create a schedule. For more information about how to use the Windows Task Scheduler and security, see the Task Scheduler help.

To define a schedule and add it to a project

  1. Create a CReplicationServer object.

  2. Initialize the server object on the specified server by using the CReplicationServer.Initialize method.

    • For a replication schedule, initialize the source staging server.

    • For an apply time schedule, initialize the destination server where the timed release of content should occur.

  3. Call the CReplicationServer.OpenProject method, specifying the OPEN_EXISTING_PROJECT flag and the name of an existing project.

  4. Call the CReplicationProject.AddSchedule method to add a schedule to the opened project.

  5. Set the schedule properties:

    • For a nonrecurring schedule, set the time and date in the RunOnce property.

    • For a recurring schedule, set the Days, Hour, and Minute properties.

    • (Optional) Define the schedule action by setting the ScheduledAction property. The default schedule action is to replicate the content (CSS_SCHEDULE_REPLICATE). If you want to set an apply schedule, set this property to CSS_SCHEDULE_APPLY.

  6. Call the CReplicationSchedule.Commit method to commit the changes that you made to the schedule

To remove a schedule from a project

  1. Create a CReplicationServer object.

  2. Initialize the server object on the specified server by using the CReplicationServer.Initialize method.

  3. Call the CReplicationServer.OpenProject method, specifying the OPEN_EXISTING_PROJECT flag and the name of the project whose schedule you want to delete.

  4. Iterate on the set of schedules that are defined for the project by calling the CReplicationProject.EnumSchedules method.

  5. Identify the schedule to be removed by checking a property of a retrieved schedule. The following properties can be checked:

  6. Remove the schedule that matches the property criteria by calling the CReplicationSchedule.Remove method.

Example

The following example adds a recurring replication schedule for MyProject on the local host that runs each Monday, Wednesday, and Friday at 11:30 PM.

const int Monday = 0x1;
const int Tuesday = 0x2;
const int Wednesday = 0x4;
const int Thursday = 0x8;
const int Friday = 0x10;
const int Saturday = 0x20;
const int Sunday = 0x40;
const int Daily = 0xFF;
CReplicationServer replicationServer = new CReplicationServer();
replicationServer.Initialize("");
CReplicationProject replicationProject = (CReplicationProject)replicationServer.OpenProject("MyProject", CSS_PROJECT_CREATION.OPEN_EXISTING_PROJECT);
CReplicationSchedule replicationSchedule = (CReplicationSchedule)replicationProject.AddSchedule();
replicationSchedule.set_Days(Monday | Wednesday | Friday);
replicationSchedule.set_Hour(23);
replicationSchedule.set_Minute(30);
replicationSchedule.set_ScheduledAction(CSS_SCHEDULE_ACTION.CSS_SCHEDULE_REPLICATE);
replicationSchedule.Commit();

The following example removes all instances of nonrecurring schedules for MyProject on the local host.

CReplicationServer replicationServer = new CReplicationServer();
replicationServer.Initialize("");
CReplicationProject replicationProject = (CReplicationProject)replicationServer.OpenProject("MyProject", CSS_PROJECT_CREATION.OPEN_EXISTING_PROJECT);
CReplicationSchedule replicationSchedule;
int iterator = 0;
object i = iterator as object;
while (true)
{
    try
    {
        replicationSchedule = (CReplicationSchedule)replicationProject.EnumSchedules(ref i);
    // If the Schedule is set to run one time, remove the schedule
    if ((bool)replicationSchedule.IsRunOnce)
      {
      replicationSchedule.Remove();
      break;
      }
    }
    catch (System.Runtime.InteropServices.COMException e)
    {
        // Quit if "No more items" error
        if (e.ErrorCode == -2147422485)
             break;
        else
             throw e;
    }
}

See Also

Other Resources

Projects

Schedules

What are the Staging API Concepts?

What are the Staging Project Options?

CReplicationProject Class

CReplicationSchedule Class

CReplicationServer Class

Managing Projects and Routes by using the Staging API