Inheritance: BaseRequestType
        /// <summary>
        /// Create a new folder within a specific folder.
        /// </summary>
        /// <param name="request">Request of CreateFolder operation.</param>
        /// <returns>Response of CreateFolder operation.</returns>
        public CreateFolderResponseType CreateFolder(CreateFolderType request)
        {
            // Send the request and get the response.
            CreateFolderResponseType response = this.exchangeServiceBinding.CreateFolder(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 CreateFolderAsync(CreateFolderType CreateFolder1, object userState)
 {
     if ((this.CreateFolderOperationCompleted == null))
     {
         this.CreateFolderOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateFolderOperationCompleted);
     }
     this.InvokeAsync("CreateFolder", new object[] {
             CreateFolder1}, this.CreateFolderOperationCompleted, userState);
 }
Exemplo n.º 3
0
 /// <remarks/>
 public void CreateFolderAsync(CreateFolderType CreateFolder1)
 {
     this.CreateFolderAsync(CreateFolder1, null);
 }
Exemplo n.º 4
0
 /// <remarks/>
 public System.IAsyncResult BeginCreateFolder(CreateFolderType CreateFolder1, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("CreateFolder", new object[] {
             CreateFolder1}, callback, asyncState);
 }
        /// <summary>
        /// Create a new folder within a specific folder.
        /// </summary>
        /// <param name="request">Request of CreateFolder operation.</param>
        /// <returns>Response of CreateFolder operation.</returns>
        public CreateFolderResponseType CreateFolder(CreateFolderType request)
        {
            // Send the request and get the response.
            CreateFolderResponseType response = this.exchangeServiceBinding.CreateFolder(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.VerifyCreateFolderResponse(this.exchangeServiceBinding.IsSchemaValidated, response);
                this.VerifyAllRelatedRequirements(this.exchangeServiceBinding.IsSchemaValidated, response);
            }

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

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

            return response;
        }
        /// <summary>
        /// Log on to a mailbox with a specified user account and create two different-level subfolders in the specified parent 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="parentFolderName">Name of the parent folder.</param>
        /// <param name="firstLevelSubFolderName">Name of the first level sub folder which will be created under the parent folder.</param>
        /// <param name="secondLevelSubFolderName">Name of the second level sub folder which will be created under the first level sub folder.</param>
        /// <returns>If the two level sub folders are created successfully, return true; otherwise, return false.</returns>
        public bool CreateSubFolders(string userName, string userPassword, string userDomain, string parentFolderName, string firstLevelSubFolderName, string secondLevelSubFolderName)
        {
            // Log on mailbox with specified user account(userName, userPassword, userDomain).
            bool isLoged = AdapterHelper.SwitchUser(userName, userPassword, userDomain, this.exchangeServiceBinding, this.Site);
            Site.Assert.IsTrue(
                isLoged,
                string.Format("Log on mailbox with the UserName: {0}, Password: {1}, Domain: {2} should be successful.", userName, userPassword, userDomain));

            // Initialize variables
            FolderIdType folderId = null;
            CreateFolderType createFolderRequest = new CreateFolderType();
            string folderClassName = null;
            DistinguishedFolderIdNameType parentFolderIdName = (DistinguishedFolderIdNameType)Enum.Parse(typeof(DistinguishedFolderIdNameType), parentFolderName, true);

            // Define different folder class name according to different parent folder.
            switch (parentFolderIdName)
            {
                case DistinguishedFolderIdNameType.inbox:
                    folderClassName = "IPF.Note";
                    break;
                case DistinguishedFolderIdNameType.contacts:
                    folderClassName = "IPF.Contact";
                    break;
                case DistinguishedFolderIdNameType.calendar:
                    folderClassName = "IPF.Appointment";
                    break;
                case DistinguishedFolderIdNameType.tasks:
                    folderClassName = "IPF.Task";
                    break;
                default:
                    Site.Assume.Fail(string.Format("The parent folder name '{0}' is invalid. Valid values are: inbox, contacts, calendar or tasks.", parentFolderName));
                    break;
            }

            // Set parent folder ID.
            createFolderRequest.ParentFolderId = new TargetFolderIdType();
            DistinguishedFolderIdType parentFolder = new DistinguishedFolderIdType();
            parentFolder.Id = parentFolderIdName;
            createFolderRequest.ParentFolderId.Item = parentFolder;

            // Set Display Name and Folder Class for the folder to be created.
            FolderType folderProperties = new FolderType();
            folderProperties.DisplayName = firstLevelSubFolderName;
            folderProperties.FolderClass = folderClassName;

            createFolderRequest.Folders = new BaseFolderType[1];
            createFolderRequest.Folders[0] = folderProperties;

            bool isSubFolderCreated = false;

            // Invoke CreateFolder operation and get the response.
            CreateFolderResponseType createFolderResponse = this.exchangeServiceBinding.CreateFolder(createFolderRequest);

            if (createFolderResponse != null && ResponseClassType.Success == createFolderResponse.ResponseMessages.Items[0].ResponseClass)
            {
                // If the first level sub folder is created successfully, save the folder ID of it.
                folderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
                FolderType created = new FolderType() { DisplayName = folderProperties.DisplayName, FolderClass = folderClassName, FolderId = folderId };
                AdapterHelper.CreatedFolders.Add(created);
            }

            // Create another sub folder under the created folder above.
            if (folderId != null)
            {
                createFolderRequest.ParentFolderId.Item = folderId;
                folderProperties.DisplayName = secondLevelSubFolderName;

                createFolderResponse = this.exchangeServiceBinding.CreateFolder(createFolderRequest);

                if (createFolderResponse != null && ResponseClassType.Success == createFolderResponse.ResponseMessages.Items[0].ResponseClass)
                {
                    // If the two level sub folders are created successfully, return true; otherwise, return false.
                    isSubFolderCreated = true;
                    folderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
                    FolderType created = new FolderType() { DisplayName = folderProperties.DisplayName, FolderClass = folderClassName, FolderId = folderId };
                    AdapterHelper.CreatedFolders.Add(created);
                }
            }

            return isSubFolderCreated;
        }
        /// <summary>
        /// Log on to a mailbox with a specified user account and create a search 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="searchFolderName">Name of the search folder.</param>
        /// <param name="searchText">Search text of the search folder.</param>
        /// <returns>If the search folder is created successfully, return true; otherwise, return false.</returns>
        public bool CreateSearchFolder(string userName, string userPassword, string userDomain, string searchFolderName, string searchText)
        {
            // Log on mailbox with specified user account(userName, userPassword, userDomain).
            bool isLoged = AdapterHelper.SwitchUser(userName, userPassword, userDomain, this.exchangeServiceBinding, this.Site);
            Site.Assert.IsTrue(
                isLoged,
                string.Format("Log on mailbox with the UserName: {0}, Password: {1}, Domain: {2} should be successful.", userName, userPassword, userDomain));

            // Create the request.
            CreateFolderType createFolder = new CreateFolderType();
            SearchFolderType[] folderArray = new SearchFolderType[1];
            SearchFolderType searchFolder = new SearchFolderType();

            // Use the following search filter to get all mail in the Inbox with the word searchText in the subject line.
            searchFolder.SearchParameters = new SearchParametersType();
            searchFolder.SearchParameters.Traversal = SearchFolderTraversalType.Deep;
            searchFolder.SearchParameters.TraversalSpecified = true;
            searchFolder.SearchParameters.BaseFolderIds = new DistinguishedFolderIdType[4];

            // Create a distinguished folder Identified of the inbox folder.
            DistinguishedFolderIdType inboxFolder = new DistinguishedFolderIdType();
            inboxFolder.Id = new DistinguishedFolderIdNameType();
            inboxFolder.Id = DistinguishedFolderIdNameType.inbox;
            searchFolder.SearchParameters.BaseFolderIds[0] = inboxFolder;
            DistinguishedFolderIdType contactType = new DistinguishedFolderIdType();
            contactType.Id = new DistinguishedFolderIdNameType();
            contactType.Id = DistinguishedFolderIdNameType.contacts;
            searchFolder.SearchParameters.BaseFolderIds[1] = contactType;
            DistinguishedFolderIdType calendarType = new DistinguishedFolderIdType();
            calendarType.Id = new DistinguishedFolderIdNameType();
            calendarType.Id = DistinguishedFolderIdNameType.calendar;
            searchFolder.SearchParameters.BaseFolderIds[2] = calendarType;
            DistinguishedFolderIdType taskType = new DistinguishedFolderIdType();
            taskType.Id = new DistinguishedFolderIdNameType();
            taskType.Id = DistinguishedFolderIdNameType.calendar;
            searchFolder.SearchParameters.BaseFolderIds[3] = taskType;

            // Use the following search filter.
            searchFolder.SearchParameters.Restriction = new RestrictionType();
            PathToUnindexedFieldType path = new PathToUnindexedFieldType();
            path.FieldURI = UnindexedFieldURIType.itemSubject;
            RestrictionType restriction = new RestrictionType();
            FieldURIOrConstantType fieldURIORConstant = new FieldURIOrConstantType();
            fieldURIORConstant.Item = new ConstantValueType();
            (fieldURIORConstant.Item as ConstantValueType).Value = searchText;
            ExistsType isEqual = new ExistsType();
            isEqual.Item = path;
            restriction.Item = isEqual;
            searchFolder.SearchParameters.Restriction = restriction;

            // Give the search folder a unique name.
            searchFolder.DisplayName = searchFolderName;
            folderArray[0] = searchFolder;

            // Create the search folder under the default Search Folder.
            TargetFolderIdType targetFolder = new TargetFolderIdType();
            DistinguishedFolderIdType searchFolders = new DistinguishedFolderIdType();
            searchFolders.Id = DistinguishedFolderIdNameType.searchfolders;
            targetFolder.Item = searchFolders;
            createFolder.ParentFolderId = targetFolder;
            createFolder.Folders = folderArray;
            bool isSearchFolderCreated = false;

            // Invoke CreateFolder operation and get the response.
            CreateFolderResponseType response = this.exchangeServiceBinding.CreateFolder(createFolder);
            if (response != null && ResponseClassType.Success == response.ResponseMessages.Items[0].ResponseClass)
            {
                // If the search folder is created successfully, return true; otherwise, return false.
                isSearchFolderCreated = true;

                searchFolder.FolderId = ((FolderInfoResponseMessageType)response.ResponseMessages.Items[0]).Folders[0].FolderId;
                AdapterHelper.CreatedFolders.Add(searchFolder);
            }

            return isSearchFolderCreated;
        }
        /// <summary>
        /// Generate the request message for operation "CreateFolder".
        /// </summary>
        /// <param name="parentFolderId">The folder identifier for the parent folder.</param>
        /// <param name="folderNames">An array of display name of the folders to be created.</param>
        /// <param name="folderClasses">An array of folder class value of the folders to be created.</param>
        /// <param name="permissionSet">An array of permission set value of the folder.</param>
        /// <returns>Create folder request instance that will send to server.</returns>
        protected CreateFolderType GetCreateFolderRequest(string parentFolderId, string[] folderNames, string[] folderClasses, PermissionSetType[] permissionSet)
        {
            CreateFolderType createFolderRequest = new CreateFolderType();
            createFolderRequest.ParentFolderId = new TargetFolderIdType();

            DistinguishedFolderIdType distinguishedFolderId = new DistinguishedFolderIdType();
            DistinguishedFolderIdNameType distinguishedFolderIdName = new DistinguishedFolderIdNameType();
            bool isSuccess = Enum.TryParse<DistinguishedFolderIdNameType>(parentFolderId, true, out distinguishedFolderIdName);

            if (isSuccess)
            {
                distinguishedFolderId.Id = distinguishedFolderIdName;
                createFolderRequest.ParentFolderId.Item = distinguishedFolderId;
            }
            else
            {
                FolderIdType id = new FolderIdType();
                id.Id = parentFolderId;
                createFolderRequest.ParentFolderId.Item = id;
            }

            createFolderRequest = this.ConfigureFolderProperty(folderNames, folderClasses, permissionSet, createFolderRequest);

            return createFolderRequest;
        }
        /// <summary>
        /// Set related folder properties of create folder request
        /// </summary>
        /// <param name="displayNames">Display names of folders that will be set into create folder request.</param>
        /// <param name="folderClasses">Folder class values of folders that will be set into create folder request.</param>
        /// <param name="folderPermissions">Folder permission values of folders that will be set into create folder request. </param>
        /// <param name="createFolderRequest">Create folder request instance that needs to set property values.</param>
        /// <returns>Create folder request instance that have folder property value configured.</returns>
        protected CreateFolderType ConfigureFolderProperty(string[] displayNames, string[] folderClasses, PermissionSetType[] folderPermissions, CreateFolderType createFolderRequest)
        {
            Site.Assert.IsNotNull(displayNames, "Display names should not be null!");
            Site.Assert.IsNotNull(folderClasses, "Folder classes should not be null!");
            Site.Assert.AreEqual<int>(displayNames.Length, folderClasses.Length, "Folder names count should equals to folder class value count!");
            if (folderPermissions != null)
            {
                Site.Assert.AreEqual<int>(displayNames.Length, folderPermissions.Length, "Folder names count should equals to folder permission value count!");
            }

            int folderCount = displayNames.Length;
            createFolderRequest.Folders = new BaseFolderType[folderCount];
            for (int folderPropertyIndex = 0; folderPropertyIndex < folderCount; folderPropertyIndex++)
            {
                string folderResourceName = Common.GenerateResourceName(this.Site, displayNames[folderPropertyIndex]);

                if (folderClasses[folderPropertyIndex] == "IPF.Appointment")
                {
                    CalendarFolderType calendarFolder = new CalendarFolderType();
                    calendarFolder.DisplayName = folderResourceName;
                    createFolderRequest.Folders[folderPropertyIndex] = calendarFolder;
                }
                else if (folderClasses[folderPropertyIndex] == "IPF.Contact")
                {
                    ContactsFolderType contactFolder = new ContactsFolderType();
                    contactFolder.DisplayName = folderResourceName;
                    if (folderPermissions != null)
                    {
                        contactFolder.PermissionSet = folderPermissions[folderPropertyIndex];
                    }

                    createFolderRequest.Folders[folderPropertyIndex] = contactFolder;
                }
                else if (folderClasses[folderPropertyIndex] == "IPF.Task")
                {
                    TasksFolderType taskFolder = new TasksFolderType();
                    taskFolder.DisplayName = folderResourceName;
                    if (folderPermissions != null)
                    {
                        taskFolder.PermissionSet = folderPermissions[folderPropertyIndex];
                    }

                    createFolderRequest.Folders[folderPropertyIndex] = taskFolder;
                }
                else if (folderClasses[folderPropertyIndex] == "IPF.Search")
                {
                    SearchFolderType searchFolder = new SearchFolderType();
                    searchFolder.DisplayName = folderResourceName;

                    // Set search parameters.
                    searchFolder.SearchParameters = new SearchParametersType();
                    searchFolder.SearchParameters.Traversal = SearchFolderTraversalType.Deep;
                    searchFolder.SearchParameters.TraversalSpecified = true;
                    searchFolder.SearchParameters.BaseFolderIds = new DistinguishedFolderIdType[1];
                    DistinguishedFolderIdType inboxType = new DistinguishedFolderIdType();
                    inboxType.Id = new DistinguishedFolderIdNameType();
                    inboxType.Id = DistinguishedFolderIdNameType.inbox;
                    searchFolder.SearchParameters.BaseFolderIds[0] = inboxType;

                    // Use the following search filter 
                    searchFolder.SearchParameters.Restriction = new RestrictionType();
                    PathToUnindexedFieldType path = new PathToUnindexedFieldType();
                    path.FieldURI = UnindexedFieldURIType.itemSubject;
                    RestrictionType restriction = new RestrictionType();
                    ExistsType isEqual = new ExistsType();
                    isEqual.Item = path;
                    restriction.Item = isEqual;
                    searchFolder.SearchParameters.Restriction = restriction;

                    if (folderPermissions != null)
                    {
                        searchFolder.PermissionSet = folderPermissions[folderPropertyIndex];
                    }

                    createFolderRequest.Folders[folderPropertyIndex] = searchFolder;
                }
                else
                {
                    // Set Display Name and Folder Class for the folder to be created.
                    FolderType folder = new FolderType();
                    folder.DisplayName = folderResourceName;
                    folder.FolderClass = folderClasses[folderPropertyIndex];

                    if (folderPermissions != null)
                    {
                        folder.PermissionSet = folderPermissions[folderPropertyIndex];
                    }

                    createFolderRequest.Folders[folderPropertyIndex] = folder;
                }
            }

            return createFolderRequest;
        }
        /// <summary>
        /// Create a sub folder in the specified parent folder.
        /// </summary>
        /// <param name="parentFolderType">Type of the parent folder.</param>
        /// <param name="subFolderName">Name of the folder which should be created.</param>
        /// <returns>ID of the new created sub folder.</returns>
        protected string CreateSubFolder(DistinguishedFolderIdNameType parentFolderType, string subFolderName)
        {
            // Variable to specified the created sub folder ID and the folder class name.
            string subFolderId = null;
            string folderClassName = null;

            // Set the folder's class name according to the type of parent folder.
            switch (parentFolderType)
            {
                case DistinguishedFolderIdNameType.contacts:
                    folderClassName = "IPF.Contact";
                    break;
                case DistinguishedFolderIdNameType.calendar:
                    folderClassName = "IPF.Appointment";
                    break;
                case DistinguishedFolderIdNameType.tasks:
                    folderClassName = "IPF.Task";
                    break;
                case DistinguishedFolderIdNameType.inbox:
                    folderClassName = "IPF.Note";
                    break;
                default:
                    Site.Assert.Fail(@"The parent folder type '{0}' is invalid.The valid folder types are: contacts, calendar, tasks and inbox", parentFolderType);
                    break;
            }

            // Initialize the create folder request.
            CreateFolderType createFolderRequest = new CreateFolderType();
            FolderType folderProperties = new FolderType();

            // Set parent folder id.
            createFolderRequest.ParentFolderId = new TargetFolderIdType();
            DistinguishedFolderIdType parentFolder = new DistinguishedFolderIdType();
            parentFolder.Id = parentFolderType;
            createFolderRequest.ParentFolderId.Item = parentFolder;

            // Set Display Name and Folder Class for the folder to be created.
            folderProperties.DisplayName = subFolderName;
            folderProperties.FolderClass = folderClassName;

            // Set permission.
            folderProperties.PermissionSet = new PermissionSetType();
            folderProperties.PermissionSet.Permissions = new PermissionType[1];
            folderProperties.PermissionSet.Permissions[0] = new PermissionType();
            folderProperties.PermissionSet.Permissions[0].CanCreateItems = true;
            folderProperties.PermissionSet.Permissions[0].CanCreateSubFolders = true;
            folderProperties.PermissionSet.Permissions[0].PermissionLevel = new PermissionLevelType();
            folderProperties.PermissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Editor;
            folderProperties.PermissionSet.Permissions[0].UserId = new UserIdType();

            string primaryUserName = Common.GetConfigurationPropertyValue("UserName", this.Site);
            string primaryDomain = Common.GetConfigurationPropertyValue("Domain", this.Site);
            folderProperties.PermissionSet.Permissions[0].UserId.PrimarySmtpAddress = primaryUserName + "@" + primaryDomain;

            createFolderRequest.Folders = new BaseFolderType[1];
            createFolderRequest.Folders[0] = folderProperties;

            // Invoke CreateFolder operation and get the response.
            CreateFolderResponseType createFolderResponse = this.FOLDAdapter.CreateFolder(createFolderRequest);

            if (createFolderResponse != null && createFolderResponse.ResponseMessages.Items[0].ResponseClass.ToString() == ResponseClassType.Success.ToString())
            {
                FolderIdType folderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
                subFolderId = folderId.Id;
                FolderType created = new FolderType() { DisplayName = folderProperties.DisplayName, FolderClass = folderClassName, FolderId = folderId, ParentFolderId = new FolderIdType() { Id = parentFolder.Id.ToString() } };
                this.CreatedFolders.Add(created);
            }

            return subFolderId;
        }
        /// <summary>
        /// Creates folders on the server.
        /// </summary>
        /// <param name="createFolderRequest">Specify the request for the CreateFolder operation.</param>
        /// <returns>The response to this operation request.</returns>
        public CreateFolderResponseType CreateFolder(CreateFolderType createFolderRequest)
        {
            if (createFolderRequest == null)
            {
                throw new ArgumentException("The CreateFolder request should not be null.");
            }

            // Send the request and get the response.
            CreateFolderResponseType response = this.exchangeServiceBinding.CreateFolder(createFolderRequest);
            return response;
        }