private static SetItemFieldType GetEndUpdate(Appointment apt)
		{
			SetItemFieldType endUpdate = new SetItemFieldType();

			PathToUnindexedFieldType endPath = new PathToUnindexedFieldType();
			endPath.FieldURI = UnindexedFieldURIType.calendarEnd;

			CalendarItemType endData = new CalendarItemType();
			endData.End = apt.End;
			endData.EndSpecified = true;

			endUpdate.Item = endPath;
			endUpdate.Item1 = endData;
			return endUpdate;
		}
		private static SetItemFieldType GetRecurrenceUpdate(Appointment apt)
		{
			SetItemFieldType recurrenceUpdate = new SetItemFieldType();

			PathToUnindexedFieldType recurrencePath = new PathToUnindexedFieldType();
			recurrencePath.FieldURI = UnindexedFieldURIType.calendarRecurrence;

			CalendarItemType recurrenceData = new CalendarItemType();
			RecurrenceRule rrule;
			RecurrenceRule.TryParse(apt.RecurrenceRule, out rrule);
			if (rrule != null && rrule.Pattern.Frequency != RecurrenceFrequency.Hourly)
			{
				recurrenceData.Recurrence = CreateRecurrence(rrule, apt.Owner);
			}

			recurrenceUpdate.Item = recurrencePath;
			recurrenceUpdate.Item1 = recurrenceData;
			return recurrenceUpdate;
		}
		private static SetItemFieldType GetStartUpdate(Appointment apt)
		{
			SetItemFieldType startUpdate = new SetItemFieldType();

			PathToUnindexedFieldType startPath = new PathToUnindexedFieldType();
			startPath.FieldURI = UnindexedFieldURIType.calendarStart;

			CalendarItemType startData = new CalendarItemType();
			startData.Start = apt.Start;
			startData.StartSpecified = true;

			startUpdate.Item = startPath;
			startUpdate.Item1 = startData;
			return startUpdate;
		}
		private static SetItemFieldType GetSubjectUpdate(Appointment apt)
		{
			SetItemFieldType subjectUpdate = new SetItemFieldType();

			PathToUnindexedFieldType subjectPath = new PathToUnindexedFieldType();
			subjectPath.FieldURI = UnindexedFieldURIType.itemSubject;

			CalendarItemType subjectData = new CalendarItemType();
			subjectData.Subject = apt.Subject;

			subjectUpdate.Item = subjectPath;
			subjectUpdate.Item1 = subjectData;
			return subjectUpdate;
		}
		private CalendarItemType GetOccurrenceItem(Appointment master, int index)
		{
			ItemIdType masterItemId = new ItemIdType();
			masterItemId.Id = master.Attributes[ExchangeIdAttribute];
			masterItemId.ChangeKey = master.Attributes[ExchangeChangeKeyAttribute];

			OccurrenceItemIdType occurrenceItemId = new OccurrenceItemIdType();
			occurrenceItemId.RecurringMasterId = masterItemId.Id;
			occurrenceItemId.InstanceIndex = index;

			PathToUnindexedFieldType calendarItemTypePath = new PathToUnindexedFieldType();
			calendarItemTypePath.FieldURI = UnindexedFieldURIType.calendarCalendarItemType;

			GetItemType getItemRequest = new GetItemType();
			getItemRequest.ItemShape = new ItemResponseShapeType();
			getItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly;
			getItemRequest.ItemShape.AdditionalProperties = new BasePathToElementType[] { calendarItemTypePath };
			getItemRequest.ItemIds = new BaseItemIdType[] { masterItemId, occurrenceItemId };

			GetItemResponseType getItemResponse = Service.GetItem(getItemRequest);

			CalendarItemType occurrenceItem = null;
			foreach (ItemInfoResponseMessageType getItemResponseMessage in getItemResponse.ResponseMessages.Items)
			{
				if (getItemResponseMessage.ResponseClass == ResponseClassType.Success &&
				    getItemResponseMessage.Items.Items != null &&
				    getItemResponseMessage.Items.Items.Length > 0)
				{
					occurrenceItem = (CalendarItemType) getItemResponseMessage.Items.Items[0];
				}
			}

			if (occurrenceItem == null)
			{
				throw new Exception("Unable to find occurrence");
			}

			return occurrenceItem;
		}
		private void RemoveRecurrenceExceptions(Appointment appointmentToUpdate)
		{
			ItemChangeType itemUpdates = new ItemChangeType();

			ItemIdType itemId = new ItemIdType();
			itemId.Id = appointmentToUpdate.Attributes[ExchangeIdAttribute];
			itemId.ChangeKey = appointmentToUpdate.Attributes[ExchangeChangeKeyAttribute];

			itemUpdates.Item = itemId;

			PathToUnindexedFieldType deletedOccurrencesPath = new PathToUnindexedFieldType();
			deletedOccurrencesPath.FieldURI = UnindexedFieldURIType.calendarRecurrence;

			DeleteItemFieldType deletedOccurrencesUpdate = new DeleteItemFieldType();
			deletedOccurrencesUpdate.Item = deletedOccurrencesPath;

			// To reset the deleted and modified occurrences we must
			// remove the recurrence rule and then immediately restore it
			itemUpdates.Updates = new ItemChangeDescriptionType[] { deletedOccurrencesUpdate, GetRecurrenceUpdate(appointmentToUpdate) };
			UpdateCalendarItem(new ItemChangeType[] { itemUpdates });
		}
        /// <summary>
        /// Finds all Calendar Items for the current User's Mailbox.
        /// </summary>
        /// <returns></returns>
        //protected internal CalendarItemType[] FindCalendarItems()
        //{
        //    // Identify which folders to search.
        //    DistinguishedFolderIdType[] parentFolderIds = new DistinguishedFolderIdType[1];

        //    parentFolderIds[0] = new DistinguishedFolderIdType();
        //    parentFolderIds[0].Id = DistinguishedFolderIdNameType.calendar;

        //    return FindCalendarItems(parentFolderIds);
        //}

		protected internal CalendarItemType[] FindCalendarItems(DistinguishedFolderIdType[] parentFolderIds)
		{
			// Form the FindItem request.
			FindItemType findItemRequest = new FindItemType();

			// Define the item properties that are returned in the response.
			ItemResponseShapeType itemProperties = new ItemResponseShapeType();
			itemProperties.BaseShape = DefaultShapeNamesType.IdOnly;
			
			PathToUnindexedFieldType calendarIsRecurringFieldPath = new PathToUnindexedFieldType();
			calendarIsRecurringFieldPath.FieldURI = UnindexedFieldURIType.calendarIsRecurring;
			
			PathToUnindexedFieldType calendarItemTypeFieldPath = new PathToUnindexedFieldType();
			calendarIsRecurringFieldPath.FieldURI = UnindexedFieldURIType.calendarCalendarItemType;

			PathToUnindexedFieldType calendarStartFieldPath = new PathToUnindexedFieldType();
			calendarStartFieldPath.FieldURI = UnindexedFieldURIType.calendarStart;

			PathToUnindexedFieldType calendarEndFieldPath = new PathToUnindexedFieldType();
			calendarEndFieldPath.FieldURI = UnindexedFieldURIType.calendarEnd;

            //location
            //PathToUnindexedFieldType calendarLocation = new PathToUnindexedFieldType();
            //calendarLocation.FieldURI = UnindexedFieldURIType.calendarLocation;
            //// body
            //PathToUnindexedFieldType itemBody = new PathToUnindexedFieldType();
            //itemBody.FieldURI = UnindexedFieldURIType.itemBody;

			itemProperties.AdditionalProperties = new PathToUnindexedFieldType[]
			                                      	{
			                                      		calendarIsRecurringFieldPath, 
			                                      		calendarItemTypeFieldPath,
			                                      		calendarStartFieldPath,
			                                      		calendarEndFieldPath
			                                      	};
			findItemRequest.ItemShape = itemProperties;

			findItemRequest.ParentFolderIds = parentFolderIds;

			// Define the sort order of items.
			FieldOrderType[] fieldsOrder = new FieldOrderType[1];
			fieldsOrder[0] = new FieldOrderType();
			PathToUnindexedFieldType subjectOrder = new PathToUnindexedFieldType();
			subjectOrder.FieldURI = UnindexedFieldURIType.calendarStart;
			fieldsOrder[0].Item = subjectOrder;
			fieldsOrder[0].Order = SortDirectionType.Ascending;
			findItemRequest.SortOrder = fieldsOrder;

			// Define the traversal type.
			findItemRequest.Traversal = ItemQueryTraversalType.Shallow;

			// Send the FindItem request and get the response.
			FindItemResponseType findItemResponse = Service.FindItem(findItemRequest);

			// Access the response message.
			ArrayOfResponseMessagesType responseMessages = findItemResponse.ResponseMessages;
			ResponseMessageType responseMessage = responseMessages.Items[0];

			if (responseMessage is FindItemResponseMessageType)
			{
				FindItemResponseMessageType firmt = (responseMessage as FindItemResponseMessageType);
				FindItemParentType fipt = firmt.RootFolder;
				object obj = fipt.Item;

				if (obj is ArrayOfRealItemsType)
				{
					ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType);

					if (items.Items != null)
					{
						List<CalendarItemType> calendarItems = new List<CalendarItemType>(items.Items.Length);
						foreach (ItemType item in items.Items)
						{
							CalendarItemType calendarItem = item as CalendarItemType;

							if (calendarItem != null)
							{
								calendarItems.Add(calendarItem);
							}
						}

						return calendarItems.ToArray();
					}

					return new CalendarItemType[0];
				}
			}

			return null;
		}