Ejemplo n.º 1
0
 public void MessageExportWithBadMessageDetection(ISourceMailbox mailbox, List <MessageRec> messages, ExportMessagesFlags flags, PropTag[] excludeProps, bool isDownlevelClient)
 {
     this.RunExportThread(delegate
     {
         List <BadMessageRec> list = new List <BadMessageRec>();
         MapiUtils.ExportMessagesWithBadItemDetection(mailbox, messages, delegate
         {
             BufferedTransmitter destination      = new BufferedTransmitter(this, this.service.ExportBufferSizeFromMrsKB, false, this.service.UseBufferring, this.service.UseCompression);
             AsynchronousTransmitter destination2 = new AsynchronousTransmitter(destination, true);
             return(new FxProxyPoolTransmitter(destination2, true, this.service.ClientVersion));
         }, flags, null, excludeProps, TestIntegration.Instance, ref list);
         if (list != null && list.Count > 0)
         {
             MessageExportResultTransmitter messageExportResultTransmitter = new MessageExportResultTransmitter(this, isDownlevelClient);
             messageExportResultTransmitter.SendMessageExportResults(list);
             ((IDataImport)this).SendMessageAndWaitForReply(FlushMessage.Instance);
         }
     });
 }
Ejemplo n.º 2
0
        private void CopyMessageBatch(FolderContentsMapper mapper, List <MessageRec> itemsToCopy, FolderMapping fm)
        {
            if (itemsToCopy == null || itemsToCopy.Count == 0)
            {
                return;
            }
            MrsTracer.Service.Debug("Sorting {0} messages in folder '{1}'", new object[]
            {
                itemsToCopy.Count,
                fm.FullFolderName
            });
            MessageRecSorter           messageRecSorter = new MessageRecSorter();
            Queue <List <MessageRec> > queue            = messageRecSorter.Sort(itemsToCopy, (base.MRSJob.CachedRequestJob.SyncProtocol == SyncProtocol.Imap) ? MessageRecSortBy.SkipSort : MessageRecSortBy.DescendingTimeStamp);

            byte[][] folderIDs = new byte[][]
            {
                fm.TargetFolder.EntryId
            };
            while (queue.Count > 0)
            {
                base.MRSJob.CheckServersHealth();
                List <MessageRec> list = queue.Dequeue();
                ulong             num  = 0UL;
                foreach (MessageRec messageRec in list)
                {
                    num += (ulong)((long)messageRec.MessageSize);
                }
                MrsTracer.Service.Debug("Copying a batch of {0} messages, {1}", new object[]
                {
                    list.Count,
                    new ByteQuantifiedSize(num)
                });
                List <BadMessageRec> list2 = new List <BadMessageRec>();
                MapiUtils.ExportMessagesWithBadItemDetection(base.SourceMailbox, list, delegate
                {
                    IFxProxyPool fxProxyPool        = this.DestMailbox.GetFxProxyPool(folderIDs);
                    IFxProxyPool fxProxyTransformer = mapper.GetFxProxyTransformer(fxProxyPool);
                    return(this.CreateFxProxyPoolTransmissionPipeline(fxProxyTransformer));
                }, ExportMessagesFlags.OneByOne, ((base.Flags & MailboxCopierFlags.TargetIsPST) != MailboxCopierFlags.None) ? MailboxCopierBase.PSTIncludeMessagePtags : null, null, base.MRSJob.TestIntegration, ref list2);
                if (list2 != null && list2.Count > 0)
                {
                    List <BadMessageRec> list3 = new List <BadMessageRec>();
                    foreach (BadMessageRec badMessageRec in list2)
                    {
                        if (badMessageRec.Kind == BadItemKind.MissingItem)
                        {
                            MrsTracer.Service.Warning("Message {0} is missing in source, skipping.", new object[]
                            {
                                TraceUtils.DumpEntryId(badMessageRec.EntryId)
                            });
                        }
                        else
                        {
                            list3.Add(badMessageRec);
                        }
                    }
                    this.ReportBadItems(list3);
                }
                if (base.MRSJob.TestIntegration.LogContentDetails)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(string.Format("CopyMessageBatch: {0} items copied", list.Count));
                    foreach (MessageRec messageRec2 in list)
                    {
                        stringBuilder.AppendLine(string.Format("ItemID {0}, FolderID {1}{2}", TraceUtils.DumpEntryId(messageRec2.EntryId), TraceUtils.DumpEntryId(messageRec2.FolderId), messageRec2.IsFAI ? ", FAI" : string.Empty));
                    }
                    base.MRSJob.Report.AppendDebug(stringBuilder.ToString());
                }
                base.MRSJob.MessagesWritten    += list.Count;
                base.MRSJob.MessageSizeWritten += num;
                base.MRSJob.ProgressTracker.AddItems((uint)list.Count);
                SaveStateFlags saveStateFlags = SaveStateFlags.Lazy;
                if (num > 0UL)
                {
                    base.UpdateTimestampWhenPersistentProgressWasMade();
                    saveStateFlags |= SaveStateFlags.RelinquishLongRunningJob;
                }
                base.MRSJob.SaveState(saveStateFlags, null);
            }
        }
Ejemplo n.º 3
0
        public static void ExportMessagesWithBadItemDetection(ISourceMailbox mailbox, List <MessageRec> messages, Func <IFxProxyPool> getProxyPool, ExportMessagesFlags flags, PropTag[] propsToCopyExplicitly, PropTag[] excludeProps, TestIntegration testIntegration, ref List <BadMessageRec> badMessages)
        {
            MrsTracer.Common.Debug("ExportMessagesWithBadItemDetection: Exporting {0} messages", new object[]
            {
                messages.Count
            });
            Exception ex;

            if (MapiUtils.ExportMessageBatch(mailbox, messages, getProxyPool, flags, propsToCopyExplicitly, excludeProps, testIntegration, out ex))
            {
                return;
            }
            MrsTracer.Common.Warning("ExportMessages failed with a bad item error. Current batch count {0}. Will retry copying messages in smaller batches. {1}", new object[]
            {
                messages.Count,
                CommonUtils.FullExceptionMessage(ex)
            });
            if (messages.Count != 1)
            {
                int num = messages.Count / 2;
                List <MessageRec> list  = new List <MessageRec>(num);
                List <MessageRec> list2 = new List <MessageRec>(messages.Count - num);
                for (int i = 0; i < messages.Count; i++)
                {
                    if (i < num)
                    {
                        list.Add(messages[i]);
                    }
                    else
                    {
                        list2.Add(messages[i]);
                    }
                }
                MapiUtils.ExportMessagesWithBadItemDetection(mailbox, list, getProxyPool, flags, propsToCopyExplicitly, excludeProps, testIntegration, ref badMessages);
                MapiUtils.ExportMessagesWithBadItemDetection(mailbox, list2, getProxyPool, flags, propsToCopyExplicitly, excludeProps, testIntegration, ref badMessages);
                return;
            }
            MessageRec messageRec = messages[0];

            MrsTracer.Common.Warning("Single message {0} copy failed. Error {1}", new object[]
            {
                TraceUtils.DumpEntryId(messageRec.EntryId),
                CommonUtils.FullExceptionMessage(ex)
            });
            EntryIdMap <MessageRec> entryIdMap;
            EntryIdMap <FolderRec>  entryIdMap2;

            MapiUtils.LookupBadMessagesInMailbox(mailbox, messages, out entryIdMap, out entryIdMap2);
            MessageRec msgData;

            if (!entryIdMap.TryGetValue(messageRec.EntryId, out msgData))
            {
                badMessages.Add(BadMessageRec.MissingItem(messageRec));
                return;
            }
            DownlevelBadItemsPermanentException ex2 = ex as DownlevelBadItemsPermanentException;

            if (ex2 != null)
            {
                badMessages.Add(ex2.BadItems[0]);
                return;
            }
            FolderRec folderRec = entryIdMap2[messageRec.FolderId];

            badMessages.Add(BadMessageRec.Item(msgData, folderRec, ex));
        }