ResourceCalendar

using System;  using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI;
using TestFramework;  namespace Tests.resource  { 	/// <summary>
	/// Summary description for ResourceCalendar.
	/// 
	/// This sample creates a calendar and then
	/// assigns it to a resource taken in the
	/// RPM repository.
	/// </summary>
	public class ResourceCalendar
	{
		public ResourceCalendar()
		{

		}

		//All these variables are used in this sample
		public static String resourceName = "IBM_testABCDEF";
		public static String calendarName = "Work";

		//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()
		{


			// start the communication with the api
			sessionid = APISetup.SetUp();

			// Declare the resource wich we are going to use
			Resource res = null;

			// create a resourceScope to keep track of the relation 
			// between the resource and the calendar
			ResourceScope rScope = new ResourceScope();

			// adjust the resource scope to keep 
			// the relation with calendar
			rScope.calendar = new CalendarScope();

			// create a calendar
			RPMCalendar calendar = new RPMCalendar();

			// Find the resource in RPM using XPath.
			// take resource in RPM repository by its 
			// fullname or externalid
			res = (Resource)APISetup.application.
				loadFromXpath(sessionid, 
				"/Resource[fullname='" + resourceName + "']", 
				null ).rpmObjectList[0];

			// initialise the calendar with default values
			calendar.name = calendarName;
			calendar.startDate = 
				new DateTime(2006, 10, 10, 10, 10, 10 );

			// save the calendar in the RPM repository
			SaveResult save = APISetup.application.
				save(sessionid, calendar, null, 
				ReloadType.SavedResult );
			APISetup.checkForErrors( save );

			// load the calendar to work with the saved object
			calendar = (RPMCalendar)APISetup.application.
				loadFromXpath(sessionid, 
				"/RPMCalendar[name='" + calendarName + "']", 
				null ).rpmObjectList[0];

			// assign the calendar to the ressource
			res.calendar = calendar;

			// save the resource in the RPM repository
			// use the sessionid acquired in the setUp
			// use the resource scope
			save = APISetup.application.save(sessionid, 
				res, rScope, ReloadType.SavedResult );
			APISetup.checkForErrors( save );


			// end the communication with the api.
			APISetup.CleanUp(sessionid);

		}
	}
}