WBSTaskDependency

using System;  using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI;
using TestFramework;  namespace Tests.wbs { 	/// <summary>
	/// Summary description for WBSTaskDependency.
	/// 
	/// This sample loads a task from RPM repository
	/// and assigns a dependency to the task.
	/// </summary>
	public class WBSTaskDependency
	{
		public WBSTaskDependency()
		{

		}

		// these are all variables that are used in this sample
		public static String taskName = "IBM_CHILD_TASK";
		public static String depName = "IBM_DEPENDENCY";
		public static String sTaskName = "IBM_MILESTONE";
		
		//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 so it includes dependencies
			tScope.dependencies = true;

			// create a task object
			Task task = new Task();

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

			// create the element dependency
			ElementDependency elemDep = new ElementDependency();

			// load the predecessor of the element dependency
			// this predecessor contains is predecessors as well
			Milestone sTask =  (Milestone)APISetup.application.
				loadFromXpath(sessionid, 
				"Milestone[name='" + sTaskName + "']", 
				null).rpmObjectList[0];

			// assign the parent and predecessor 
			// to element dependency
			elemDep.parent = task;
			elemDep.predecessor = sTask;

			// assign element dependency to the task
			task.dependencies = new ElementDependency[] {elemDep};

			// 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);
		}

	}
}