Ejemplo n.º 1
0
        private void DeleteItem(BaseItemIdType itemId)
        {
            DeleteItemType deleteItemRequest = new DeleteItemType();

            deleteItemRequest.DeleteType = DisposalType.HardDelete;
            deleteItemRequest.AffectedTaskOccurrences           = AffectedTaskOccurrencesType.SpecifiedOccurrenceOnly;
            deleteItemRequest.AffectedTaskOccurrencesSpecified  = true;
            deleteItemRequest.SendMeetingCancellations          = CalendarItemCreateOrDeleteOperationType.SendToNone;
            deleteItemRequest.SendMeetingCancellationsSpecified = true;

            deleteItemRequest.ItemIds = new BaseItemIdType[] { itemId };

            DeleteItemResponseType response        = Service.DeleteItem(deleteItemRequest);
            ResponseMessageType    responseMessage = response.ResponseMessages.Items[0];

            if (responseMessage.ResponseCode != ResponseCodeType.NoError)
            {
                throw new Exception("DeleteItem failed with response code " + responseMessage.ResponseCode);
            }
        }
        /// <summary>
        /// Get the items information.
        /// </summary>
        /// <param name="itemIds">The array of item ids.</param>
        /// <returns>The items information.</returns>
        protected ItemType[] GetItems(BaseItemIdType[] itemIds)
        {
            GetItemType getItem = new GetItemType();
            if (itemIds != null)
            {
                getItem.ItemIds = itemIds;
                getItem.ItemShape = new ItemResponseShapeType();
                getItem.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
            }

            // Call GetItem operation
            GetItemResponseType getItemResponse = this.COREAdapter.GetItem(getItem);

            // Check whether the GetItem operation is executed successfully.
            foreach (ResponseMessageType responseMessage in getItemResponse.ResponseMessages.Items)
            {
                Site.Assert.AreEqual<ResponseClassType>(
                    ResponseClassType.Success,
                    responseMessage.ResponseClass,
                    string.Format(
                        "Get items should not be failed! Expected response code: {0}, actual response code: {1}",
                        ResponseCodeType.NoError,
                        responseMessage.ResponseCode));
            }

            // If the operation executes successfully, the items in getItem response should be equal to the value of ItemCount.
            Site.Assert.AreEqual<int>(
                getItemResponse.ResponseMessages.Items.Length,
                this.ItemCount,
                string.Format(
                "The getItem response should contain {0} items, actually it contains {1}",
                this.ItemCount,
                getItemResponse.ResponseMessages.Items.Length));

            // Get the items from successful response.
            ItemType[] getItems = Common.GetItemsFromInfoResponse<ItemType>(getItemResponse);

            return getItems;
        }
        /// <summary>
        /// Handle the server response.
        /// </summary>
        /// <param name="request">The request messages.</param>
        /// <param name="response">The response messages.</param>
        /// <param name="isSchemaValidated">Verify the schema.</param>
        private void ExchangeServiceBinding_ResponseEvent(
            BaseRequestType request,
            BaseResponseMessageType response,
            bool isSchemaValidated)
        {
            this.IsSchemaValidated = isSchemaValidated;

            // A flag represents the response contains the item information or not.
            bool hasItemInfo = false;
            if (response is SetUserPhotoResponseMessageType)
            {
                return;
            }

            foreach (ResponseMessageType responseMessage in response.ResponseMessages.Items)
            {
                if (responseMessage is ItemInfoResponseMessageType)
                {
                    hasItemInfo = true;
                    break;
                }
            }

            BaseItemIdType[] itemIds;
            if (hasItemInfo)
            {
                itemIds = Common.GetItemIdsFromInfoResponse(response);
            }
            else
            {
                itemIds = new BaseItemIdType[0];
                return;
            }

            foreach (ItemIdType itemId in itemIds)
            {
                bool notExist = true;
                foreach (ItemIdType exist in this.ExistContactItems)
                {
                    if (exist.Id == itemId.Id)
                    {
                        // Check if the Id of the item in response exists in previous recorded item list.
                        notExist = false;
                        break;
                    }
                }

                // If the Id of Item is not exist, add the item into item list.
                if (notExist)
                {
                    this.ExistContactItems.Add(itemId);
                }
            }
        }
		private void DeleteItem(BaseItemIdType itemId)
		{
			DeleteItemType deleteItemRequest = new DeleteItemType();
			deleteItemRequest.DeleteType = DisposalType.HardDelete;
			deleteItemRequest.AffectedTaskOccurrences = AffectedTaskOccurrencesType.SpecifiedOccurrenceOnly;
			deleteItemRequest.AffectedTaskOccurrencesSpecified = true;
			deleteItemRequest.SendMeetingCancellations = CalendarItemCreateOrDeleteOperationType.SendToNone;
			deleteItemRequest.SendMeetingCancellationsSpecified = true;

			deleteItemRequest.ItemIds = new BaseItemIdType[] { itemId };

			DeleteItemResponseType response = Service.DeleteItem(deleteItemRequest);
			ResponseMessageType responseMessage = response.ResponseMessages.Items[0];

			if (responseMessage.ResponseCode != ResponseCodeType.NoError)
			{
				throw new Exception("DeleteItem failed with response code " + responseMessage.ResponseCode);
			}
		}