Inheritance: BaseFolderType
コード例 #1
0
        /// <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;
        }