public bool UploadItems(FolderIdType parentFolderId, IEnumerable <ItemInformation> items, bool alwaysCreateNew) { UploadItemsType itemsType = new UploadItemsType(); CreateActionType createActionType = alwaysCreateNew ? CreateActionType.CreateNew : CreateActionType.UpdateOrCreate; itemsType.Items = (from item in items select new UploadItemType { CreateAction = createActionType, ItemId = new ItemIdType { Id = item.Id }, Data = item.Data, ParentFolderId = parentFolderId }).ToArray <UploadItemType>(); int successCount = 0; this.CallEwsWithRetries((LID)0U, () => this.binding.UploadItems(itemsType), delegate(ResponseMessageType responseMessage, int messageIndex) { UploadItemsResponseMessageType uploadItemsResponseMessageType = responseMessage as UploadItemsResponseMessageType; if (uploadItemsResponseMessageType != null && uploadItemsResponseMessageType.ResponseClass == ResponseClassType.Success) { successCount++; if (this.IsTraceEnabled(TraceType.DebugTrace)) { this.Tracer.TraceDebug(0L, "Items uploaded successfully"); } } return(false); }, null); return(successCount == itemsType.Items.Length); }
/// <summary> /// Uploads the items into a specified folder. /// </summary> /// <param name="uploadItemsRequest">Specify the request for UploadItems operation.</param> /// <returns>The response to this operation request.</returns> public UploadItemsResponseType UploadItems(UploadItemsType uploadItemsRequest) { if (uploadItemsRequest == null) { throw new ArgumentException("The uploadItems should not be null."); } // Send the request and get the response. UploadItemsResponseType response = this.exchangeServiceBinding.UploadItems(uploadItemsRequest); this.VerifyTransportType(); this.VerifySoapVersion(); this.VerifyUploadItemsResponseType(response, this.exchangeServiceBinding.IsSchemaValidated); return(response); }
public void MSOXWSBTRF_S01_TC05_ExportAndUploadItems_Update_Fail() { #region Get the exported items. // Get the exported items which are prepared for uploading. ExportItemsResponseMessageType[] exportedItem = this.ExportItems(false); #endregion #region Create a new folder to place the upload item. // Create another sub folder. string[] subFolderIds = new string[this.ParentFolderType.Count]; for (int i = 0; i < subFolderIds.Length; i++) { // Generate the folder name. string folderName = Common.GenerateResourceName(this.Site, this.ParentFolderType[i] + "NewFolder"); // Create sub folder in the specified parent folder subFolderIds[i] = this.CreateSubFolder(this.ParentFolderType[i], folderName); Site.Assert.IsNotNull( subFolderIds[i], string.Format( "The sub folder named '{0}' under '{1}' should be created successfully.", folderName, this.ParentFolderType[i].ToString())); } #endregion #region Call UploadItems operation with CreateAction set to Update and the ParentFolderId set to the new created sub folder. // Initialize the uploaded items using the previous exported items, set the item's CreateAction to Update and the ParentFolderId to the sub folder. UploadItemsType uploadItemsWithChangedParentFolderId = new UploadItemsType(); uploadItemsWithChangedParentFolderId.Items = new UploadItemType[this.ItemCount]; for (int i = 0; i < uploadItemsWithChangedParentFolderId.Items.Length; i++) { uploadItemsWithChangedParentFolderId.Items[i] = TestSuiteHelper.GenerateUploadItem( exportedItem[i].ItemId.Id, exportedItem[i].ItemId.ChangeKey, exportedItem[i].Data, subFolderIds[i], CreateActionType.Update); } // Call UploadItems operation. UploadItemsResponseType uploadItemsWithChangedParentFolderIdResponse = this.BTRFAdapter.UploadItems(uploadItemsWithChangedParentFolderId); // Check whether the ExportItems operation is executed successfully. foreach (UploadItemsResponseMessageType responseMessage in uploadItemsWithChangedParentFolderIdResponse.ResponseMessages.Items) { Site.Assert.AreEqual <ResponseClassType>( ResponseClassType.Error, responseMessage.ResponseClass, string.Format( @"The ExportItems operation should be unsuccessful. Expected response code: {0}, actual response code: {1}", ResponseClassType.Error, responseMessage.ResponseClass)); } #endregion #region Verify UploadItems related requirements. // Verify UploadItems related requirements. this.VerifyUploadItemsErrorResponse(uploadItemsWithChangedParentFolderIdResponse); // If the ResponseClass property equals Error, then MS-OXWSBTRF_R231 can be captured // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSBTRF_R231."); // Verify MS-OXWSBTRF requirement: MS-OXWSBTRF_R231 Site.CaptureRequirementIfAreEqual <ResponseCodeType>( ResponseCodeType.ErrorItemNotFound, uploadItemsWithChangedParentFolderIdResponse.ResponseMessages.Items[0].ResponseCode, 231, @"[In CreateActionType Simple Type][Update] if the target item is not in the original folder specified by the <ParentFolderId> element in the UploadItemType complex type, an ErrorItemNotFound error code MUST be returned in the UploadItemsResponseMessageType complex type."); #endregion #region Call UploadItems operation with CreateAction set to Update and the ItemId set to invalid value. // Call UploadItemsFail method to upload three kinds of items and set the CreateAction to Update: // 1.The ID attribute of ItemId is empty; // 2.The ID attribute of ItemId is valid and the ChangeKey is invalid; // 3.The ID attribute of ItemId is invalid and the ChangeKey is null. this.UploadInvalidItems(this.OriginalFolderId, CreateActionType.Update); #endregion }
private void MigrateItens(ref DataGridViewRow row, ExchangeServiceBinding srcService, ExchangeServiceBinding tgtService, DistinguishedFolderIdNameType folder, string srcUserMail, string tgtUserMail) { ResponseMessageType[] itemsResponse = this.GetFolderItems(srcService, folder); ExportItemsType exExportItems = new ExportItemsType(); foreach (ResponseMessageType responseMessage in itemsResponse) { FindItemResponseMessageType firmt = responseMessage as FindItemResponseMessageType; FindItemParentType fipt = firmt.RootFolder; object obj = fipt.Item; int count = 0; // FindItem contains an array of items. if (obj is ArrayOfRealItemsType) { ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType); exExportItems.ItemIds = new ItemIdType[(items.Items.Count() + 1)]; foreach (ItemType it in items.Items) { exExportItems.ItemIds[count] = new ItemIdType(); exExportItems.ItemIds[count].Id = it.ItemId.Id; count++; } } } ExportItemsResponseType exResponse = srcService.ExportItems(exExportItems); ResponseMessageType[] rmResponses = exResponse.ResponseMessages.Items; UploadItemsType upUploadItems = new UploadItemsType(); upUploadItems.Items = new UploadItemType[(rmResponses.Length + 1)]; Int32 icItemCount = 0; foreach (ResponseMessageType rmReponse in rmResponses) { if (rmReponse.ResponseClass == ResponseClassType.Success) { ExportItemsResponseMessageType exExportedItem = (ExportItemsResponseMessageType)rmReponse; Byte[] messageBytes = exExportedItem.Data; UploadItemType upUploadItem = new UploadItemType(); upUploadItem.CreateAction = CreateActionType.UpdateOrCreate; upUploadItem.Data = messageBytes; upUploadItem.IsAssociatedSpecified = true; upUploadItem.IsAssociated = false; upUploadItems.Items[icItemCount] = upUploadItem; FolderIdManager folderIdMgr = new FolderIdManager(); FolderIdType folderId = new FolderIdType(); folderId.Id = folderIdMgr.GetFolderId(tgtUserMail, Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Contacts, Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP2); upUploadItem.ParentFolderId = folderId; icItemCount += 1; } } //Erro de Internal Server Error nessa etapa UploadItemsResponseType upLoadResponse = tgtService.UploadItems(upUploadItems); Int32 Success = 0; Int32 Failure = 0; foreach (ResponseMessageType upResponse in upLoadResponse.ResponseMessages.Items) { if (upResponse.ResponseClass == ResponseClassType.Success) { Success++; } if (upResponse.ResponseClass == ResponseClassType.Error) { Failure++; } } string resTask = string.Format("Items Copied Sucessfull : {0} - Failure: {1}", Success, Failure); Tools.SetRowValue(ref row, EColumns.results, resTask); //iv.Offset += fiItems.Items.Count; }
/// <summary> /// Get the UploadItemsResponseMessageType response of UploadItems operation when this operation executes unsuccessfully. /// </summary> /// <param name="parentFolderId">Specifies the target folder in which to place the upload item.</param> /// <param name="createAction">Specifies the action for uploading items to the folder.</param> /// <returns>The array of UploadItemsResponseMessageType response.</returns> protected UploadItemsResponseMessageType[] UploadInvalidItems(Collection <string> parentFolderId, CreateActionType createAction) { #region Get the exported items and parent folder ID. // Get the exported items which is prepared for uploading. ExportItemsResponseMessageType[] exportedItem = this.ExportItems(false); #endregion #region Call UploadItems operation to upload the items that exported in last step to the server. // Initialize the upload items using the data of previous export items, and set that item CreateAction to a value of CreateActionType. UploadItemsType uploadInvalidItems = new UploadItemsType(); uploadInvalidItems.Items = new UploadItemType[4]; // The ID attribute of ItemId is empty. uploadInvalidItems.Items[0] = TestSuiteHelper.GenerateUploadItem( string.Empty, null, exportedItem[0].Data, parentFolderId[0], createAction); // The ID attribute of ItemId is valid and the ChangeKey is invalid. uploadInvalidItems.Items[1] = TestSuiteHelper.GenerateUploadItem( exportedItem[1].ItemId.Id, InvalidChangeKey, exportedItem[1].Data, parentFolderId[1], createAction); // The ID attribute of ItemId is invalid and the ChangeKey is null. uploadInvalidItems.Items[2] = TestSuiteHelper.GenerateUploadItem( InvalidItemId, null, exportedItem[2].Data, parentFolderId[2], createAction); // The ID attribute of ItemId is invalid and the ChangeKey is null. uploadInvalidItems.Items[3] = TestSuiteHelper.GenerateUploadItem( InvalidItemId, null, exportedItem[3].Data, parentFolderId[3], createAction); // Call UploadItems operation. UploadItemsResponseType uploadItemsResponse = this.BTRFAdapter.UploadItems(uploadInvalidItems); // Check whether the ExportItems operation is executed successfully. foreach (UploadItemsResponseMessageType responseMessage in uploadItemsResponse.ResponseMessages.Items) { Site.Assert.AreEqual <ResponseClassType>( ResponseClassType.Error, responseMessage.ResponseClass, string.Format( @"The UploadItems operation should be unsuccessful. Expected response code: {0}, actual response code: {1}", ResponseClassType.Error, responseMessage.ResponseClass)); } #endregion #region Verify the UploadItemsResponseType related requirements // Verify the UploadItemsResponseType related requirements. this.VerifyUploadItemsErrorResponse(uploadItemsResponse); #endregion #region Call GetResponseMessages to get the UploadItemsResponseMessageType items. // Get the UploadItemsResponseMessageType items. UploadItemsResponseMessageType[] uploadItemsResponseMessages = TestSuiteHelper.GetResponseMessages <UploadItemsResponseMessageType>(uploadItemsResponse); return(uploadItemsResponseMessages); #endregion }
/// <summary> /// Get the UploadItemsResponseMessageType response of UploadItems operation when this operation executes successfully. /// </summary> /// <param name="exportedItems">The items exported from server.</param> /// <param name="parentFolderId">Specifies the target folder in which to place the upload item.</param> /// <param name="createAction">Specifies the action for uploading items to the folder.</param> /// <param name="isAssociatedSpecified">A Boolean value specifies whether IsAssociated attribute is specified.</param> /// <param name="isAssociated">Specifies the value of the IsAssociated attribute.</param> /// <param name="configureSOAPHeader">A Boolean value specifies whether configuring the SOAP header before calling operations.</param> /// <returns>The array of UploadItemsResponseMessageType response.</returns> protected UploadItemsResponseMessageType[] UploadItems( ExportItemsResponseMessageType[] exportedItems, Collection <string> parentFolderId, CreateActionType createAction, bool isAssociatedSpecified, bool isAssociated, bool configureSOAPHeader) { #region Call UploadItems operation to upload the items that exported in last step to the server. // Initialize the upload items using the data of previous exported items, and set that item CreateAction to a value of CreateActionType. UploadItemsType uploadItems = new UploadItemsType(); uploadItems.Items = new UploadItemType[this.ItemCount]; for (int i = 0; i < uploadItems.Items.Length; i++) { uploadItems.Items[i] = TestSuiteHelper.GenerateUploadItem( exportedItems[i].ItemId.Id, exportedItems[i].ItemId.ChangeKey, exportedItems[i].Data, parentFolderId[i], createAction); uploadItems.Items[i].IsAssociatedSpecified = isAssociatedSpecified; if (uploadItems.Items[i].IsAssociatedSpecified) { uploadItems.Items[i].IsAssociated = isAssociated; } } // Call UploadItems operation. UploadItemsResponseType uploadItemsResponse = this.BTRFAdapter.UploadItems(uploadItems); // Check whether the operation is executed successfully. foreach (UploadItemsResponseMessageType uploadResponse in uploadItemsResponse.ResponseMessages.Items) { Site.Assert.AreEqual <ResponseClassType>( ResponseClassType.Success, uploadResponse.ResponseClass, string.Format( @"The UploadItems operation should be successful. Expected response code: {0}, actual response code: {1}", ResponseClassType.Error, uploadResponse.ResponseClass)); } // If the operation executes successfully, the items in UploadItems response should be equal to the value of ItemCount Site.Assert.AreEqual <int>( uploadItemsResponse.ResponseMessages.Items.Length, this.ItemCount, string.Format( "The uploadItems response should contain {0} items, actually, it contains {1}", this.ItemCount, uploadItemsResponse.ResponseMessages.Items.Length)); #endregion #region Verify the UploadItemsResponseType related requirements // Verify the UploadItemsResponseType related requirements. this.VerifyUploadItemsSuccessResponse(uploadItemsResponse); #endregion #region Call GetResponseMessages to get the UploadItemsResponseMessageType items. // Get the UploadItemsResponseMessageType items. UploadItemsResponseMessageType[] uploadItemsResponseMessages = TestSuiteHelper.GetResponseMessages <UploadItemsResponseMessageType>(uploadItemsResponse); return(uploadItemsResponseMessages); #endregion }
// Token: 0x06000581 RID: 1409 RVA: 0x0002AA2C File Offset: 0x00028C2C public List <ElcEwsItem> UploadItems(FolderIdType parentFolderId, IList <ElcEwsItem> items, bool alwaysCreateNew) { UploadItemsType uploadItems = new UploadItemsType(); uploadItems.Items = (from item in items select new UploadItemType { CreateAction = (alwaysCreateNew ? CreateActionType.CreateNew : CreateActionType.UpdateOrCreate), ItemId = new ItemIdType { Id = item.Id }, Data = item.Data, ParentFolderId = parentFolderId }).ToArray <UploadItemType>(); List <ElcEwsItem> returnedItems = new List <ElcEwsItem>(uploadItems.Items.Length); int startIndex = 0; this.CallService(() => this.ServiceBinding.UploadItems(uploadItems), delegate(ResponseMessageType responseMessage, int messageIndex) { UploadItemsResponseMessageType uploadItemsResponseMessageType = (UploadItemsResponseMessageType)responseMessage; ElcEwsItem elcEwsItem = items[startIndex + messageIndex]; if (uploadItemsResponseMessageType.ResponseClass == ResponseClassType.Error) { ElcEwsClient.Tracer.TraceError <ResponseCodeType>(0L, "ElcEwsClient.UploadItems: UploadItems with error response message. ResponseCode : {0}", uploadItemsResponseMessageType.ResponseCode); if (uploadItemsResponseMessageType.ResponseCode == ResponseCodeType.ErrorQuotaExceeded) { throw new ElcEwsException(ElcEwsErrorType.TargetOutOfSpace, uploadItemsResponseMessageType.ResponseCode.ToString()); } returnedItems.Add(new ElcEwsItem { Id = elcEwsItem.Id, Data = elcEwsItem.Data, Error = new ElcEwsException(ElcEwsErrorType.FailedToUploadItem, uploadItemsResponseMessageType.ResponseCode.ToString()), StorageItemData = elcEwsItem.StorageItemData }); } else if (uploadItemsResponseMessageType.ResponseClass == ResponseClassType.Warning) { ElcEwsClient.Tracer.TraceWarning <ResponseCodeType, string>(0L, "ElcEwsClient.UploadItems: Message response warning. ResponseCode:{0}; MessageText:'{1}'", uploadItemsResponseMessageType.ResponseCode, uploadItemsResponseMessageType.MessageText); if (uploadItemsResponseMessageType.ResponseCode == ResponseCodeType.ErrorBatchProcessingStopped) { ElcEwsClient.Tracer.TraceWarning <int, int>(0L, "ElcEwsClient.UploadItems: Hitting ErrorBatchProcessingStopped, startIndex:{0}; messageIndex={1}", startIndex, messageIndex); if (messageIndex == 0) { throw new RetryException(new ElcEwsException(ElcEwsErrorType.FailedToUploadItem, "Internal Error: Hitting ErrorBatchProcessingStopped as the first response."), false); } startIndex += messageIndex; uploadItems.Items = uploadItems.Items.Skip(messageIndex).ToArray <UploadItemType>(); throw new RetryException(new ElcEwsException(ElcEwsErrorType.FailedToUploadItem, "Hitting ErrorBatchProcessingStopped"), true); } else { returnedItems.Add(new ElcEwsItem { Id = elcEwsItem.Id, Data = null, Error = new ElcEwsException(ElcEwsErrorType.FailedToUploadItem, uploadItemsResponseMessageType.ResponseCode.ToString()), StorageItemData = elcEwsItem.StorageItemData }); } } else { returnedItems.Add(new ElcEwsItem { Id = uploadItemsResponseMessageType.ItemId.Id, Data = elcEwsItem.Data, Error = null, StorageItemData = elcEwsItem.StorageItemData }); } return(true); }, (Exception exception) => ElcEwsClient.WrapElcEwsException(ElcEwsErrorType.FailedToUploadItem, exception)); return(returnedItems); }