Running the Process or Operation

Service operation classes contain methods that you can call to run operations. These methods accept a service argument class as a parameter. The service argument class contains options that indicate the behaviors of the operation.

Creating Service Argument Classes

Service operations classes have a method to create an instance of service argument classes. For the ProjectOperation class, the method is:

CreateProjectOperationsServiceArguments<TProjectOperationsServiceArguments>().

For Integration class, the method is:

CreateIntegrationServiceArguments<TIntegrationServiceArguments>().

You need to specify the type of service argument class to create and that type depends on the operation you would like to run. For example, if you want to run Advance Calendar, you need to specify the type of AdvanceCalendarServiceArguments class.

// Create an instance of AdvanceCalendarServiceArguments class
// to be used in Advance Calendar
AdvanceCalendarServiceArguments advCalArgs = projOps.CreateProjectOperationsServiceArguments
<AdvanceCalendarServiceArguments>();
// Create an instance of IntegrateActualCostsServiceArguments class
// to be used in Integrate Actual Costs
IntegrateActualCostsServiceArguments intActualsArgs = integration.
CreateIntegrationServiceArguments<IntegrateActualCostsServiceArguments>();

To know what the type of each operation is, you can examine the parameter of the methods in the service operation classes.

Once you have the instance of the service argument classes, you can assign values to the options. These options are the properties of the class. For example, to run the Advance Calendar on Demo project, you need to specify that in the instance of AdvanceCalendarServiceArguments class:

advCalArgs.Project = "Demo";

You can specify values on other options.  For example, if you want to use the status date as actual start date for LoE and you want to include forecast in update totals, you can set true to the following properties:

advCalArgs.UseStatusDateAsActualStartDateForLoE = true;
advCalArgs.IncludeForecastInUpdateTotals = true;

For the instance of IntegrateActualCostsServiceArguments class, an example would be to define the configuration name.

intActualsArgs.ConfigurationName = "LoadDemoActualsConfig";

Calling on the Operations

Operations are represented in the service operation classes as methods. For example, in the ProjectOperations class, there is a method AdvanceCalendar(). If you want to run Advance Calendar on a specific project, you need to create an instance of the AdvanceCalendarServiceArguments class, set the name of the project to that instance, and call the AdvanceCalendar() method passing the instance of AdvanceCalendarServiceArguments class. The above section demonstrated the first two steps, the last step would be:

ServiceResult advCalResult = projOps.AdvanceCalendar(advCalArgs);

This sample script runs the Integrate Actual Costs:

ServiceResult intActualsResult = integration.IntegrateActualCosts(intActualsArgs);

Examining the Result from Operations

When you call on operations, the methods return an instance of ServiceResult class. This class contains information and messages resulting from the operation.

The service result class contains a Boolean property named Success. This property specifies if the operations have been completed successfully. You can check this before running other operations:

ServiceResult advCalResult;
ServiceResult intActualsResult;
advCalResult = projOps.AdvanceCalendar(advCalArgs);
if (advCalResult.Success
intActualsResult = integration.IntegrateActualCosts(intActualsArgs);

In the above example, it will not call on the Integrate Actual Costs if the Advance Calendar failed.

There are two methods in the ServiceResult class that relate to the messages resulting from the operation. The GetMessageCount() method returns the number of messages and the GetMessages() method returns the messages. These two methods accept MessageType enum flags as a parameter. The current version contains four flags for the MessageType enum: ValidationWarning, ValidationError, Warning and Error. ValidationWarning and ValidationError are messages returned when the operations validated the service arguments. The Cobra Web Service returns warning and error messages.

To get the number of errors from the Cobra Web Service:

if (!intActualsResult.Success) {
int errorCount = intActualsResult.GetMessageCount(MessageType.Error);
MessageBox.Show(string.Format("Advance Calendar failed with {0} errors", errorCount), "Operation Failed");

The GetMessages() method returns an array of ServiceMessage class. The ServiceMessage class contains the MessageType and the Message property. For example:

ServiceMessage[] warningMessages = intActualsResult.GetMessages(MessageType.ValidationWarning | 
MessageType.Warning);
StringBuilder warningMessagesString = new StringBuilder();
foreach (ServiceMessage warningMessage in warningMessages) {
warningMessagesString.AppendLine(string.Format("{0}: {1}", warningMessage.MessageType, warningMessage.
Message));
MessageBox.Show(warningMessagesString.ToString(), "Operation Warnings");

In the above example, both the ValidationWarning and Warning flags are specified in the GetMessages() method by using the bitwise OR operator ‘|’. The GetMessages() method will return both messages from ValidationWarning and Warning flags. You can also use the bitwise OR operator in the GetMessageCount() method.

The ServiceResult class also contains a string ProcessLogUid property. This property specifies the Uid of the Process Log. You can use the value of this property to query the details of the process in the process log.

In the event that when a process is running in the Cobra Web Service host machine and an unhandled exception occurs, the Exception property of the ServiceResult class will contain the exception information.