private void ProcessSingleResult(object[] result)
 {
     if (SearchResultProcessor.PropertyExists(result[0]) && SearchResultProcessor.PropertyExists(result[2]))
     {
         StoreId storeId = (StoreId)result[0];
         StoreId id      = (StoreId)result[2];
         if (this.currentFolderId == null)
         {
             this.currentFolderId = id;
         }
         if (this.fetchedItemCount >= this.batchedItemBuffer.Length || !this.currentFolderId.Equals(id))
         {
             this.ProcessCurrentBatch();
             this.fetchedItemCount = 0;
             this.currentFolderId  = id;
             if (this.searchCommunicator.IsAborted)
             {
                 return;
             }
         }
         this.batchedItemBuffer[this.fetchedItemCount++] = result;
         return;
     }
     SearchResultProcessor.Tracer.TraceDebug((long)this.GetHashCode(), "Item is skipped because the itemId or ParentItemId is unavailable");
 }
        private ByteQuantifiedSize CalculateBatchSize(object[][] batchedItemBuffer, int fetchedItemCount)
        {
            ByteQuantifiedSize byteQuantifiedSize = ByteQuantifiedSize.Zero;

            for (int i = 0; i < fetchedItemCount; i++)
            {
                if (SearchResultProcessor.PropertyExists(batchedItemBuffer[i][1]))
                {
                    byteQuantifiedSize += (int)batchedItemBuffer[i][1];
                }
            }
            return(byteQuantifiedSize);
        }
        private void ProcessFolderItems(Folder folder, MailboxSession sourceMailbox, MailboxSession targetMailbox, double maxProgress)
        {
            double mailboxProgress  = this.searchWorker.MailboxProgress;
            int    resultItemsCount = this.searchWorker.SearchResult.ResultItemsCount;

            using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, new SortBy[]
            {
                new SortBy(StoreObjectSchema.ParentEntryId, SortOrder.Ascending)
            }, SearchResultProcessor.ItemPreloadProperties))
            {
                while (!this.searchCommunicator.IsAborted)
                {
                    this.BackOffFromSourceStore();
                    object[][] rows = queryResult.GetRows(this.batchedItemBuffer.Length);
                    if (rows == null || rows.Length <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < rows.Length; i++)
                    {
                        this.ProcessSingleResult(rows[i]);
                        this.searchWorker.SearchResult.ResultItemsCount++;
                        StoreId       storeId       = (StoreId)rows[i][0];
                        StoreObjectId storeObjectId = StoreId.GetStoreObjectId(storeId);
                        if (this.unsearchableItemSet != null && storeObjectId != null && this.unsearchableItemSet.Contains(storeObjectId))
                        {
                            this.unsearchableItemSet.Remove(storeObjectId);
                        }
                        if (SearchResultProcessor.PropertyExists(rows[i][1]))
                        {
                            this.searchWorker.SearchResult.ResultItemsSize += (int)rows[i][1];
                        }
                        else
                        {
                            SearchResultProcessor.Tracer.TraceDebug <StoreId>((long)this.GetHashCode(), "Unable to retrieve message size for message {0}", storeId);
                        }
                        int    num      = this.searchWorker.SearchResult.ResultItemsCount - resultItemsCount;
                        double progress = this.CalcProgress(num, Math.Max(queryResult.EstimatedRowCount, num), mailboxProgress, maxProgress);
                        this.UpdateProgress(progress, 10.0);
                    }
                }
            }
        }
        private string[] GetUniqueFolderName(MailboxSession mailboxStore, StoreId folderId, string[] suggestedNames)
        {
            List <string> subFolderNames = new List <string>();

            using (Folder folder = Folder.Bind(mailboxStore, folderId))
            {
                using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, null, new PropertyDefinition[]
                {
                    FolderSchema.DisplayName
                }))
                {
                    ElcMailboxHelper.ForeachQueryResult(queryResult, delegate(object[] rowProps, ref bool breakLoop)
                    {
                        if (SearchResultProcessor.PropertyExists(rowProps[0]))
                        {
                            subFolderNames.Add((string)rowProps[0]);
                        }
                    });
                }
            }
            string[] array = new string[suggestedNames.Length];
            for (int i = 0; i < suggestedNames.Length; i++)
            {
                string        folderName = suggestedNames[i];
                List <string> list       = (from x in subFolderNames
                                            where x.StartsWith(folderName, StringComparison.OrdinalIgnoreCase)
                                            select x).ToList <string>();
                for (int j = 0; j < list.Count + 1; j++)
                {
                    if (list.Find((string x) => x.Equals(folderName, StringComparison.OrdinalIgnoreCase)) == null)
                    {
                        break;
                    }
                    folderName = string.Format("{0}-{1}", suggestedNames[i], j + 1);
                }
                array[i] = folderName;
            }
            return(array);
        }
 public override void PerformBatchOperation(object[][] batchedItemBuffer, int fetchedItemCount, StoreId currentFolderId, MailboxSession sourceMailbox, MailboxSession targetMailbox, Dictionary <StoreId, FolderNode> folderNodeMap, SearchResultProcessor processor)
 {
     if (this.loggingLevel != LoggingLevel.Full)
     {
         return;
     }
     LocalizedString[] array = new LocalizedString[fetchedItemCount];
     for (int i = 0; i < fetchedItemCount; i++)
     {
         VersionedId versionedId = (VersionedId)batchedItemBuffer[i][0];
         string      text        = SearchMailboxAction.PropertyExists(batchedItemBuffer[i][3]) ? ((string)batchedItemBuffer[i][3]) : string.Empty;
         bool?       flag        = null;
         if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][4]))
         {
             flag = new bool?((bool)batchedItemBuffer[i][4]);
         }
         ExDateTime?exDateTime = null;
         if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][5]))
         {
             exDateTime = new ExDateTime?((ExDateTime)batchedItemBuffer[i][5]);
         }
         ExDateTime?exDateTime2 = null;
         if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][6]))
         {
             exDateTime2 = new ExDateTime?((ExDateTime)batchedItemBuffer[i][6]);
         }
         Participant participant = null;
         if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][7]))
         {
             participant = (Participant)batchedItemBuffer[i][7];
         }
         string text2 = null;
         if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][8]))
         {
             text2 = (string)batchedItemBuffer[i][8];
         }
         string text3       = (participant != null) ? participant.DisplayName : string.Empty;
         string text4       = (participant != null) ? participant.EmailAddress : string.Empty;
         string displayName = folderNodeMap[currentFolderId].DisplayName;
         array[i] = new LocalizedString(string.Format("{0},\"{1}\",\"{2}\",{3},{4},{5},{6},{7},{8}", new object[]
         {
             sourceMailbox.MailboxOwner.MailboxInfo.DisplayName,
             displayName,
             text,
             flag,
             exDateTime,
             exDateTime2,
             text3,
             text2 ?? text4,
             versionedId.ObjectId
         }));
     }
     StreamLogItem.LogItem logItem = new StreamLogItem.LogItem(processor.WorkerId, array);
     processor.ReportLogs(logItem);
 }
示例#6
0
        private static bool DeleteItemByItem(object[][] batchedItemBuffer, int fetchedItemCount, StoreId currentFolderId, MailboxSession sourceMailbox, SearchResultProcessor processor, out string message)
        {
            StringBuilder stringBuilder = new StringBuilder();
            bool          result        = true;

            using (Folder folder = Folder.Bind(sourceMailbox, currentFolderId))
            {
                for (int i = 0; i < fetchedItemCount; i++)
                {
                    StoreId storeId = (StoreId)batchedItemBuffer[i][0];
                    if (!DeleteSearchMailboxAction.ItemSuccessfullyDeleted(sourceMailbox, storeId))
                    {
                        lock (sourceMailbox)
                        {
                            if (processor.IsAborted())
                            {
                                message = stringBuilder.ToString();
                                return(result);
                            }
                            AggregateOperationResult aggregateOperationResult = folder.DeleteObjects(DeleteItemFlags.HardDelete, new StoreId[]
                            {
                                storeId
                            });
                            if (aggregateOperationResult.OperationResult != OperationResult.Succeeded)
                            {
                                foreach (GroupOperationResult groupOperationResult in aggregateOperationResult.GroupOperationResults)
                                {
                                    if (groupOperationResult.OperationResult != OperationResult.Succeeded)
                                    {
                                        result = false;
                                        string text  = SearchMailboxAction.PropertyExists(batchedItemBuffer[i][3]) ? ((string)batchedItemBuffer[i][3]) : string.Empty;
                                        bool?  flag2 = null;
                                        if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][4]))
                                        {
                                            flag2 = new bool?((bool)batchedItemBuffer[i][4]);
                                        }
                                        ExDateTime?exDateTime = null;
                                        if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][5]))
                                        {
                                            exDateTime = new ExDateTime?((ExDateTime)batchedItemBuffer[i][5]);
                                        }
                                        ExDateTime?exDateTime2 = null;
                                        if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][6]))
                                        {
                                            exDateTime2 = new ExDateTime?((ExDateTime)batchedItemBuffer[i][6]);
                                        }
                                        Participant participant = null;
                                        if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][7]))
                                        {
                                            participant = (Participant)batchedItemBuffer[i][7];
                                        }
                                        string text2 = null;
                                        if (SearchMailboxAction.PropertyExists(batchedItemBuffer[i][8]))
                                        {
                                            text2 = (string)batchedItemBuffer[i][8];
                                        }
                                        string text3 = (participant != null) ? participant.DisplayName : string.Empty;
                                        string text4 = (participant != null) ? participant.EmailAddress : string.Empty;
                                        string text5 = (folder != null) ? folder.DisplayName : string.Empty;
                                        stringBuilder.Append(string.Format("\n{0}:\n {1},\"{2}\",\"{3}\",{4},{5},{6},{7},{8},{9}", new object[]
                                        {
                                            Strings.DeleteItemFailedForMessage(groupOperationResult.Exception.Message),
                                            sourceMailbox.MailboxOwner.MailboxInfo.DisplayName,
                                            text5,
                                            text,
                                            flag2,
                                            exDateTime,
                                            exDateTime2,
                                            text3,
                                            text2 ?? text4,
                                            ((VersionedId)storeId).ObjectId
                                        }));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            message = stringBuilder.ToString();
            return(result);
        }
示例#7
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);
                }
            }
        }
示例#9
0
 public abstract void PerformBatchOperation(object[][] batchedItemBuffer, int fetchedItemCount, StoreId currentFolderId, MailboxSession sourceMailbox, MailboxSession targetMailbox, Dictionary <StoreId, FolderNode> folderNodeMap, SearchResultProcessor processor);