WBSProjectRTF

using System;  using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI;
using TestFramework;  namespace Tests.wbs { 	/// <summary>
	/// Summary description for WBSProjectRTF.
	/// 
	/// This sample loads a project.
	/// It loads a projectRTF from RPM repository, 
	/// creates an rtf value and assigns it to a rtf assignement.
	/// It then saves the assignement into the project.
	/// </summary>
	public class WBSProjectRTF
	{
		public WBSProjectRTF()
		{

		}

		// these are all variables that are used in this sample
		public static String projectName = "IBM_GENERIC_PROJECT_ABC";
		public static String rtfType = "Key Accomplishments";
		public static String rtfValue = "{\\rtf1\\ansi\\deff0{\\fonttbl" +
			"{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Tahoma;}}" +
			"\n{\\colortbl ;\\red255\\green0\\blue0;}\n\\viewkind4\\uc1\\" +
			"pard\\cf1\\lang1033\\b\\fs28 This is a test.\\cf0\\b0\\f1\\fs20" +
			"\n\\par }";
		
		//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 pScope = new WorkElementScope();

			// adjust scope so it includes rtf assignment
			pScope.rtfAssignments = true;

			// create a project object
			Project project = new Project();

			// query the project
			project = (Project)APISetup.application.loadFromXpath(
				sessionid, "/Project[name='" + projectName + "']", 
					pScope ).rpmObjectList[0];

			// create a rtf assignement
			RtfAssignment rtfAssign = new RtfAssignment();

			// load an existing RTF corresponding to the type of
			// container being modified
			ProjectRTF pRtf =  (ProjectRTF)APISetup.application.
				loadFromXpath(sessionid, "/ProjectRTF[value='" + 
				rtfType + "']", null).rpmObjectList[0];

			// assign rtf to the assignement
			rtfAssign.rtf = pRtf;
			
			// value contains most information about rtf and content
			// value sample :
			//   {\\rtf1\\ansi\\deff0{\\fonttbl{\\f0\\fnil\\fcharset0
			//   Arial;}{\\f1\\fnil\\fcharset0 Tahoma;}}\n{\\colortbl
			//    ;\\red0\\green128\\blue0;}\n\\viewkind4\\uc1\\pard\
			//   \cf1\\lang1033\\b\\fs28 This is a test.\\cf0\\b0\\f1
			//   \\fs20 \n\\par }
			rtfAssign.value = rtfValue;

			int power;
			int bitFlag;

			// create a bitFlag for the rtf assignement
			power = int.Parse(pRtf.name.Trim());
			bitFlag = ((int)Math.Pow(2, power-1));

			// assign the bitFlag
			rtfAssign.bitFlag = bitFlag;

			// link the assignement with the wbs object
			rtfAssign.parent = project;
			project.rtfAssignments = new RtfAssignment[] {rtfAssign};

			// save the project into the RPM repository
			// the scope is necessary to save changes 
			// with link to the parent
			save = new SaveResult();
			save = APISetup.application.save(sessionid, 
				project, pScope, 
				ReloadType.None);
			APISetup.checkForErrors( save );


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

	}
}