Inheritance: BaseRequestType
Esempio n. 1
0
 /// <remarks/>
 public void FindFolderAsync(FindFolderType FindFolder1)
 {
     this.FindFolderAsync(FindFolder1, null);
 }
Esempio n. 2
0
 /// <remarks/>
 public void FindFolderAsync(FindFolderType FindFolder1, object userState)
 {
     if ((this.FindFolderOperationCompleted == null))
     {
         this.FindFolderOperationCompleted = new System.Threading.SendOrPostCallback(this.OnFindFolderOperationCompleted);
     }
     this.InvokeAsync("FindFolder", new object[] {
             FindFolder1}, this.FindFolderOperationCompleted, userState);
 }
Esempio n. 3
0
 /// <remarks/>
 public System.IAsyncResult BeginFindFolder(FindFolderType FindFolder1, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("FindFolder", new object[] {
             FindFolder1}, callback, asyncState);
 }
        /// <summary>
        /// Search specific folders.
        /// </summary>
        /// <param name="findRequest">Specify a request for a FindFolder operation</param>
        /// <returns>A response to FindFolder operation request</returns>
        public FindFolderResponseType FindFolder(FindFolderType findRequest)
        {
            FindFolderResponseType findResponse = this.exchangeServiceBinding.FindFolder(findRequest);

            return findResponse; 
        }
        public void MSOXWSCORE_S04_TC23_VerifyPublicFolderItem()
        {
            FolderIdType folderId = null;

            FindFolderType findRequest = new FindFolderType();
            findRequest.FolderShape = new FolderResponseShapeType();
            findRequest.FolderShape.BaseShape = DefaultShapeNamesType.AllProperties;
            DistinguishedFolderIdType id = new DistinguishedFolderIdType();
            id.Id = DistinguishedFolderIdNameType.publicfoldersroot;
            findRequest.ParentFolderIds = new DistinguishedFolderIdType[] { id };
            findRequest.Traversal = FolderQueryTraversalType.Shallow;

            BaseFolderType[] folders = null;
            FindFolderResponseType findFolderResponse = this.SRCHAdapter.FindFolder(findRequest);
            FindFolderResponseMessageType findFolderResponseMessageType = new FindFolderResponseMessageType();
            if (findFolderResponse != null && findFolderResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
            {
                findFolderResponseMessageType = findFolderResponse.ResponseMessages.Items[0] as FindFolderResponseMessageType;
                folders = findFolderResponseMessageType.RootFolder.Folders;
                foreach (BaseFolderType folder in folders)
                {
                    if (folder.DisplayName.Equals(Common.GetConfigurationPropertyValue("PublicFolderName", this.Site)))
                    {
                        folderId = folder.FolderId;
                    }
                }
            }

            Site.Assert.IsNotNull(
                folderId,
                "The destination public folder {0} in should exist!",
                Common.GetConfigurationPropertyValue("PublicFolderName", this.Site));

            MessageType message = new MessageType();
            MessageType[] items = new MessageType[] { message };
            CreateItemType requestItem = new CreateItemType();
            requestItem.MessageDispositionSpecified = true;
            requestItem.MessageDisposition = MessageDispositionType.SaveOnly;
            requestItem.Items = new NonEmptyArrayOfAllItemsType();
            requestItem.Items.Items = items;

            requestItem.SavedItemFolderId = new TargetFolderIdType();

            requestItem.SavedItemFolderId.Item = folderId;

            CreateItemResponseType createItemResponse = this.COREAdapter.CreateItem(requestItem);

            Common.CheckOperationSuccess(createItemResponse, 1, this.Site);

            ItemInfoResponseMessageType itemInfo = (ItemInfoResponseMessageType)createItemResponse.ResponseMessages.Items[0];
            ItemIdId itemId = this.ITEMIDAdapter.ParseItemId(itemInfo.Items.Items[0].ItemId);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSITEMID_R62");

            // Verify MS-OXWSITEMID requirement: MS-OXWSITEMID_R62
            Site.CaptureRequirementIfAreEqual<IdStorageType>(
                IdStorageType.PublicFolderItem,
                itemId.StorageType,
                "MS-OXWSITEMID",
                62,
                @"[In Id Storage Type (byte)] Its [Id Storage Type's] value maps to the following enumeration value.
                    /// <summary>
                    /// Indicates which type of storage is used for the item/folder represented by this Id.
                    /// </summary>
                    internal enum IdStorageType : byte
                    {
                [        /// <summary>
                        /// The Id represents an item or folder in a mailbox and 
                        /// it contains a primary SMTP address. 
                        /// </summary>
                        MailboxItemSmtpAddressBased = 0,

                        /// <summary>
                        /// The Id represents a folder in a PublicFolder store.
                        /// </summary>
                        PublicFolder = 1,]

                        /// <summary>
                        /// The Id represents an item in a PublicFolder store.
                        /// </summary>
                        PublicFolderItem = 2,
                [
                        /// <summary>
                        /// The Id represents an item or folder in a mailbox and contains a mailbox GUID.
                        /// </summary>
                        MailboxItemMailboxGuidBased = 3,

                        /// <summary>
                        /// The Id represents a conversation in a mailbox and contains a mailbox GUID.
                        /// </summary>
                        ConversationIdMailboxGuidBased = 4,

                        /// <summary>
                        /// The Id represents (by objectGuid) an object in the Active Directory.
                        /// </summary>
                        ActiveDirectoryObject = 5,]
                }");
        }
        /// <summary>
        /// Find all the sub folders in the specified folder.
        /// </summary>
        /// <param name="parentFolderName">Name of the specified parent folder.</param>
        /// <returns>An array of found sub folders.</returns>
        private BaseFolderType[] FindAllSubFolders(DistinguishedFolderIdNameType parentFolderName)
        {
            // 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;

            FindFolderResponseType findFolderResponse = this.exchangeServiceBinding.FindFolder(findFolderRequest);
            FindFolderResponseMessageType findFolderResponseMessageType = new FindFolderResponseMessageType();
            if (findFolderResponse != null && findFolderResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
            {
                findFolderResponseMessageType = findFolderResponse.ResponseMessages.Items[0] as FindFolderResponseMessageType;
                folders = findFolderResponseMessageType.RootFolder.Folders;
            }

            return folders;
        }
        /// <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
        }