Inheritance: BaseRequestType
        /// <summary>
        /// Delete a folder from mailbox.
        /// </summary>
        /// <param name="request">Request DeleteFolder operation.</param>
        /// <returns>Response of DeleteFolder operation.</returns>
        public DeleteFolderResponseType DeleteFolder(DeleteFolderType request)
        {
            // Send the request and get the response.
            DeleteFolderResponseType response = this.exchangeServiceBinding.DeleteFolder(request);
            Site.Assert.IsNotNull(response, "If the operation is successful, the response should not be null.");

            return response;
        }
Exemplo n.º 2
0
 /// <remarks/>
 public void DeleteFolderAsync(DeleteFolderType DeleteFolder1, object userState)
 {
     if ((this.DeleteFolderOperationCompleted == null))
     {
         this.DeleteFolderOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDeleteFolderOperationCompleted);
     }
     this.InvokeAsync("DeleteFolder", new object[] {
             DeleteFolder1}, this.DeleteFolderOperationCompleted, userState);
 }
Exemplo n.º 3
0
 /// <remarks/>
 public void DeleteFolderAsync(DeleteFolderType DeleteFolder1)
 {
     this.DeleteFolderAsync(DeleteFolder1, null);
 }
Exemplo n.º 4
0
 /// <remarks/>
 public System.IAsyncResult BeginDeleteFolder(DeleteFolderType DeleteFolder1, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("DeleteFolder", new object[] {
             DeleteFolder1}, callback, asyncState);
 }
        /// <summary>
        /// Delete a folder from mailbox.
        /// </summary>
        /// <param name="request">Request DeleteFolder operation.</param>
        /// <returns>Response of DeleteFolder operation.</returns>
        public DeleteFolderResponseType DeleteFolder(DeleteFolderType request)
        {
            // Send the request and get the response.
            DeleteFolderResponseType response = this.exchangeServiceBinding.DeleteFolder(request);
            Site.Assert.IsNotNull(response, "If the operation is successful, the response should not be null.");

            if (ResponseClassType.Success == response.ResponseMessages.Items[0].ResponseClass)
            {
                this.VerifyDeleteFolderResponse(this.exchangeServiceBinding.IsSchemaValidated);
                this.VerifyAllRelatedRequirements(this.exchangeServiceBinding.IsSchemaValidated, response);
            }

            // Verify transport type related requirement.
            this.VerifyTransportType();

            // Verify soap version.
            this.VerifySoapVersion();

            return response;
        }
        /// <summary>
        /// Generate the request message for operation "DeleteFolder".
        /// </summary>
        /// <param name="deleteType">How folders are to be deleted.</param>
        /// <param name="folderIds">An array of folder identifier of the folders need to be deleted</param>
        /// <returns>Delete folder request instance that will send to server.</returns>
        protected DeleteFolderType GetDeleteFolderRequest(DisposalType deleteType, params BaseFolderIdType[] folderIds)
        {
            Site.Assert.IsNotNull(folderIds, "Folders id should not be null!");
            Site.Assert.AreNotEqual<int>(0, folderIds.Length, "Folders id should contains at least one Id!");
            DeleteFolderType deleteFolderRequest = new DeleteFolderType();

            // Specify the delete type.
            deleteFolderRequest.DeleteType = deleteType;
            int folderCount = folderIds.Length;

            // Set the request's folderId field.
            deleteFolderRequest.FolderIds = new BaseFolderIdType[folderCount];
            for (int folderIdIndex = 0; folderIdIndex < folderCount; folderIdIndex++)
            {
                deleteFolderRequest.FolderIds[folderIdIndex] = folderIds[folderIdIndex];
            }

            return deleteFolderRequest;
        }
        /// <summary>
        /// Clean up the environment.
        /// </summary>
        protected override void TestCleanup()
        {
            // Ensure use the right user to clean up.
            #region Switch user

            this.SwitchUser(Common.GetConfigurationPropertyValue("User1Name", this.Site), Common.GetConfigurationPropertyValue("User1Password", this.Site), Common.GetConfigurationPropertyValue("Domain", this.Site));

            #endregion

            // Following codes shall be run after every test case execution.
            #region Delete the new created folder to make sure each case run at the same environment.

            // Clean up all created folders.
            if (this.newCreatedFolderIds.Count > 0)
            {
                for (int temp = 0; temp < this.newCreatedFolderIds.Count; temp++)
                {
                    // Delete folder request.
                    DeleteFolderType deleteFolderRequest = new DeleteFolderType();

                    // Specify the delete type.
                    deleteFolderRequest.DeleteType = DisposalType.HardDelete;

                    // Set the deleteFolderRequest's folderId type.
                    deleteFolderRequest.FolderIds = new BaseFolderIdType[1];
                    deleteFolderRequest.FolderIds[0] = this.newCreatedFolderIds[temp];

                    // Delete the specified folder.
                    this.FOLDAdapter.DeleteFolder(deleteFolderRequest);
                }
            }

            // Clean up all created items.
            if (this.newCreatedItemIds.Count > 0)
            {
                for (int temp = 0; temp < this.newCreatedItemIds.Count; temp++)
                {
                    this.DeleteItem(this.newCreatedItemIds[temp]);
                }
            }

            #endregion
        }
        /// <summary>
        /// Deletes all items and sub folders from the specified folder.
        /// </summary>
        /// <param name="folderName">Name of the specified parent folder.</param>
        /// <param name="needVerify">If need to verify the subfolders,when false,it will cleanup all the folders without verify</param>
        /// <returns>If the specified folder is cleaned up successfully, return true; otherwise, return false.</returns>
        private bool CleanupFolder(DistinguishedFolderIdNameType folderName, bool needVerify = true)
        {
            bool isAllItemsAndFoldersDeleted = false;
            ItemType[] items = this.FindAllItems(folderName);

            // Create a request for the DeleteItem operation.
            DeleteItemType deleteItemRequest = new DeleteItemType();

            // The item is permanently removed from the store.
            deleteItemRequest.DeleteType = DisposalType.HardDelete;

            // Do not send meeting cancellations.
            deleteItemRequest.SendMeetingCancellations = CalendarItemCreateOrDeleteOperationType.SendToNone;
            deleteItemRequest.SendMeetingCancellationsSpecified = true;

            if (items != null)
            {
                foreach (ItemType currentItem in items)
                {
                    if (currentItem.GetType() == typeof(TaskType))
                    {
                        deleteItemRequest.AffectedTaskOccurrencesSpecified = true;
                        deleteItemRequest.AffectedTaskOccurrences = AffectedTaskOccurrencesType.AllOccurrences;
                    }

                    deleteItemRequest.ItemIds = new BaseItemIdType[] { currentItem.ItemId };

                    // Invoke the delete item operation.
                    DeleteItemResponseType response = this.exchangeServiceBinding.DeleteItem(deleteItemRequest);

                    Site.Assert.AreEqual<ResponseClassType>(
                            ResponseClassType.Success,
                            response.ResponseMessages.Items[0].ResponseClass,
                            "The delete item operation should execute successfully.");
                }
            }

            // Find all sub folders in the specified folder.
            BaseFolderType[] folders = this.FindAllSubFolders(folderName);

            if (folders.Length != 0)
            {
                foreach (BaseFolderType currentFolder in folders)
                {
                    if (needVerify)
                    {
                        bool isCreatedByCase = false;
                        AdapterHelper.CreatedFolders.ForEach(r =>
                        {
                            if (r.FolderId.Id == currentFolder.FolderId.Id)
                            {
                                isCreatedByCase = true;
                            }
                        });

                        if (!isCreatedByCase)
                        {
                            continue;
                        }
                    }

                    FolderIdType responseFolderId = currentFolder.FolderId;

                    FolderIdType folderId = new FolderIdType();
                    folderId.Id = responseFolderId.Id;

                    DeleteFolderType deleteFolderRequest = new DeleteFolderType();
                    deleteFolderRequest.DeleteType = DisposalType.HardDelete;
                    deleteFolderRequest.FolderIds = new BaseFolderIdType[1];
                    deleteFolderRequest.FolderIds[0] = folderId;

                    // Send the request and get the response.
                    DeleteFolderResponseType deleteFolderResponse = this.exchangeServiceBinding.DeleteFolder(deleteFolderRequest);

                    // Delete folder operation should return response info.
                    if (deleteFolderResponse.ResponseMessages.Items[0] != null)
                    {
                        Site.Assert.AreEqual<ResponseClassType>(
                            ResponseClassType.Success,
                            deleteFolderResponse.ResponseMessages.Items[0].ResponseClass,
                            "The delete folder operation should be successful.");
                    }
                }
            }

            // Invoke the FindItem operation.
            items = this.FindAllItems(folderName);

            // Invoke the FindFolder operation.
            folders = this.FindAllSubFolders(folderName);

            // If neither items and sub folders could be found, the folder has been cleaned up successfully.
            bool allFoldersBelongstoSys = true;

            foreach (BaseFolderType folder in folders)
            {               
                bool find = false;
                AdapterHelper.CreatedFolders.ForEach(r =>
                {
                    if (r.FolderId.Id == folder.FolderId.Id)
                    {
                        find = true;
                    }
                });

                if (find)
                {
                    allFoldersBelongstoSys = false;
                    break;
                }
            }

            if (items == null && (folders.Length == 0 || allFoldersBelongstoSys))
            {
                isAllItemsAndFoldersDeleted = true;
            }

            return isAllItemsAndFoldersDeleted;
        }
        /// <summary>
        /// Log on to a mailbox with a specified user account and find the specified folder, then delete it if it is found.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <param name="userPassword">Password of the user.</param>
        /// <param name="userDomain">Domain of the user.</param>
        /// <param name="parentFolderName">Name of the parent folder.</param>
        /// <param name="subFolderName">Name of the folder which will be updated.</param>
        /// <returns>If the folder is deleted successfully, return true; otherwise, return false.</returns>
        public bool FindAndDeleteSubFolder(string userName, string userPassword, string userDomain, string parentFolderName, string subFolderName)
        {
            // Switch to specified user mailbox.
            bool isSwitched = AdapterHelper.SwitchUser(userName, userPassword, userDomain, this.exchangeServiceBinding, this.Site);
            Site.Assert.IsTrue(
                isSwitched,
                string.Format("Log on mailbox with the UserName: {0}, Password: {1}, Domain: {2} should be successful.", userName, userPassword, userDomain));

            // Parse the parent folder name to DistinguishedFolderIdNameType.
            DistinguishedFolderIdNameType parentFolderIdName = (DistinguishedFolderIdNameType)Enum.Parse(typeof(DistinguishedFolderIdNameType), parentFolderName, true);

            DeleteFolderType deleteFolderRequest = new DeleteFolderType();
            deleteFolderRequest.DeleteType = DisposalType.HardDelete;
            deleteFolderRequest.FolderIds = new BaseFolderIdType[1];
            deleteFolderRequest.FolderIds[0] = this.FindSubFolder(parentFolderIdName, subFolderName);

            // Invoke the DeleteFolder operation and get the response.
            DeleteFolderResponseType deleteFolderResponse = this.exchangeServiceBinding.DeleteFolder(deleteFolderRequest);

            bool isDeleted = false;
            if (deleteFolderResponse != null && deleteFolderResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
            {
                // If the DeleteFolder operation succeeds, return true.
                isDeleted = true;
            }

            return isDeleted;
        }
        /// <summary>
        /// Log on to a mailbox with a specified user account and delete all the subfolders from the specified folder.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <param name="userPassword">Password of the user.</param>
        /// <param name="userDomain">Domain of the user.</param>
        /// <param name="folderName">Name of the folder which should be cleaned up.</param>
        /// <param name="destFolderName">The name of the destination folder which will be deleted.</param>
        /// <returns>If the folder is cleaned up successfully, return true; otherwise, return false.</returns>
        public bool CleanupFolder(string userName, string userPassword, string userDomain, string folderName, string destFolderName)
        {
            // Log on mailbox with specified user mailbox.
            this.exchangeServiceBinding.Credentials = new NetworkCredential(userName, userPassword, userDomain);
            #region Delete all sub folders and the items in these sub folders in the specified parent folder.
            // Parse the parent folder name.
            DistinguishedFolderIdNameType parentFolderName = (DistinguishedFolderIdNameType)Enum.Parse(typeof(DistinguishedFolderIdNameType), folderName, true);

            // Create an array of BaseFolderType.
            BaseFolderType[] folders = null;

            // Create the request and specify the traversal type.
            FindFolderType findFolderRequest = new FindFolderType();
            findFolderRequest.Traversal = FolderQueryTraversalType.Deep;

            // Define the properties to be returned in the response.
            FolderResponseShapeType responseShape = new FolderResponseShapeType();
            responseShape.BaseShape = DefaultShapeNamesType.Default;
            findFolderRequest.FolderShape = responseShape;

            // Identify which folders to search.
            DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
            folderIDArray[0] = new DistinguishedFolderIdType();
            folderIDArray[0].Id = parentFolderName;

            // Add the folders to search to the request.
            findFolderRequest.ParentFolderIds = folderIDArray;

            // Invoke FindFolder operation and get the response.
            FindFolderResponseType findFolderResponse = this.exchangeServiceBinding.FindFolder(findFolderRequest);

            // If there are folders found under the specified folder, delete all of them.
            if (findFolderResponse != null && findFolderResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
            {
                // Get the folders from the response.
                FindFolderResponseMessageType findFolderResponseMessageType = findFolderResponse.ResponseMessages.Items[0] as FindFolderResponseMessageType;
                Site.Assert.IsNotNull(findFolderResponseMessageType, "The items in FindFolder response should not be null.");

                folders = findFolderResponseMessageType.RootFolder.Folders;
                if (folders.Length != 0)
                {
                    ////Indicates whether the destination folder was found and removed.
                    bool found = false;

                    // Loop to delete all the found folders.
                    foreach (BaseFolderType currentFolder in folders)
                    {
                        if (string.Compare(currentFolder.DisplayName, destFolderName, StringComparison.InvariantCultureIgnoreCase) != 0)
                        {
                            continue;
                        }

                        FolderIdType responseFolderId = currentFolder.FolderId;

                        FolderIdType folderId = new FolderIdType();
                        folderId.Id = responseFolderId.Id;

                        DeleteFolderType deleteFolderRequest = new DeleteFolderType();
                        deleteFolderRequest.DeleteType = DisposalType.HardDelete;
                        deleteFolderRequest.FolderIds = new BaseFolderIdType[1];
                        deleteFolderRequest.FolderIds[0] = folderId;

                        // Invoke DeleteFolder operation and get the response.
                        DeleteFolderResponseType deleteFolderResponse = this.exchangeServiceBinding.DeleteFolder(deleteFolderRequest);

                        Site.Assert.AreEqual<ResponseClassType>(
                            ResponseClassType.Success,
                            deleteFolderResponse.ResponseMessages.Items[0].ResponseClass,
                            "The delete folder operation should be successful.");

                        found = true;
                        break;
                    }

                    Site.Assert.IsTrue(
                           found,
                           "The destination folder can not be found in the assigned parent folder.");
                }
            }
            #endregion

            #region Check whether sub folders are deleted successfully.
            // Invoke the FindFolder operation again.
            findFolderResponse = this.exchangeServiceBinding.FindFolder(findFolderRequest);

            Site.Assert.AreEqual<ResponseCodeType>(
                ResponseCodeType.NoError,
                findFolderResponse.ResponseMessages.Items[0].ResponseCode,
                string.Format(
                "The delete folder operation should be successful. Expected response code: {0}, actual response code: {1}",
                ResponseCodeType.NoError,
                findFolderResponse.ResponseMessages.Items[0].ResponseCode));

            // Get the found folders from the response.
            FindFolderResponseMessageType findFolderResponseMessage = findFolderResponse.ResponseMessages.Items[0] as FindFolderResponseMessageType;
            folders = findFolderResponseMessage.RootFolder.Folders;

            // If no sub folders that created by case could be found, the folder has been cleaned up successfully.
            foreach (BaseFolderType folder in folders)
            {
                if (string.Compare(folder.DisplayName, destFolderName, StringComparison.InvariantCultureIgnoreCase) != 0)
                {
                    continue;
                }
                else
                {
                    return false;
                }
            }

            return true;
            #endregion
        }