Esempio n. 1
0
        private static Folder GetFolder(AnchorContext context, MailboxSession mailboxSession, StoreObjectId rootFolderId, string folderName)
        {
            AnchorUtil.ThrowOnNullArgument(mailboxSession, "mailboxSession");
            AnchorUtil.ThrowOnNullArgument(rootFolderId, "rootFolderId");
            AnchorUtil.ThrowOnNullArgument(folderName, "folderName");
            Folder result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                Folder        folder        = null;
                StoreObjectId storeObjectId = AnchorFolder.GetFolderId(context, mailboxSession, rootFolderId, folderName);
                if (storeObjectId == null)
                {
                    folder = Folder.Create(mailboxSession, rootFolderId, StoreObjectType.Folder, folderName, CreateMode.OpenIfExists);
                    disposeGuard.Add <Folder>(folder);
                    folder.Save();
                    folder.Load(AnchorFolder.FolderIdPropertyDefinition);
                    storeObjectId = folder.Id.ObjectId;
                }
                if (folder == null)
                {
                    folder = Folder.Bind(mailboxSession, storeObjectId, AnchorFolder.FolderIdPropertyDefinition);
                    disposeGuard.Add <Folder>(folder);
                }
                disposeGuard.Success();
                result = folder;
            }
            return(result);
        }
Esempio n. 2
0
        public static bool RemoveFolder(AnchorContext context, MailboxSession mailboxSession, string folderName)
        {
            StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Root);
            StoreObjectId folderId        = AnchorFolder.GetFolderId(context, mailboxSession, defaultFolderId, folderName);

            if (folderId == null)
            {
                context.Logger.Log(MigrationEventType.Verbose, "couldn't find folder with name {0} treating as success", new object[]
                {
                    folderName
                });
                return(true);
            }
            using (Folder folder = Folder.Bind(mailboxSession, folderId, AnchorFolder.FolderIdPropertyDefinition))
            {
                context.Logger.Log(MigrationEventType.Information, "About to remove all messages & subfolders from {0} with id {1}", new object[]
                {
                    folderName,
                    folderId
                });
                GroupOperationResult groupOperationResult = folder.DeleteAllObjects(DeleteItemFlags.HardDelete, true);
                if (groupOperationResult.OperationResult != OperationResult.Succeeded)
                {
                    context.Logger.Log(MigrationEventType.Warning, "unsuccessfully removed messages & subfolders from {0} with id {1} with result {2}", new object[]
                    {
                        folderName,
                        folderId,
                        groupOperationResult
                    });
                    return(false);
                }
            }
            bool result;

            using (Folder folder2 = Folder.Bind(mailboxSession, defaultFolderId))
            {
                context.Logger.Log(MigrationEventType.Information, "About to remove folder {0} with id {1}", new object[]
                {
                    folderName,
                    folderId
                });
                AggregateOperationResult aggregateOperationResult = folder2.DeleteObjects(DeleteItemFlags.HardDelete, new StoreId[]
                {
                    folderId
                });
                if (aggregateOperationResult.OperationResult != OperationResult.Succeeded)
                {
                    context.Logger.Log(MigrationEventType.Warning, "unsuccessfully removed folder {0} with id {1} with result {2}", new object[]
                    {
                        folderName,
                        folderId,
                        aggregateOperationResult
                    });
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }