WBSTask

using System;  using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI;
using TestFramework;  namespace Tests.wbs { 	/// <summary>
	/// Summary description for WBSTask.
	/// 
	/// This sample loads a task from RPM repository 
	/// and fills the task before saving it back to RPM repository
	/// </summary>
	public class WBSTask
	{
		public WBSTask()
		{

		}

		public static String taskName = "IBM_CHILD_TASK";
		
		//Session ID is use for all transaction and is get from the 
		//Authenticate.login function. The session ID will replace 
		// the User password while transacting
		public static String sessionid;

		public void sampleTest()
		{

			// initialize a session with the API
			sessionid = APISetup.SetUp();

			// create a save result object 
			SaveResult save = null;

			// create a task scope
			// this scope enables us to save 
			// information around the task
			WorkElementScope tScope = new WorkElementScope();

			// adjust task scope to save sheduled dates and status
			tScope.scheduleDates = true;
			tScope.statusUpdate = true;

			// adjust task scope to save Task State
			tScope.state = true;

			// query a task object
			Task task = (Task)APISetup.application.loadFromXpath(
				sessionid, "/Task[name='" + taskName + "']", tScope )
				.rpmObjectList[0];

			// enter estimated dates
			task.estimatedStartDate = 
				new DateTime(2006,10,10,10,10,10,10);
			task.estimatedFinishDate = 
				new DateTime(2007,10,10,10,10,10,10);

			// expected dates can be entered here or if not 
			// they will be copied from estimated dates
			task.expectedDate.startDate = 
				new DateTime(2006,10,10,10,10,10,10);
			task.expectedDate.finishDate = 
				new DateTime(2007,10,10,10,10,10,10);

			// initialize start proposed date
			task.proposedDate.startDate = 
				new DateTime(2006,11,11,11,11,11,11);

			// save task
			// use a work element scope initialized 
			// so it includes good task childs
			// use a reload type that enables reloaded results
			save = new SaveResult();
			save = APISetup.application.save(sessionid, 
				task, tScope,ReloadType.ReloadResult);
			APISetup.checkForErrors( save );

			// reload task
			task = (Task)save.rpmObject;

			// execute a copy proposed to plan action on the task
			APISetup.application.copyProposedToPlan(
				sessionid, task, null);

			// save task
			// use a work element scope initialized so it 
			// includes good task childs
			// use a reload type that enables reloaded results
			save = new SaveResult();
			save = APISetup.application.save(sessionid, task, 
				tScope,ReloadType.ReloadResult);
			APISetup.checkForErrors( save );

			// reload task
			task = (Task)save.rpmObject;

			// create actual date
			task.actualDate = new WbsScheduleDate();
			// duration in minutes is mandatory to add an actual 
			// date and must be higher than 0 
			// but not higher than planed duration in minutes
			task.actualDate.durationInMinutes = 1;
			task.actualDate.startDate = 
				new DateTime(2007,2,2,2,2,2,2);

			// save task
			// use a work element scope initialized 
			// so it includes good task childs
			// use a reload type that enables reloaded results
			save = new SaveResult();
			save = APISetup.application.save(sessionid, task, tScope,
				ReloadType.ReloadResult);
			APISetup.checkForErrors( save );

			// reload task
			task = (Task)save.rpmObject;

			// forecast dates cannot be modified in RPM API
			//task.forecastDate = new WbsScheduleDate();
			//task.forecastDate.durationInMinutes = 5000;

			// initialize task state
			task.state = (DatafieldState)APISetup.application.
				loadFromXpath(sessionid, 
				"/TaskState[value='In Progress']", 
				null).rpmObjectList[0];

			// save task into RPM repository
			// use a scope that includes any information added
			// a reload type is not necessary at this point since 
			// we don't use this object again
			save = new SaveResult();
			save = APISetup.application.save(sessionid, task, 
				tScope,ReloadType.None);
			APISetup.checkForErrors( save );


			// close connection with API
			APISetup.CleanUp(sessionid);
		}

	}
}