示例#1
0
        public override void PerformBatchOperation(object[][] batchedItemBuffer, int fetchedItemCount, StoreId currentFolderId, MailboxSession sourceMailbox, MailboxSession targetMailbox, Dictionary <StoreId, FolderNode> folderNodeMap, SearchResultProcessor processor)
        {
            StoreId[] array = new StoreId[fetchedItemCount];
            for (int i = 0; i < fetchedItemCount; i++)
            {
                array[i] = (StoreId)batchedItemBuffer[i][0];
            }
            processor.BackOffFromSourceStore();
            AggregateOperationResult aggregateOperationResult = null;

            using (Folder folder = Folder.Bind(sourceMailbox, currentFolderId))
            {
                lock (sourceMailbox)
                {
                    if (processor.IsAborted())
                    {
                        return;
                    }
                    aggregateOperationResult = folder.DeleteObjects(DeleteItemFlags.HardDelete, array);
                }
            }
            if (aggregateOperationResult.OperationResult == OperationResult.Succeeded)
            {
                SearchMailboxAction.Tracer.TraceDebug <int, string>((long)this.GetHashCode(), "SearchMailboxWoker progressed with {0} message deletes on mailbox {1}", array.Length, processor.GetSourceUserName());
                return;
            }
            string empty = string.Empty;

            if (!DeleteSearchMailboxAction.DeleteItemByItem(batchedItemBuffer, fetchedItemCount, currentFolderId, sourceMailbox, processor, out empty))
            {
                foreach (GroupOperationResult groupOperationResult in aggregateOperationResult.GroupOperationResults)
                {
                    if (groupOperationResult.OperationResult != OperationResult.Succeeded && !(groupOperationResult.Exception is RecoverableItemsAccessDeniedException))
                    {
                        SearchMailboxAction.Tracer.TraceError <OperationResult, LocalizedException>((long)this.GetHashCode(), "DeleteItems operation failed with operation result: {0} and exception: {1}", groupOperationResult.OperationResult, groupOperationResult.Exception);
                        SearchMailboxException e = new SearchMailboxException(new LocalizedString(empty), groupOperationResult.Exception);
                        processor.ReportActionException(e);
                    }
                }
                return;
            }
            SearchMailboxAction.Tracer.TraceDebug <int, string>((long)this.GetHashCode(), "Item by Item delete succeded with {0} message deletes on mailbox {1}", array.Length, processor.GetSourceUserName());
        }
        public override void PerformBatchOperation(object[][] batchedItemBuffer, int fetchedItemCount, StoreId currentFolderId, MailboxSession sourceMailbox, MailboxSession targetMailbox, Dictionary <StoreId, FolderNode> folderNodeMap, SearchResultProcessor processor)
        {
            processor.CheckTargetMailboxAvailableSpace();
            StoreId[] array = new StoreId[fetchedItemCount];
            for (int i = 0; i < fetchedItemCount; i++)
            {
                array[i] = (StoreId)batchedItemBuffer[i][0];
            }
            FolderNode folderNode = folderNodeMap[currentFolderId];

            using (Folder folder = Folder.Bind(sourceMailbox, currentFolderId))
            {
                processor.BackOffFromSourceStore();
                processor.BackOffFromTargetStore();
                try
                {
                    GroupOperationResult groupOperationResult = null;
                    lock (targetMailbox)
                    {
                        if (processor.IsAborted())
                        {
                            return;
                        }
                        if (folderNode.TargetFolderId == null)
                        {
                            this.CreateTargetFolder(targetMailbox, folderNode);
                        }
                        groupOperationResult = folder.CopyItems(targetMailbox, folderNode.TargetFolderId, false, array);
                    }
                    if (groupOperationResult.OperationResult != OperationResult.Succeeded)
                    {
                        SearchMailboxAction.Tracer.TraceError <OperationResult, LocalizedException>((long)this.GetHashCode(), "DeleteItems operation failed with operation result: {0} and exception: {1}", groupOperationResult.OperationResult, groupOperationResult.Exception);
                        if (groupOperationResult.Exception.GetType() == typeof(MapiExceptionPartialCompletion) || groupOperationResult.Exception.GetType() == typeof(PartialCompletionException))
                        {
                            StoragePermanentException e = new StoragePermanentException(Strings.CopyItemsFailed, groupOperationResult.Exception);
                            processor.ReportActionException(e);
                        }
                        else
                        {
                            SearchMailboxException e2 = new SearchMailboxException(Strings.CopyItemsFailed, groupOperationResult.Exception);
                            processor.ReportActionException(e2);
                        }
                    }
                    else
                    {
                        SearchMailboxAction.Tracer.TraceDebug <int, string>((long)this.GetHashCode(), "SearchMailboxWoker progressed with {0} message deletes on mailbox {1}", array.Length, processor.GetSourceUserName());
                    }
                }
                catch (ArgumentException ex)
                {
                    SearchMailboxAction.Tracer.TraceError <ArgumentException>((long)this.GetHashCode(), "CopyItems operation failed due to item validation failed, exception: {0}", ex);
                    SearchMailboxException e3 = new SearchMailboxException(Strings.CopyItemsFailed, ex);
                    processor.ReportActionException(e3);
                }
                catch (MapiExceptionPartialCompletion mapiExceptionPartialCompletion)
                {
                    SearchMailboxAction.Tracer.TraceError <MapiExceptionPartialCompletion>((long)this.GetHashCode(), "CopyItems operation failed due to insufficient space in target mailbox, exception: {0}", mapiExceptionPartialCompletion);
                    StoragePermanentException e4 = new StoragePermanentException(Strings.CopyItemsFailed, mapiExceptionPartialCompletion);
                    processor.ReportActionException(e4);
                }
                catch (PartialCompletionException ex2)
                {
                    SearchMailboxAction.Tracer.TraceError <PartialCompletionException>((long)this.GetHashCode(), "CopyItems operation failed due to insufficient space in target mailbox, exception: {0}", ex2);
                    StoragePermanentException e5 = new StoragePermanentException(Strings.CopyItemsFailed, ex2);
                    processor.ReportActionException(e5);
                }
            }
        }