/// <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);
        }
        private BaseFolderType GetWorkingFolder()
        {
            BaseFolderIdType parentFolderId = new DistinguishedFolderIdType
            {
                Id      = DistinguishedFolderIdNameType.msgfolderroot,
                Mailbox = new EmailAddressType
                {
                    EmailAddress = this.targetPrimarySmtpAddress
                }
            };
            string         text           = this.IsUnsearchable ? (this.workingLocation + ".unsearchable") : this.workingLocation;
            BaseFolderType baseFolderType = this.ewsClient.GetFolderByName(this.targetPrimarySmtpAddress, parentFolderId, text);

            if (baseFolderType == null)
            {
                FolderType folderType = new FolderType
                {
                    DisplayName = text
                };
                folderType.ExtendedProperty = new ExtendedPropertyType[]
                {
                    MailboxItemIdList.IsHiddenExtendedProperty
                };
                List <BaseFolderType> list = this.ewsClient.CreateFolder(this.targetPrimarySmtpAddress, parentFolderId, new BaseFolderType[]
                {
                    folderType
                });
                baseFolderType = list[0];
            }
            return(baseFolderType);
        }
        /// <summary>
        /// Creates a request for the SyncFolderHierarchy operation.
        /// </summary>
        /// <param name="folder">A default folder name.</param>
        /// <param name="defaultShapeNames">Standard sets of properties to return.</param>
        /// <param name="isSyncFolderIdPresent">A Boolean value indicates whether the SyncFolderId element present in the request.</param>
        /// <param name="isSyncStatePresent">A Boolean value indicates whether the SyncState element present in the request.</param>
        /// <returns>An instance of SyncFolderHierarchyType used by the SyncFolderHierarchy operation.</returns>
        public static SyncFolderHierarchyType CreateSyncFolderHierarchyRequest(
            DistinguishedFolderIdNameType folder,
            DefaultShapeNamesType defaultShapeNames,
            bool isSyncFolderIdPresent,
            bool isSyncStatePresent)
        {
            // Create an instance of SyncFolderHierarchyType
            SyncFolderHierarchyType request = new SyncFolderHierarchyType();

            request.FolderShape           = new FolderResponseShapeType();
            request.FolderShape.BaseShape = defaultShapeNames;

            // Set the value of SyncFolderId if this element is present in the request.
            if (isSyncFolderIdPresent)
            {
                request.SyncFolderId = new TargetFolderIdType();
                DistinguishedFolderIdType distinguishedFolderId = new DistinguishedFolderIdType();
                distinguishedFolderId.Id  = folder;
                request.SyncFolderId.Item = distinguishedFolderId;
            }

            // Set the value of SyncState element if this element is present in the request.
            if (isSyncStatePresent)
            {
                request.SyncState = string.Empty;
            }

            return(request);
        }
        /// <summary>
        /// Find all the items in the specified folder.
        /// </summary>
        /// <param name="folderName">Name of the specified folder.</param>
        /// <returns>An array of found items.</returns>
        private ItemType[] FindAllItems(DistinguishedFolderIdNameType folderName)
        {
            // Create an array of ItemType.
            ItemType[] items = null;

            // Create an instance of FindItemType.
            FindItemType findItemRequest = new FindItemType();

            findItemRequest.ParentFolderIds = new BaseFolderIdType[1];

            DistinguishedFolderIdType parentFolder = new DistinguishedFolderIdType();

            parentFolder.Id = folderName;
            findItemRequest.ParentFolderIds[0] = parentFolder;

            // Get properties that are defined as the default for the items.
            findItemRequest.ItemShape           = new ItemResponseShapeType();
            findItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.Default;

            // Invoke the FindItem operation.
            FindItemResponseType findItemResponse = this.exchangeServiceBinding.FindItem(findItemRequest);

            if (findItemResponse != null && findItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
            {
                // Get the found items from the response.
                FindItemResponseMessageType findItemMessage = findItemResponse.ResponseMessages.Items[0] as FindItemResponseMessageType;
                ArrayOfRealItemsType        findItems       = findItemMessage.RootFolder.Item as ArrayOfRealItemsType;
                items = findItems.Items;
            }

            return(items);
        }
Esempio n. 5
0
        /// <summary>
        /// Reads the appointments from the Exchange server.
        /// </summary>
        /// <param name="owner">The owner RadScheduler instance.</param>
        /// <returns></returns>
        public override IEnumerable <Appointment> GetAppointments(RadScheduler owner)
        {
            List <Appointment> appointments = new List <Appointment>();

            foreach (Resource resource in owner.Resources)
            {
                string sharedCalendarName = this.CalendarNames;// resource.Text;

                // Identify which folders to search.
                DistinguishedFolderIdType distinguishedFolderIdType = new DistinguishedFolderIdType();
                distinguishedFolderIdType.Id = DistinguishedFolderIdNameType.calendar;


                EmailAddressType emailAddressType = new EmailAddressType();
                emailAddressType.EmailAddress = sharedCalendarName;

                distinguishedFolderIdType.Mailbox = emailAddressType;

                List <ItemIdType> itemIds = new List <ItemIdType>();

                foreach (CalendarItemType item in FindCalendarItems(new DistinguishedFolderIdType[] { distinguishedFolderIdType }))
                {
                    if ((item.Start < owner.VisibleRangeEnd && item.End > owner.VisibleRangeStart) ||
                        item.CalendarItemType1 == CalendarItemTypeType.RecurringMaster)
                    {
                        itemIds.Add(item.ItemId);
                    }
                }

                appointments.AddRange(GetAppointments(owner, sharedCalendarName, itemIds.ToArray()));
            }

            return(appointments);
        }
Esempio n. 6
0
        private void CreateWorkingFolderIfNotExist()
        {
            BaseFolderIdType parentFolderId = new DistinguishedFolderIdType
            {
                Id      = DistinguishedFolderIdNameType.msgfolderroot,
                Mailbox = new EmailAddressType
                {
                    EmailAddress = this.PrimarySmtpAddress
                }
            };

            this.workingFolder = this.GetWorkingOrResultFolder(this.targetLocation.WorkingLocation);
            if (this.workingFolder == null)
            {
                FolderType folderType = new FolderType
                {
                    DisplayName = this.targetLocation.WorkingLocation
                };
                folderType.ExtendedProperty = new ExtendedPropertyType[]
                {
                    MailboxItemIdList.IsHiddenExtendedProperty
                };
                List <BaseFolderType> list = this.ewsClient.CreateFolder(this.PrimarySmtpAddress, parentFolderId, new BaseFolderType[]
                {
                    folderType
                });
                this.workingFolder = list[0];
            }
        }
Esempio n. 7
0
        public FolderIdType FindFolderID(ExchangeServiceBinding service, DistinguishedFolderIdNameType folder)
        {
            FindFolderType requestFindFolder = new FindFolderType();

            requestFindFolder.Traversal = FolderQueryTraversalType.Deep;

            DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
            folderIDArray[0]    = new DistinguishedFolderIdType();
            folderIDArray[0].Id = folder;

            FolderResponseShapeType itemProperties = new FolderResponseShapeType();

            itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;

            requestFindFolder.ParentFolderIds = folderIDArray;
            requestFindFolder.FolderShape     = itemProperties;
            //requestFindFolder.FolderShape.BaseShape = DefaultShapeNamesType.AllProperties;


            FindFolderResponseType objFindFolderResponse = service.FindFolder(requestFindFolder);

            foreach (ResponseMessageType responseMsg in objFindFolderResponse.ResponseMessages.Items)
            {
                if (responseMsg.ResponseClass == ResponseClassType.Success)
                {
                    FindFolderResponseMessageType objFindResponse = responseMsg as FindFolderResponseMessageType;

                    foreach (BaseFolderType objFolderType in objFindResponse.RootFolder.Folders)
                    {
                        return(objFolderType.FolderId);
                    }
                }
            }
            return(null);
        }
        public void MSOXWSFOLD_S04_TC05_GetNotesFolder()
        {
            #region Get the notes folder.

            DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
            folder.Id = DistinguishedFolderIdNameType.notes;

            // GetFolder request.
            GetFolderType getNotesFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, folder);

            // Get the notes folder.
            GetFolderResponseType getNotesFolderResponse = this.FOLDAdapter.GetFolder(getNotesFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(getNotesFolderResponse, 1, this.Site);

            // Variable to save the folder.
            FolderInfoResponseMessageType allFolders = (FolderInfoResponseMessageType)getNotesFolderResponse.ResponseMessages.Items[0];
            BaseFolderType folderInfo = (BaseFolderType)allFolders.Folders[0];

            #endregion

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

            // Verify MS-OXWSFOLD_R588.
            Site.CaptureRequirementIfAreEqual <string>(
                "IPF.StickyNote",
                folderInfo.FolderClass,
                588,
                @"[In t:BaseFolderType Complex Type]This value[FolderClass] MUST be ""IPF.StickyNote"" for note folders.");
        }
        public void MSOXWSFOLD_S04_TC09_GetFolderIdOnly()
        {
            #region Get the contacts folder.

            DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
            folder.Id = DistinguishedFolderIdNameType.contacts;

            // GetFolder request.
            GetFolderType getContactsFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.IdOnly, folder);

            // Get the Contacts folder.
            GetFolderResponseType getContactsFolderResponse = this.FOLDAdapter.GetFolder(getContactsFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(getContactsFolderResponse, 1, this.Site);

            #endregion

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R42103
            bool isVerifiedR42103 = Common.IsIdOnly((XmlElement)this.FOLDAdapter.LastRawResponseXml, "t:ContactsFolder", "t:FolderId");
            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR42103,
                42103,
                @"[In t:DefaultShapeNamesType Simple Type] A value of ""IdOnly"" [in DefaultShapeNamesType] specifies only the item or folder ID. include in the response.");
        }
Esempio n. 10
0
        public void MSOXWSFOLD_S02_TC02_CopyMultipleFolders()
        {
            #region Copy the "drafts" and "deleteditems" folder to inbox

            // Set "drafts" and "deleteditems" folders' Id.
            DistinguishedFolderIdType copiedFolderId1 = new DistinguishedFolderIdType();
            copiedFolderId1.Id = DistinguishedFolderIdNameType.drafts;
            DistinguishedFolderIdType copiedFolderId2 = new DistinguishedFolderIdType();
            copiedFolderId2.Id = DistinguishedFolderIdNameType.deleteditems;

            // CopyFolder request.
            CopyFolderType copyFolderRequest = this.GetCopyFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), copiedFolderId1, copiedFolderId2);

            // Copy the "drafts" and "deleteditems" folder.
            CopyFolderResponseType copyFolderResponse = this.FOLDAdapter.CopyFolder(copyFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(copyFolderResponse, 2, this.Site);

            // Save copied folders' id.
            FolderIdType folderId1 = ((FolderInfoResponseMessageType)copyFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            FolderIdType folderId2 = ((FolderInfoResponseMessageType)copyFolderResponse.ResponseMessages.Items[1]).Folders[0].FolderId;

            // Save the copied folders' id.
            this.NewCreatedFolderIds.Add(folderId1);
            this.NewCreatedFolderIds.Add(folderId2);

            #endregion
        }
Esempio n. 11
0
        /// <summary>
        /// Проверяет успешность подключения к серверу Exchange с указанными параметрами
        /// </summary>
        /// <param name="ex">Параметры подключения</param>
        /// <param name="message">Возвращает текст ошибки подключения при ее наличии</param>
        /// <returns></returns>
        public static bool CheckConnection(Configuration.Exchange ex, out string message)
        {
            try {
                message = string.Empty;

                ExchangeServiceBinding bind = new ExchangeServiceBinding();
                bind.Credentials = new NetworkCredential(ex.Username, ex.Password, ex.Domain);
                bind.Url         = "https://" + ex.ServerName + "/EWS/Exchange.asmx";

                FindItemType findType = new FindItemType();
                findType.Traversal           = ItemQueryTraversalType.Shallow;
                findType.ItemShape           = new ItemResponseShapeType();
                findType.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly;

                DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
                folder.Id = DistinguishedFolderIdNameType.inbox;
                findType.ParentFolderIds = new BaseFolderIdType[] { folder };

                FindItemResponseType findResp = bind.FindItem(findType);
            }
            catch (Exception error) {
                message = error.Message;
                return(false);
            }

            return(true);
        }
        public void MSOXWSFOLD_S03_TC03_MoveFolderFailed()
        {
            #region Create a new folder in the inbox folder

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.inbox.ToString(), new string[] { "Custom Folder" }, new string[] { "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderResponse = this.FOLDAdapter.CreateFolder(createFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(createFolderResponse, 1, this.Site);

            // Save the new created folder's folder id.
            FolderIdType newFolderId = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            this.NewCreatedFolderIds.Add(newFolderId);

            #endregion

            #region Delete the created folder

            // DeleteFolder request.
            DeleteFolderType deleteFolderRequest = this.GetDeleteFolderRequest(DisposalType.HardDelete, newFolderId);

            // Delete the specified folder.
            DeleteFolderResponseType deleteFolderResponse = this.FOLDAdapter.DeleteFolder(deleteFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(deleteFolderResponse, 1, this.Site);

            // The folder has been deleted, so its folder id has disappeared.
            this.NewCreatedFolderIds.Remove(newFolderId);

            #endregion

            #region Move the deleted folder
            MoveFolderType moveFolderRequest = new MoveFolderType();
            moveFolderRequest.FolderIds    = new BaseFolderIdType[1];
            moveFolderRequest.FolderIds[0] = newFolderId;
            DistinguishedFolderIdType toFolderId = new DistinguishedFolderIdType();
            toFolderId.Id = DistinguishedFolderIdNameType.inbox;
            moveFolderRequest.ToFolderId      = new TargetFolderIdType();
            moveFolderRequest.ToFolderId.Item = toFolderId;

            // Move the specified folder.
            MoveFolderResponseType moveFolderResponse = this.FOLDAdapter.MoveFolder(moveFolderRequest);

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

            this.Site.CaptureRequirementIfAreEqual <ResponseClassType>(
                ResponseClassType.Error,
                moveFolderResponse.ResponseMessages.Items[0].ResponseClass,
                4315,
                @"[In MoveFolder Operation]An unsuccessful MoveFolder operation request returns a MoveFolderResponse element with the ResponseClass attribute of the MoveFolderResponseMessage element set to ""Error"".");
            #endregion
        }
Esempio n. 13
0
        /// <summary>
        /// The operation construct a request for FindItem operation.
        /// </summary>
        /// <param name="folderName">A string that specifies the folder to search.</param>
        /// <param name="value">A string that specifies the value for a search restriction.</param>
        /// <param name="field">A string that specifies the type of referenced field URI.</param>
        /// <returns>The request of FindItem operation which constructed with special folder name, search restriction and referenced field URI</returns>
        protected FindItemType ConstructFindItemRequest(string folderName, string value, string field)
        {
            FindItemType findRequest = new FindItemType();

            findRequest.ItemShape           = new ItemResponseShapeType();
            findRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;

            DistinguishedFolderIdType     folderId = new DistinguishedFolderIdType();
            DistinguishedFolderIdNameType folderIdName;

            if (Enum.TryParse <DistinguishedFolderIdNameType>(folderName, out folderIdName))
            {
                folderId.Id = folderIdName;
            }
            else
            {
                Site.Assert.Fail("The value of the first argument (foldIdNameType) of FindItem operation is invalid.");
            }

            findRequest.ParentFolderIds    = new BaseFolderIdType[1];
            findRequest.ParentFolderIds[0] = folderId;

            PathToUnindexedFieldType itemClass = new PathToUnindexedFieldType();
            UnindexedFieldURIType    fieldURI;

            if (Enum.TryParse <UnindexedFieldURIType>(field, out fieldURI))
            {
                // set search field.
                itemClass.FieldURI = fieldURI;
            }
            else
            {
                Site.Assert.Fail("The value of the second argument (fieldURIType) of FindItem operation is invalid.");
            }

            ContainsExpressionType expressionType = new ContainsExpressionType();

            expressionType.Item                           = itemClass;
            expressionType.ContainmentMode                = ContainmentModeType.Substring;
            expressionType.ContainmentModeSpecified       = true;
            expressionType.ContainmentComparison          = ContainmentComparisonType.IgnoreCaseAndNonSpacingCharacters;
            expressionType.ContainmentComparisonSpecified = true;
            expressionType.Constant                       = new ConstantValueType();
            expressionType.Constant.Value                 = value;

            RestrictionType restriction = new RestrictionType();

            restriction.Item = expressionType;

            if (!string.IsNullOrEmpty(value))
            {
                findRequest.Restriction = restriction;
            }

            return(findRequest);
        }
        public void MSOXWSMTGS_S05_TC04_MoveMultipleCalendarItems()
        {
            #region Define two calendar items to move
            CalendarItemType calendarItem1 = new CalendarItemType();
            calendarItem1.UID     = Guid.NewGuid().ToString();
            calendarItem1.Subject = Common.GenerateResourceName(this.Site, Common.GetConfigurationPropertyValue("MeetingSubject", this.Site));
            CalendarItemType calendarItem2 = new CalendarItemType();
            calendarItem2.UID     = Guid.NewGuid().ToString();
            calendarItem2.Subject = Common.GenerateResourceName(this.Site, Common.GetConfigurationPropertyValue("MeetingSubject", this.Site));
            #endregion

            #region Create the two calendar items
            ItemInfoResponseMessageType[] calendars = this.CreateMultipleCalendarItems(Role.Organizer, new ItemType[] { calendarItem1, calendarItem2 }, CalendarItemCreateOrDeleteOperationType.SendToNone);
            Site.Assert.IsNotNull(calendars, "The calendars should be created successfully.");
            Site.Assert.IsTrue(calendars.Length == 2, "There should be only two calendars created.");

            ItemIdType[] calendarIds = new ItemIdType[] { calendars[0].Items.Items[0].ItemId, calendars[1].Items.Items[0].ItemId };
            #endregion

            #region Move the two calendar items to Inbox folder
            DistinguishedFolderIdType folderId = new DistinguishedFolderIdType();
            folderId.Id = DistinguishedFolderIdNameType.inbox;
            TargetFolderIdType targetFolderId = new TargetFolderIdType();
            targetFolderId.Item = folderId;

            Site.Assert.IsNotNull(
                this.MoveMultipleCalendarItems(Role.Organizer, calendarIds, targetFolderId),
                "The calendars should be moved into the inbox folder successfully.");

            #endregion

            #region Call FindItem to verify the two calendar items are moved to Inbox folder
            Site.Assert.IsNull(
                this.SearchDeletedSingleItem(Role.Organizer, DistinguishedFolderIdNameType.calendar, "IPM.Appointment", calendarItem1.UID),
                "The original calendar should not be in organizer's calendar folder after MoveItem operation.");

            Site.Assert.IsNotNull(
                this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.inbox, "IPM.Appointment", calendarItem1.UID),
                "The original calendar should be in organizer's inbox folder after MoveItem operation.");

            Site.Assert.IsNull(
                this.SearchDeletedSingleItem(Role.Organizer, DistinguishedFolderIdNameType.calendar, "IPM.Appointment", calendarItem2.UID),
                "The original calendar should not be in organizer's calendar folder after MoveItem operation.");

            Site.Assert.IsNotNull(
                this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.inbox, "IPM.Appointment", calendarItem2.UID),
                "The original calendar should be in organizer's inbox folder after MoveItem operation.");
            #endregion

            #region Clean up organizer's inbox folder.
            this.CleanupFoldersByRole(Role.Organizer, new List <DistinguishedFolderIdNameType>()
            {
                DistinguishedFolderIdNameType.inbox
            });
            #endregion
        }
Esempio n. 15
0
        public void MSOXWSFOLD_S04_TC06_GetTasksFolder()
        {
            #region Get the tasks folder.

            DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
            folder.Id = DistinguishedFolderIdNameType.tasks;

            // GetFolder request.
            GetFolderType getTasksFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, folder);

            // Get the tasks folder.
            GetFolderResponseType getTasksFolderResponse = this.FOLDAdapter.GetFolder(getTasksFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(getTasksFolderResponse, 1, this.Site);

            // Variable to save the folder.
            FolderInfoResponseMessageType allFolders = (FolderInfoResponseMessageType)getTasksFolderResponse.ResponseMessages.Items[0];

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R35
            this.Site.CaptureRequirementIfIsInstanceOfType(
                allFolders.Folders[0],
                typeof(TasksFolderType),
                35,
                @"[In t:ArrayOfFoldersType Complex Type]The type of element TasksFolder is t:TasksFolderType ([MS-OXWSTASK] section 2.2.4.5).");

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

            // Verify MS-OXWSFOLD requirement: MS-OXWSFOLD_R3501
            this.Site.CaptureRequirementIfIsInstanceOfType(
                allFolders.Folders[0],
                typeof(TasksFolderType),
                3501,
                @"[In t:ArrayOfFoldersType Complex Type]TasksFolder represents a Tasks folder that is contained in a mailbox.");

            TasksFolderType folderInfo = (TasksFolderType)allFolders.Folders[0];

            #endregion

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

            // Verify MS-OXWSFOLD_R589.
            Site.CaptureRequirementIfAreEqual <string>(
                "IPF.Task",
                folderInfo.FolderClass,
                589,
                @"[In t:BaseFolderType Complex Type]This value[FolderClass] MUST be ""IPF.Task"" for Tasks folders.");
        }
Esempio n. 16
0
        private BaseFolderType GetWorkingOrResultFolder(string folderName)
        {
            DistinguishedFolderIdType parentFolderId = new DistinguishedFolderIdType
            {
                Id      = DistinguishedFolderIdNameType.msgfolderroot,
                Mailbox = new EmailAddressType
                {
                    EmailAddress = this.PrimarySmtpAddress
                }
            };

            return(this.ewsClient.GetFolderByName(this.PrimarySmtpAddress, parentFolderId, folderName));
        }
Esempio n. 17
0
        public void MSOXWSMTGS_S03_TC01_CopySingleCalendar()
        {
            #region Define a calendar item to copy
            CalendarItemType calendarItem = new CalendarItemType();
            calendarItem.UID     = Guid.NewGuid().ToString();
            calendarItem.Subject = this.Subject;
            #endregion

            #region Create the calendar item with CalendarItemCreateOrDeleteOperationType set to SendToNone
            ItemInfoResponseMessageType item = this.CreateSingleCalendarItem(Role.Organizer, calendarItem, CalendarItemCreateOrDeleteOperationType.SendToNone);
            Site.Assert.IsNotNull(item, "Create a calendar item should be successful.");
            ItemIdType calendarId = item.Items.Items[0].ItemId;
            #endregion

            #region Copy the calendar item to Drafts folder
            DistinguishedFolderIdType folderId = new DistinguishedFolderIdType();
            folderId.Id = DistinguishedFolderIdNameType.drafts;
            TargetFolderIdType targetFolderId = new TargetFolderIdType();
            targetFolderId.Item = folderId;

            ItemInfoResponseMessageType copiedItem = this.CopySingleCalendarItem(Role.Organizer, calendarId, targetFolderId);

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R602
            this.Site.CaptureRequirementIfIsNotNull(
                copiedItem,
                602,
                @"[In Messages] CopyItemSoapIn: For each item being copied that is not a recurring calendar item, the ItemIds element MUST contain an ItemId child element ([MS-OXWSCORE] section 2.2.4.11).");
            #endregion

            #region Call GetItem operation to verify whether the calendar item is really copied
            CalendarItemType calendar = this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.drafts, "IPM.Appointment", calendarItem.UID) as CalendarItemType;
            Site.Assert.IsNotNull(calendar, "The calendar item should be in organizer's drafts folder.");

            CalendarItemType calendarInCalendar = this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.calendar, "IPM.Appointment", calendarItem.UID) as CalendarItemType;
            Site.Assert.IsNotNull(calendarInCalendar, "The calendar item should also be in organizer's calendar folder.");
            #endregion

            #region Clean up organizer's drafts and calendar folders
            this.CleanupFoldersByRole(Role.Organizer, new List <DistinguishedFolderIdNameType>()
            {
                DistinguishedFolderIdNameType.calendar, DistinguishedFolderIdNameType.drafts
            });
            #endregion
        }
        public void MSOXWSFOLD_S06_TC06_UpdateDistinguishedFolder()
        {
            #region Get the sent items folder.

            DistinguishedFolderIdType folderId = new DistinguishedFolderIdType();
            folderId.Id = DistinguishedFolderIdNameType.sentitems;

            // GetFolder request.
            GetFolderType getSentItemsFolderRequest = this.GetGetFolderRequest(DefaultShapeNamesType.AllProperties, folderId);

            GetFolderResponseType getSentItemsFolderResponse = this.FOLDAdapter.GetFolder(getSentItemsFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(getSentItemsFolderResponse, 1, this.Site);

            // Variable to save the folder.
            FolderInfoResponseMessageType allFolders = (FolderInfoResponseMessageType)getSentItemsFolderResponse.ResponseMessages.Items[0];
            BaseFolderType folderInfo = (BaseFolderType)allFolders.Folders[0];

            #endregion

            #region Update Folder Operation.

            // UpdateFolder request to delete folder permission value.
            UpdateFolderType updateFolderRequest = this.GetUpdateFolderRequest("Folder", "DeleteFolderField", folderInfo.FolderId);

            // Set change key value.
            folderId.ChangeKey = folderInfo.FolderId.ChangeKey;
            updateFolderRequest.FolderChanges[0].Item = folderId;

            // Update the specific folder's properties.
            UpdateFolderResponseType updateFolderResponse = this.FOLDAdapter.UpdateFolder(updateFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(updateFolderResponse, 1, this.Site);

            #endregion

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

            // Distinguished folder id set and update folder return a successfully, this requirement can be captured.
            this.Site.CaptureRequirement(
                9101,
                @"[In t:FolderChangeType Complex Type]DistinguishedFolderId specifies an identifier for a distinguished folder.");
        }
        public void MSOXWSMTGS_S04_TC01_MoveSingleCalendar()
        {
            #region Define a calendar item to move
            CalendarItemType calendarItem = new CalendarItemType();
            calendarItem.UID     = Guid.NewGuid().ToString();
            calendarItem.Subject = this.Subject;
            #endregion

            #region Create the calendar item
            ItemInfoResponseMessageType item = this.CreateSingleCalendarItem(Role.Organizer, calendarItem, CalendarItemCreateOrDeleteOperationType.SendToNone);
            ItemIdType calendarId            = item.Items.Items[0].ItemId;
            #endregion

            #region Move the created calendar item to Inbox folder
            DistinguishedFolderIdType folderId = new DistinguishedFolderIdType();
            folderId.Id = DistinguishedFolderIdNameType.inbox;
            TargetFolderIdType targetFolderId = new TargetFolderIdType();
            targetFolderId.Item = folderId;

            ItemInfoResponseMessageType movedItem = this.MoveSingleCalendarItem(Role.Organizer, calendarId, targetFolderId);

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

            // Verify MS-OXWSMTGS requirement: MS-OXWSMTGS_R640
            this.Site.CaptureRequirementIfIsNotNull(
                movedItem,
                640,
                @"[In Messages] MoveItemSoapIn: For each item being moved that is not a recurring calendar item, the ItemIds element MUST contain an ItemId child element ([MS-OXWSCORE] section 2.2.4.11).");
            #endregion

            #region Verify the calendar item is moved to Inbox folder
            CalendarItemType calendar = this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.inbox, "IPM.Appointment", calendarItem.UID) as CalendarItemType;
            Site.Assert.IsNotNull(calendar, "The calendar item should be moved to Inbox folder.");

            CalendarItemType calendarInCalendar = this.SearchDeletedSingleItem(Role.Organizer, DistinguishedFolderIdNameType.calendar, "IPM.Appointment", calendarItem.UID) as CalendarItemType;
            Site.Assert.IsNull(calendarInCalendar, "The calendar item should not be in the Calendar folder.");
            #endregion

            #region Clean up organizer's inbox folder.
            this.CleanupFoldersByRole(Role.Organizer, new List <DistinguishedFolderIdNameType>()
            {
                DistinguishedFolderIdNameType.inbox
            });
            #endregion
        }
        public void MSOXWSFOLD_S03_TC02_MoveMultipleFolders()
        {
            #region Create multiple folders in the "drafts" folder

            // CreateFolder request.
            CreateFolderType createFolderRequest = this.GetCreateFolderRequest(DistinguishedFolderIdNameType.drafts.ToString(), new string[] { "ForMoveFolder1", "ForMoveFolder2" }, new string[] { "IPF.MyCustomFolderClass", "IPF.MyCustomFolderClass" }, null);

            // Create a new folder.
            CreateFolderResponseType createFolderResponse = this.FOLDAdapter.CreateFolder(createFolderRequest);
            FolderIdType             newFolderId1         = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[0]).Folders[0].FolderId;
            FolderIdType             newFolderId2         = ((FolderInfoResponseMessageType)createFolderResponse.ResponseMessages.Items[1]).Folders[0].FolderId;

            // Check the response.
            Common.CheckOperationSuccess(createFolderResponse, 2, this.Site);

            // Save the new created folder's folder id.
            this.NewCreatedFolderIds.Add(newFolderId1);
            this.NewCreatedFolderIds.Add(newFolderId2);

            #endregion

            #region Move the new created folder to the inbox folder

            // MoveFolder request.
            MoveFolderType moveFolderRequest = new MoveFolderType();

            // Set the request's folderId field.
            moveFolderRequest.FolderIds    = new BaseFolderIdType[2];
            moveFolderRequest.FolderIds[0] = newFolderId1;
            moveFolderRequest.FolderIds[1] = newFolderId2;

            // Set the request's destFolderId field.
            DistinguishedFolderIdType toFolderId = new DistinguishedFolderIdType();
            toFolderId.Id = DistinguishedFolderIdNameType.inbox;
            moveFolderRequest.ToFolderId      = new TargetFolderIdType();
            moveFolderRequest.ToFolderId.Item = toFolderId;

            // Move the specified folder.
            MoveFolderResponseType moveFolderResponse = this.FOLDAdapter.MoveFolder(moveFolderRequest);

            // Check the response.
            Common.CheckOperationSuccess(moveFolderResponse, 2, this.Site);

            #endregion
        }
Esempio n. 21
0
        private BaseFolderType CreateRootResultFolderIfNotExist()
        {
            BaseFolderType baseFolderType = this.GetWorkingOrResultFolder(this.targetLocation.ExportLocation);

            if (baseFolderType == null)
            {
                DistinguishedFolderIdType parentFolderId = new DistinguishedFolderIdType
                {
                    Id      = DistinguishedFolderIdNameType.msgfolderroot,
                    Mailbox = new EmailAddressType
                    {
                        EmailAddress = this.PrimarySmtpAddress
                    }
                };
                baseFolderType = this.CreateFolder(parentFolderId, this.targetLocation.ExportLocation, false);
            }
            return(baseFolderType);
        }
Esempio n. 22
0
        private BaseFolderType GetOrCreateRecycleFolder(bool createFolderIfNotExist)
        {
            DistinguishedFolderIdType folderId = new DistinguishedFolderIdType
            {
                Id      = DistinguishedFolderIdNameType.root,
                Mailbox = new EmailAddressType
                {
                    EmailAddress = this.PrimarySmtpAddress
                }
            };
            BaseFolderType folderById     = this.ewsClient.GetFolderById(this.PrimarySmtpAddress, folderId);
            BaseFolderType baseFolderType = this.ewsClient.GetFolderByName(this.PrimarySmtpAddress, folderById.FolderId, Constants.MailboxSearchRecycleFolderName);

            if (baseFolderType == null && createFolderIfNotExist)
            {
                baseFolderType = this.CreateFolder(folderById.FolderId, Constants.MailboxSearchRecycleFolderName, true);
            }
            return(baseFolderType);
        }
        /// <summary>
        /// Log on to a mailbox with a specified user account and create an user configuration objects on inbox folder.
        /// </summary>
        /// <param name="userName">The name of the user used to communicate with server</param>
        /// <param name="password">The password of the user used to communicate with server</param>
        /// <param name="domain">The domain of the user used to communicate with server</param>
        /// <param name="userConfigurationName">Name of the user configuration object.</param>
        /// <returns>If succeed, return true; otherwise, return false.</returns>
        public bool CreateUserConfiguration(string userName, string password, string domain, string userConfigurationName)
        {
            userConfigurationName = userConfigurationName.Replace("_", string.Empty);
            this.exchangeServiceBinding.Credentials = new System.Net.NetworkCredential(userName, password, domain);
            CreateUserConfigurationType request = new CreateUserConfigurationType();

            request.UserConfiguration = new UserConfigurationType();
            request.UserConfiguration.UserConfigurationName      = new UserConfigurationNameType();
            request.UserConfiguration.UserConfigurationName.Name = userConfigurationName;
            DistinguishedFolderIdType distinguishedFolderId = new DistinguishedFolderIdType();

            distinguishedFolderId.Id = DistinguishedFolderIdNameType.inbox;
            request.UserConfiguration.UserConfigurationName.Item = distinguishedFolderId;

            CreateUserConfigurationResponseType response = this.exchangeServiceBinding.CreateUserConfiguration(request);

            return(response.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success &&
                   response.ResponseMessages.Items[0].ResponseCode == ResponseCodeType.NoError ? true : false);
        }
Esempio n. 24
0
        /// <summary>
        /// Inserts the specified appointment.
        /// </summary>
        /// <param name="owner">The owner RadScheduler instance.</param>
        /// <param name="appointmentToInsert">The appointment to insert.</param>
        public override void Insert(RadScheduler owner, Appointment appointmentToInsert)
        {
            CreateRecurrenceExceptionContext createExceptionContext = owner.ProviderContext as CreateRecurrenceExceptionContext;

            if (createExceptionContext != null)
            {
                Debug.Assert(appointmentToInsert.RecurrenceState == RecurrenceState.Exception);
                InsertRecurrenceException(owner, appointmentToInsert, createExceptionContext.RecurrenceExceptionDate);
                return;
            }


            CalendarItemType calendarItem = CreateCalendarItem(owner, appointmentToInsert);

            CreateItemType createItemRequest = new CreateItemType();

            DistinguishedFolderIdType destFolder = new DistinguishedFolderIdType();

            destFolder.Id = DistinguishedFolderIdNameType.calendar;

            EmailAddressType emailAddressType = new EmailAddressType();

            emailAddressType.EmailAddress = this.CalendarNames;

            destFolder.Mailbox = emailAddressType;

            createItemRequest.SavedItemFolderId      = new TargetFolderIdType();
            createItemRequest.SavedItemFolderId.Item = destFolder;


            createItemRequest.SendMeetingInvitations          = CalendarItemCreateOrDeleteOperationType.SendToNone;
            createItemRequest.SendMeetingInvitationsSpecified = true;
            createItemRequest.Items       = new NonEmptyArrayOfAllItemsType();
            createItemRequest.Items.Items = new CalendarItemType[] { calendarItem };

            CreateItemResponseType response        = Service.CreateItem(createItemRequest);
            ResponseMessageType    responseMessage = response.ResponseMessages.Items[0];

            if (responseMessage.ResponseCode != ResponseCodeType.NoError)
            {
                throw new Exception("CreateItem failed with response code " + responseMessage.ResponseCode);
            }
        }
        public void MSOXWSCONT_S03_TC01_CopyContactItem()
        {
            #region Step 1:Create the contact item.
            // Create a contact item.
            ContactItemType        item = this.BuildContactItemWithRequiredProperties();
            CreateItemResponseType createItemResponse = this.CallCreateItemOperation(item);

            // Check the response.
            Common.CheckOperationSuccess(createItemResponse, 1, this.Site);
            #endregion

            #region Step 2:Copy the contact item.
            CopyItemType         copyItemRequest  = new CopyItemType();
            CopyItemResponseType copyItemResponse = new CopyItemResponseType();

            // Configure ItemIds.
            copyItemRequest.ItemIds    = new BaseItemIdType[1];
            copyItemRequest.ItemIds[0] = this.ExistContactItems[0];

            // Configure the copy Distinguished Folder.
            DistinguishedFolderIdType distinguishedFolderIdForCopyItem = new DistinguishedFolderIdType();
            distinguishedFolderIdForCopyItem.Id = DistinguishedFolderIdNameType.drafts;
            copyItemRequest.ToFolderId          = new TargetFolderIdType();
            copyItemRequest.ToFolderId.Item     = distinguishedFolderIdForCopyItem;

            copyItemResponse = this.CONTAdapter.CopyItem(copyItemRequest);

            // Check the response.
            Common.CheckOperationSuccess(copyItemResponse, 1, this.Site);
            #endregion

            #region Step 3:Get the contact item.
            // The contact item to get.
            ItemIdType[] itemArray = new ItemIdType[this.ExistContactItems.Count];
            this.ExistContactItems.CopyTo(itemArray, 0);

            GetItemResponseType getItemResponse = this.CallGetItemOperation(itemArray);

            // Check the response.
            Common.CheckOperationSuccess(getItemResponse, 2, this.Site);
            #endregion
        }
Esempio n. 26
0
        private ResponseMessageType[] GetFolderItems(ExchangeServiceBinding svc, DistinguishedFolderIdNameType folder)
        {
            // Form the FindItem request.
            FindItemType findItemRequest = new FindItemType();

            findItemRequest.Traversal = ItemQueryTraversalType.Shallow;

            // Define which item properties are returned in the response.
            ItemResponseShapeType itemProperties = new ItemResponseShapeType();

            itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;

            //Define propriedade que armazena antigo ID
            PathToExtendedFieldType netShowUrlPath = new PathToExtendedFieldType();

            netShowUrlPath.PropertyTag  = "0x3A4D";
            netShowUrlPath.PropertyType = MapiPropertyTypeType.String;

            //Adiciona propriedade na busca
            itemProperties.AdditionalProperties    = new BasePathToElementType[1];
            itemProperties.AdditionalProperties[0] = netShowUrlPath;

            // Add properties shape to the request.
            findItemRequest.ItemShape = itemProperties;

            // Identify which folders to search to find items.
            DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[2];
            folderIDArray[0]    = new DistinguishedFolderIdType();
            folderIDArray[0].Id = folder;

            // Add folders to the request.
            findItemRequest.ParentFolderIds = folderIDArray;

            // Send the request and get the response.
            FindItemResponseType findItemResponse = svc.FindItem(findItemRequest);

            // Get the response messages.
            ResponseMessageType[] rmta = findItemResponse.ResponseMessages.Items;

            return(rmta);
        }
Esempio n. 27
0
        /// <summary>
        /// Gets the nr of items in a given folder
        /// </summary>
        /// <returns></returns>
        public long GetNrItemsInFolder(ChannelFolder folder)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            var findItemRequest = new FindItemType {
                Traversal = ItemQueryTraversalType.Shallow
            };
            var itemProperties = new ItemResponseShapeType {
                BaseShape = DefaultShapeNamesType.AllProperties
            };

            findItemRequest.ItemShape = itemProperties;

            var folderIdArray = new DistinguishedFolderIdType[2];

            folderIdArray[0] = new DistinguishedFolderIdType {
                Id = DistinguishedFolderIdNameType.inbox
            };

            findItemRequest.ParentFolderIds = folderIdArray;

            FindItemResponseType findItemResponse = binding.FindItem(findItemRequest);

            // Determine whether the request was a success.
            if (findItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
            {
                throw new Exception(findItemResponse.ResponseMessages.Items[0].MessageText);
            }

            var responseMessage =
                (FindItemResponseMessageType)findItemResponse.ResponseMessages.Items[0];

            var mailboxItems = (ArrayOfRealItemsType)responseMessage.RootFolder.Item;

            if (mailboxItems.Items == null)
            {
                return(0);
            }

            return(mailboxItems.Items.Length);
        }
Esempio n. 28
0
        /// <summary>
        /// Asks Exchange to send a specific message.
        /// </summary>
        /// <param name="messageId"></param>
        public void SendMessage(ItemIdType messageId)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            // Send message
            var sendItem = new SendItemType {
                ItemIds = new BaseItemIdType[1], SavedItemFolderId = new TargetFolderIdType()
            };
            var siSentItemsFolder = new DistinguishedFolderIdType {
                Id = DistinguishedFolderIdNameType.sentitems
            };

            sendItem.SavedItemFolderId.Item = siSentItemsFolder;
            sendItem.SaveItemToFolder       = true;
            sendItem.ItemIds[0]             = messageId;

            SendItemResponseType sendItemResponse = binding.SendItem(sendItem);

            if (sendItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
            {
                throw new Exception(sendItemResponse.ResponseMessages.Items[0].MessageText);
            }
        }
Esempio n. 29
0
 // Token: 0x06000536 RID: 1334 RVA: 0x00027578 File Offset: 0x00025778
 public bool SaveConfigItemInArchive(byte[] xmlData)
 {
     try
     {
         DistinguishedFolderIdType folderId = new DistinguishedFolderIdType
         {
             Id = DistinguishedFolderIdNameType.archiveinbox
         };
         if (this.ArchiveEwsClient.GetMrmConfiguration(folderId) == null)
         {
             this.ArchiveEwsClient.CreateMrmConfiguration(folderId, xmlData);
         }
         else
         {
             this.ArchiveEwsClient.UpdateMrmConfiguration(folderId, xmlData);
         }
     }
     catch (ElcEwsException arg)
     {
         RemoteArchiveProcessorBase.Tracer.TraceError <MailboxSession, ElcEwsException>((long)this.GetHashCode(), "The MRM FAI message could not be saved in archive for {0}, Exception: {1}", this.primaryMailboxSession, arg);
         throw;
     }
     return(true);
 }
        /// <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);
        }
Esempio n. 31
0
    static FolderIdType FindFolder(ExchangeServiceBinding esb, DistinguishedFolderIdType fiFolderID, String fnFldName)
    {
        FolderIdType rvFolderID = new FolderIdType();

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

        // Define the properties 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 = fiFolderID.Id;

        //Add Restriction for DisplayName
        RestrictionType ffRestriction = new RestrictionType();
        IsEqualToType ieToType = new IsEqualToType();
        PathToUnindexedFieldType diDisplayName = new PathToUnindexedFieldType();
        diDisplayName.FieldURI = UnindexedFieldURIType.folderDisplayName;
        FieldURIOrConstantType ciConstantType = new FieldURIOrConstantType();
        ConstantValueType cvConstantValueType = new ConstantValueType();
        cvConstantValueType.Value = fnFldName;
        ciConstantType.Item = cvConstantValueType;
        ieToType.Item = diDisplayName;
        ieToType.FieldURIOrConstant = ciConstantType;
        ffRestriction.Item = ieToType;
        findFolderRequest.Restriction = ffRestriction;

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

        try
        {
            // Send the request and get the response
            FindFolderResponseType findFolderResponse = esb.FindFolder(findFolderRequest);

            // Get the response messages
            ResponseMessageType[] rmta = findFolderResponse.ResponseMessages.Items;

            foreach (ResponseMessageType rmt in rmta)
            {
                // Cast to the correct response message type
                FindFolderResponseMessageType ffResponse = (FindFolderResponseMessageType)rmt;

                foreach (FolderType fFoundFolder in ffResponse.RootFolder.Folders)
                {
                    rvFolderID = fFoundFolder.FolderId;
                }
            }
        }
        catch (Exception e)
        {
            string problem = e.Message;
        }

        return rvFolderID;
    }
Esempio n. 32
0
    static void MoveOutlookFolder(string folderToMove, string destinationFolderName)
    {
        ExchangeServiceBinding esb = CreateESB();
        DistinguishedFolderIdType myInbox = new DistinguishedFolderIdType();
        myInbox.Id = DistinguishedFolderIdNameType.inbox;

        // get source folder info
        FolderIdType sourceFolderID = FindFolder(esb, myInbox, folderToMove);
        // get target folder info
        FolderIdType destinationFolderID = FindFolder(esb, myInbox, destinationFolderName);

        // call move method
        MoveFolder(esb, sourceFolderID, destinationFolderID);
    }
Esempio n. 33
0
    private void CreateOutlookFolder(string newFolderName, string destinationFolder)
    {
        ExchangeServiceBinding esb = CreateESB();

        DistinguishedFolderIdType myInbox = new DistinguishedFolderIdType();
        myInbox.Id = DistinguishedFolderIdNameType.inbox;

        FolderIdType estFolder = FindFolder(esb, myInbox, destinationFolder);

        CreateFolder(esb, estFolder, newFolderName);
    }
Esempio n. 34
0
        /// <summary>
        /// Sends mail through the exchange server.
        /// </summary>
        /// <param name="Config"> ReviewNotifierConfiguration. </param>
        /// <param name="ExchangeItems"> Mail to send. </param>
        /// <returns> true if successful. </returns>
        private static bool SendExchangeMail(ReviewNotifierConfiguration Config, List<MessageType> ExchangeItems)
        {
            int maxQuotaNum = Int32.MaxValue;
            var binding = (ExchangeServicePortType)new ExchangeServicePortTypeClient(
                                                       new BasicHttpBinding("ExchangeServiceBinding")
                                                       {
                                                           MaxReceivedMessageSize = maxQuotaNum,
                                                           MaxBufferSize = maxQuotaNum,
                                                           ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
                                                           {
                                                               MaxArrayLength = maxQuotaNum,
                                                               MaxStringContentLength = maxQuotaNum,
                                                               MaxNameTableCharCount = maxQuotaNum
                                                           }
                                                       },
                                                       new EndpointAddress(Config.EmailService));

            DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
            folder.Id = DistinguishedFolderIdNameType.sentitems;

            TargetFolderIdType targetFolder = new TargetFolderIdType();
            targetFolder.Item = folder;

            CreateItemType createItem = new CreateItemType();
            createItem.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
            createItem.MessageDispositionSpecified = true;
            createItem.SavedItemFolderId = targetFolder;

            createItem.Items = new NonEmptyArrayOfAllItemsType();
            createItem.Items.Items = ExchangeItems.ToArray();

            var createReq = new CreateItemRequest() { CreateItem = createItem };

            var response = binding.CreateItem(createReq);

            bool result = true;
            foreach (ResponseMessageType r in response.CreateItemResponse1.ResponseMessages.Items)
            {
                if (r.ResponseClass != ResponseClassType.Success)
                {
                    Log.Info("Failed to send the message. ");
                    Log.Info(r.MessageText);

                    result = false;
                }
            }

            return result;
        }