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);
        }