public override void RunNow(Guid mailboxGuid, string parameters)
        {
            StoreMailboxData mailboxData;

            using (ExRpcAdmin exRpcAdmin = ExRpcAdmin.Create("Client=TBA", null, null, null, null))
            {
                try
                {
                    PropValue[][] mailboxTableInfo = exRpcAdmin.GetMailboxTableInfo(base.DatabaseInfo.Guid, mailboxGuid, new PropTag[]
                    {
                        PropTag.MailboxType,
                        PropTag.PersistableTenantPartitionHint,
                        PropTag.LastLogonTime
                    });
                    if (mailboxTableInfo.Length != 1 || mailboxTableInfo[0].Length < 1)
                    {
                        throw new InvalidOperationException("Failed to get the mailbox property");
                    }
                    PropValue           mailboxProperty     = MailboxTableQuery.GetMailboxProperty(mailboxTableInfo[0], PropTag.PersistableTenantPartitionHint);
                    TenantPartitionHint tenantPartitionHint = null;
                    if (mailboxProperty.PropTag == PropTag.PersistableTenantPartitionHint)
                    {
                        byte[] bytes = mailboxProperty.GetBytes();
                        if (bytes != null && bytes.Length != 0)
                        {
                            tenantPartitionHint = TenantPartitionHint.FromPersistablePartitionHint(bytes);
                        }
                    }
                    if (string.IsNullOrEmpty(parameters))
                    {
                        MailboxInformation mailboxInformation = MailboxInformation.Create(mailboxGuid.ToByteArray(), base.DatabaseInfo.Guid, mailboxGuid.ToString(), ControlData.Empty, mailboxTableInfo[0], MailboxInformation.GetLastLogonTime(mailboxTableInfo[0]), tenantPartitionHint);
                        mailboxData = mailboxInformation.MailboxData;
                    }
                    else
                    {
                        mailboxData = new MailboxDataForDemandJob(mailboxGuid, base.DatabaseInfo.Guid, null, parameters, tenantPartitionHint);
                    }
                }
                catch (MapiExceptionNotFound arg)
                {
                    ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedStoreDatabaseDriver, MapiExceptionNotFound>((long)this.GetHashCode(), "{0}: Mailbox does not exist on the store: {1}", this, arg);
                    if (string.IsNullOrEmpty(parameters))
                    {
                        mailboxData = new StoreMailboxData(mailboxGuid, base.DatabaseInfo.Guid, mailboxGuid.ToString(), null);
                    }
                    else
                    {
                        mailboxData = new MailboxDataForDemandJob(mailboxGuid, base.DatabaseInfo.Guid, null, parameters);
                    }
                }
            }
            ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedStoreDatabaseDriver, Guid>((long)this.GetHashCode(), "{0}: RunNow: about to start processing mailbox {1} on this database.", this, mailboxGuid);
            base.RunNow(mailboxData);
        }
        private static string GetTenantId(IStoreSession session)
        {
            string result = string.Empty;

            byte[] valueOrDefault = session.Mailbox.GetValueOrDefault <byte[]>(MailboxSchema.PersistableTenantPartitionHint, null);
            if (valueOrDefault != null && valueOrDefault.Length > 0)
            {
                TenantPartitionHint tenantPartitionHint = TenantPartitionHint.FromPersistablePartitionHint(valueOrDefault);
                Guid externalDirectoryOrganizationId    = tenantPartitionHint.GetExternalDirectoryOrganizationId();
                result = (Guid.Empty.Equals(externalDirectoryOrganizationId) ? string.Empty : externalDirectoryOrganizationId.ToString());
            }
            return(result);
        }
        public static TenantPartitionHintAdapter FromPersistableTenantPartitionHint(byte[] persistedData)
        {
            TenantPartitionHint partitionHint;

            if (persistedData == null)
            {
                partitionHint = TenantPartitionHint.FromOrganizationId(OrganizationId.ForestWideOrgId);
            }
            else
            {
                partitionHint = TenantPartitionHint.FromPersistablePartitionHint(persistedData);
            }
            return(TenantPartitionHintAdapter.FromPartitionHint(partitionHint));
        }
Exemplo n.º 4
0
        // Token: 0x06001561 RID: 5473 RVA: 0x00079BAC File Offset: 0x00077DAC
        public MailboxProcessorMailboxData(DatabaseInfo databaseInfo, Guid mailboxGuid, int mailboxNumber, PropValue[] row) : base(mailboxGuid, mailboxNumber, databaseInfo.Guid)
        {
            MailboxProcessorAssistantType.TraceInformation(0L, "Retrieving mailbox information for database {0}", new object[]
            {
                databaseInfo.Guid
            });
            this.DatabaseName = databaseInfo.DatabaseName;
            PropValue mailboxProperty = MailboxTableQuery.GetMailboxProperty(row, PropTag.MailboxMiscFlags);

            if (mailboxProperty.PropTag == PropTag.MailboxMiscFlags)
            {
                MailboxMiscFlags @int = (MailboxMiscFlags)mailboxProperty.GetInt();
                this.IsMoveDestination = ((@int & MailboxMiscFlags.CreatedByMove) == MailboxMiscFlags.CreatedByMove);
                this.IsArchive         = ((@int & MailboxMiscFlags.ArchiveMailbox) == MailboxMiscFlags.ArchiveMailbox);
            }
            else
            {
                MailboxProcessorAssistantType.TraceInformation(0L, "Cannot retrieve property MailboxMiscFlags for Mailbox with GUID {0}", new object[]
                {
                    mailboxGuid
                });
                this.IsMoveDestination = false;
                this.IsArchive         = false;
            }
            PropValue mailboxProperty2 = MailboxTableQuery.GetMailboxProperty(row, PropTag.PersistableTenantPartitionHint);

            this.TenantPartitionHint = null;
            if (mailboxProperty2.PropTag == PropTag.PersistableTenantPartitionHint)
            {
                byte[] bytes = mailboxProperty2.GetBytes();
                if (bytes != null && bytes.Length != 0)
                {
                    this.TenantPartitionHint = TenantPartitionHint.FromPersistablePartitionHint(bytes);
                }
            }
            else
            {
                MailboxProcessorAssistantType.TraceInformation(0L, "Cannot retrieve property PersistableTenantPartitionHint for Mailbox with GUID {0}", new object[]
                {
                    mailboxGuid
                });
            }
            MailboxProcessorAssistantType.TraceInformation(0L, "Found mailbox with GUID {0}. Is archive: {1}", new object[]
            {
                mailboxGuid,
                this.IsArchive
            });
        }
Exemplo n.º 5
0
 private void LoadMailboxOwner(byte[] tenantPartitionHintBlob, string nonLocalizedAssistantName)
 {
     if (this.mailboxOwner == null)
     {
         this.InvokeAndMapException(delegate
         {
             ExTraceGlobals.EventDispatcherTracer.TraceDebug <MailboxDispatcher>((long)this.GetHashCode(), "{0}: Looking up ExchangePrincipal...", this);
             ADSessionSettings adSettings;
             if (tenantPartitionHintBlob != null && tenantPartitionHintBlob.Length != 0)
             {
                 adSettings = ADSessionSettings.FromTenantPartitionHint(TenantPartitionHint.FromPersistablePartitionHint(tenantPartitionHintBlob));
             }
             else
             {
                 adSettings = ADSessionSettings.FromRootOrgScopeSet();
             }
             this.mailboxOwner = ExchangePrincipal.FromLocalServerMailboxGuid(adSettings, this.DatabaseInfo.Guid, this.MailboxGuid);
         }, nonLocalizedAssistantName);
     }
 }
Exemplo n.º 6
0
 public MoveJob(PropValue[] properties, Guid requestQueueGuid)
 {
     this.JobType = MapiUtils.GetValue <MRSJobType>(properties[9], MRSJobType.Unknown);
     if (!RequestJobXML.IsKnownJobType(this.JobType))
     {
         MrsTracer.Service.Debug("Skipping unknown jobType {0}", new object[]
         {
             (int)this.JobType
         });
         return;
     }
     this.RequestGuid         = MapiUtils.GetValue <Guid>(properties[26], Guid.Empty);
     this.ExchangeGuid        = MapiUtils.GetValue <Guid>(properties[5], Guid.Empty);
     this.ArchiveGuid         = MapiUtils.GetValue <Guid>(properties[6], Guid.Empty);
     this.CancelRequest       = MapiUtils.GetValue <bool>(properties[4], false);
     this.MrsServerName       = MapiUtils.GetValue <string>(properties[2], null);
     this.Status              = MapiUtils.GetValue <RequestStatus>(properties[0], RequestStatus.None);
     this.JobState            = MapiUtils.GetValue <JobProcessingState>(properties[1], JobProcessingState.NotReady);
     this.LastUpdateTimeStamp = MapiUtils.GetValue <DateTime>(properties[7], DateTime.MinValue);
     this.Flags = MapiUtils.GetValue <RequestFlags>(properties[10], RequestFlags.None);
     this.SourceDatabaseGuid        = MapiUtils.GetValue <Guid>(properties[11], Guid.Empty);
     this.TargetDatabaseGuid        = MapiUtils.GetValue <Guid>(properties[12], Guid.Empty);
     this.SourceArchiveDatabaseGuid = MapiUtils.GetValue <Guid>(properties[15], Guid.Empty);
     this.TargetArchiveDatabaseGuid = MapiUtils.GetValue <Guid>(properties[16], Guid.Empty);
     this.Priority = MapiUtils.GetValue <int>(properties[17], -1);
     this.DoNotPickUntilTimestamp = MapiUtils.GetValue <DateTime>(properties[13], DateTime.MinValue);
     this.RequestType             = MapiUtils.GetValue <MRSRequestType>(properties[14], MRSRequestType.Move);
     this.MessageID          = MapiUtils.GetValue <byte[]>(properties[27], null);
     this.SourceExchangeGuid = MapiUtils.GetValue <Guid>(properties[18], Guid.Empty);
     this.TargetExchangeGuid = MapiUtils.GetValue <Guid>(properties[19], Guid.Empty);
     this.RehomeRequest      = MapiUtils.GetValue <bool>(properties[20], false);
     this.InternalFlags      = MapiUtils.GetValue <RequestJobInternalFlags>(properties[21], RequestJobInternalFlags.None);
     this.PoisonCount        = MapiUtils.GetValue <int>(properties[23], 0);
     this.FailureType        = MapiUtils.GetValue <string>(properties[24], null);
     this.WorkloadType       = MapiUtils.GetValue <RequestWorkloadType>(properties[25], RequestWorkloadType.None);
     byte[] value = MapiUtils.GetValue <byte[]>(properties[22], null);
     this.PartitionHint             = ((value != null && value.Length > 0) ? TenantPartitionHint.FromPersistablePartitionHint(value) : null);
     this.RequestQueueGuid          = requestQueueGuid;
     this.IsActiveOnThisMRSInstance = MRSService.JobIsActive(this.RequestGuid);
     this.isInteractive             = MoveJob.IsInteractive(this.RequestType, this.WorkloadType);
 }
        protected override List <MailboxData> GetMailboxesForCurrentWindow(out int totalMailboxOnDatabaseCount, out int notInterestingMailboxCount, out int filteredMailboxCount, out int failedFilteringCount)
        {
            Guid activityId = Guid.NewGuid();

            PropTag[]     mailboxProperties = this.GetMailboxProperties();
            PropValue[][] mailboxes         = MailboxTableQuery.GetMailboxes("Client=TBA", base.DatabaseInfo, mailboxProperties);
            totalMailboxOnDatabaseCount = ((mailboxes == null) ? 0 : mailboxes.Length);
            notInterestingMailboxCount  = 0;
            filteredMailboxCount        = 0;
            failedFilteringCount        = 0;
            AssistantsLog.LogGetMailboxesQueryEvent(activityId, base.Assistant.NonLocalizedName, totalMailboxOnDatabaseCount, base.Assistant as AssistantBase);
            if (mailboxes == null)
            {
                return(new List <MailboxData>());
            }
            List <MailboxInformation> list3 = new List <MailboxInformation>(mailboxes.Length);
            Guid mailboxGuid = Guid.Empty;
            VariantConfigurationSnapshot snapshot    = VariantConfiguration.GetSnapshot(DatabaseSettingsContext.Get(base.DatabaseInfo.Guid), null, null);
            TimeSpan notInterestingLogInterval       = snapshot.MailboxAssistants.GetObject <IMailboxAssistantSettings>(base.AssistantType.Identifier, new object[0]).MailboxNotInterestingLogInterval;
            int      filteredMailboxCountLocal       = 0;
            int      notInterestingMailboxCountLocal = 0;
            string   traceMessage;

            foreach (PropValue[] propertiesForDelegateClosure2 in mailboxes)
            {
                try
                {
                    PropValue[] propertiesForDelegateClosure = propertiesForDelegateClosure2;
                    List <MailboxInformation> list           = list3;
                    base.CatchMeIfYouCan(delegate
                    {
                        PropValue mailboxProperty  = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.UserGuid);
                        PropValue mailboxProperty2 = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.DisplayName);
                        string mailboxDisplayNameTracingOnlyUsage = (mailboxProperty2.IsNull() || mailboxProperty2.Value == null) ? string.Empty : mailboxProperty2.Value.ToString();
                        if (mailboxProperty.PropTag != PropTag.UserGuid || mailboxProperty2.PropTag != PropTag.DisplayName)
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxNoGuidFilter, MailboxSlaFilterReasonType.NoGuid, new object[]
                            {
                                mailboxProperty.Value
                            });
                            filteredMailboxCountLocal++;
                            return;
                        }
                        byte[] bytes = mailboxProperty.GetBytes();
                        if (bytes != null && bytes.Length == 16)
                        {
                            mailboxGuid = new Guid(bytes);
                        }
                        if (MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.DateDiscoveredAbsentInDS).PropTag == PropTag.DateDiscoveredAbsentInDS)
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxNotInDirectoryFilter, MailboxSlaFilterReasonType.NotInDirectory, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        PropValue mailboxProperty3 = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.MailboxMiscFlags);
                        MailboxMiscFlags @int      = (MailboxMiscFlags)mailboxProperty3.GetInt(0);
                        if ((@int & MailboxMiscFlags.CreatedByMove) == MailboxMiscFlags.CreatedByMove)
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxMoveDestinationFilter, MailboxSlaFilterReasonType.MoveDestination, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        MailboxMiscFlags mailboxMiscFlags = @int & (MailboxMiscFlags.DisabledMailbox | MailboxMiscFlags.SoftDeletedMailbox | MailboxMiscFlags.MRSSoftDeletedMailbox);
                        if (mailboxMiscFlags != MailboxMiscFlags.None)
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxInaccessibleFilter, MailboxSlaFilterReasonType.Inaccessible, new object[]
                            {
                                mailboxMiscFlags
                            });
                            filteredMailboxCountLocal++;
                            return;
                        }
                        IMailboxFilter mailboxFilter = this.AssistantType as IMailboxFilter;
                        if (mailboxFilter != null && mailboxProperty3.PropTag == PropTag.MailboxMiscFlags)
                        {
                            MailboxMiscFlags int2 = (MailboxMiscFlags)mailboxProperty3.GetInt();
                            bool flag             = (int2 & MailboxMiscFlags.ArchiveMailbox) == MailboxMiscFlags.ArchiveMailbox;
                            if (flag && !mailboxFilter.MailboxType.Contains(MailboxType.Archive))
                            {
                                this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxArchiveFilter, MailboxSlaFilterReasonType.Archive, new object[0]);
                                filteredMailboxCountLocal++;
                                return;
                            }
                        }
                        ControlData controlData = ControlData.Empty;
                        if (this.AssistantType.ControlDataPropertyDefinition != null)
                        {
                            PropValue mailboxProperty4 = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, (PropTag)this.AssistantType.ControlDataPropertyDefinition.PropertyTag);
                            if (mailboxProperty4.PropTag == (PropTag)this.AssistantType.ControlDataPropertyDefinition.PropertyTag)
                            {
                                controlData = ControlData.CreateFromByteArray(mailboxProperty4.GetBytes());
                            }
                        }
                        TenantPartitionHint tenantPartitionHint = null;
                        PropValue mailboxProperty5 = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.PersistableTenantPartitionHint);
                        if (mailboxProperty5.PropTag == PropTag.PersistableTenantPartitionHint)
                        {
                            byte[] bytes2 = mailboxProperty5.GetBytes();
                            if (bytes2 != null && bytes2.Length != 0)
                            {
                                tenantPartitionHint = TenantPartitionHint.FromPersistablePartitionHint(bytes2);
                            }
                        }
                        MailboxInformation mailboxInformation2 = MailboxInformation.Create(mailboxProperty.GetBytes(), this.DatabaseInfo.Guid, mailboxProperty2.GetString(), controlData, propertiesForDelegateClosure, MailboxInformation.GetLastLogonTime(propertiesForDelegateClosure), tenantPartitionHint);
                        if (!this.DatabaseInfo.IsUserMailbox(mailboxInformation2.MailboxGuid))
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxNotUserFilter, MailboxSlaFilterReasonType.NotUser, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        if (mailboxInformation2.MailboxData.IsPublicFolderMailbox && (mailboxFilter == null || !mailboxFilter.MailboxType.Contains(MailboxType.PublicFolder)))
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxPublicFolderFilter, MailboxSlaFilterReasonType.PublicFolder, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        if (this.IsMailboxInDemandJob(mailboxInformation2.MailboxData))
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxInDemandJobFilter, MailboxSlaFilterReasonType.InDemandJob, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        if (this.AssistantType.MailboxExtendedProperties != null)
                        {
                            if (!this.AssistantType.IsMailboxInteresting(mailboxInformation2))
                            {
                                traceMessage = string.Format("{0}: {1} is not interesting for the assistant {2}.", this, mailboxGuid, this.Assistant.NonLocalizedName);
                                ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug((long)this.GetHashCode(), traceMessage);
                                DateTime utcNow = DateTime.UtcNow;
                                if (!this.notInterestingEventsLastLogDateTimes.ContainsKey(this.Assistant.NonLocalizedName) || utcNow - this.notInterestingEventsLastLogDateTimes[this.Assistant.NonLocalizedName] >= notInterestingLogInterval)
                                {
                                    AssistantsLog.LogMailboxNotInterestingEvent(activityId, this.Assistant.NonLocalizedName, this.Assistant as AssistantBase, mailboxGuid, mailboxDisplayNameTracingOnlyUsage);
                                    this.notInterestingEventsLastLogDateTimes[this.Assistant.NonLocalizedName] = utcNow;
                                }
                                notInterestingMailboxCountLocal++;
                                return;
                            }
                        }
                        else
                        {
                            traceMessage = string.Format("{0}: {1} mailbox properties are null, IsMailboxInteresting was not called.", this, mailboxGuid);
                            ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug((long)this.GetHashCode(), traceMessage);
                        }
                        traceMessage = string.Format("{0}: {1} is interesting for the assistant {2}.", this, mailboxGuid, this.Assistant.NonLocalizedName);
                        ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug((long)this.GetHashCode(), traceMessage);
                        AssistantsLog.LogMailboxInterestingEvent(activityId, this.Assistant.NonLocalizedName, this.Assistant as AssistantBase, null, mailboxGuid, mailboxDisplayNameTracingOnlyUsage);
                        list.Add(mailboxInformation2);
                    }, base.AssistantType.NonLocalizedName);
                }
                catch (AIException exception)
                {
                    failedFilteringCount++;
                    AssistantsLog.LogErrorEnumeratingMailboxes(base.Assistant, mailboxGuid, exception, true);
                }
                catch (Exception exception2)
                {
                    AssistantsLog.LogErrorEnumeratingMailboxes(base.Assistant, mailboxGuid, exception2, false);
                    throw;
                }
            }
            traceMessage = string.Format("{0}: {1} mailboxes after filtering", this, list3.Count);
            ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug((long)this.GetHashCode(), traceMessage);
            if (this.firstIteration || base.AssistantType.WorkCycleCheckpoint < base.AssistantType.WorkCycle)
            {
                int count = list3.Count;
                list3 = list3.FindAll((MailboxInformation mailbox) => DateTime.UtcNow - mailbox.LastProcessedDate > base.AssistantType.WorkCycle - base.AssistantType.WorkCycleCheckpoint);
                this.firstIteration        = false;
                filteredMailboxCountLocal += count - list3.Count;
            }
            list3.Sort((MailboxInformation m1, MailboxInformation m2) => m1.LastProcessedDate.CompareTo(m2.LastProcessedDate));
            List <MailboxData> list2 = new List <MailboxData>();

            foreach (MailboxInformation mailboxInformation in list3)
            {
                list2.Add(mailboxInformation.MailboxData);
            }
            AssistantsLog.LogEndGetMailboxesEvent(activityId, base.Assistant.NonLocalizedName, list2.Count, base.Assistant as AssistantBase);
            filteredMailboxCount       = filteredMailboxCountLocal;
            notInterestingMailboxCount = notInterestingMailboxCountLocal;
            return(list2);
        }
Exemplo n.º 8
0
        // Token: 0x06000024 RID: 36 RVA: 0x000030E0 File Offset: 0x000012E0
        public void HandleEvent(MapiEvent mapiEvent, MailboxSession itemStore, StoreObject item)
        {
            MailboxTransportSubmissionAssistant.IdentifyProbeMessage(mapiEvent);
            Thread currentThread = Thread.CurrentThread;

            try
            {
                Interlocked.Increment(ref this.concurrentEvents);
                this.SubmissionsInProgress[currentThread] = new SubmissionsInProgress.Entry(ExDateTime.UtcNow, this.databaseInfo.Guid, mapiEvent);
                using (new SenderGuidTraceFilter(this.databaseInfo.Guid, mapiEvent.MailboxGuid))
                {
                    bool flag = true;
                    MailboxTransportSubmissionAssistant.LatencyRecord latencyRecord;
                    LatencyTracker latencyTracker;
                    if (MailboxTransportSubmissionAssistant.eventCounterToLatencyMap.TryGetValue(mapiEvent.EventCounter, out latencyRecord))
                    {
                        MailboxTransportSubmissionAssistant.eventCounterToLatencyMap.Remove(mapiEvent.EventCounter);
                        latencyTracker = latencyRecord.LatencyTracker;
                        LatencyTracker.EndTrackLatency(latencyRecord.LatencyComponent, latencyTracker, true);
                        flag = false;
                    }
                    else
                    {
                        latencyTracker = LatencyTracker.CreateInstance(LatencyComponent.MailboxTransportSubmissionService);
                        LatencyTracker.TrackPreProcessLatency(LatencyComponent.SubmissionAssistant, latencyTracker, mapiEvent.CreateTime);
                    }
                    LatencyTracker.BeginTrackLatency(LatencyComponent.MailboxTransportSubmissionService, latencyTracker);
                    string text = this.FormatMapiEventInfo(mapiEvent);
                    this.LogMapiEventIntoCrimsonChannelPeriodically(text);
                    this.SubmissionsInProgress[Thread.CurrentThread].LatencyTracker = latencyTracker;
                    if (MailboxTransportSubmissionAssistant.ShouldLogNotifyEvents && (flag || MailboxTransportSubmissionAssistant.ShouldLogTemporaryFailures))
                    {
                        LatencyFormatter       latencyFormatter = new LatencyFormatter(latencyTracker, Components.Configuration.LocalServer.TransportServer.Fqdn, mapiEvent.CreateTime, mapiEvent.CreateTime, true, false, false);
                        MsgTrackMapiSubmitInfo msgTrackInfo     = new MsgTrackMapiSubmitInfo(text, null, string.Empty, StoreDriverSubmission.LocalIPAddress, Components.Configuration.LocalServer.TransportServer.Name, string.Empty, string.Empty, MailboxTransportSubmissionAssistant.ItemEntryId(mapiEvent), latencyFormatter.FormatAndUpdatePerfCounters(), null, false, true);
                        MessageTrackingLog.TrackNotify(msgTrackInfo, false);
                    }
                    MSExchangeSubmission.PendingSubmissions.Increment();
                    new HashSet <string>();
                    DateTime createTime = mapiEvent.CreateTime;
                    MailboxTransportSubmissionService.StoreDriverTracer.ServiceTracer.TracePfdPass <int, Guid, long>(MailboxTransportSubmissionService.StoreDriverTracer.MessageProbeActivityId, (long)this.GetHashCode(), "PFD EMS {0} SubmitMail for mailbox {1} at entry {2}", 22427, mapiEvent.MailboxGuid, mapiEvent.EventCounter);
                    LatencyFormatter latencyFormatter2 = new LatencyFormatter(latencyTracker, Components.Configuration.LocalServer.TransportServer.Fqdn, createTime, createTime, false, true, false);
                    bool             isPublicFolder    = mapiEvent.ExtendedEventFlags.HasFlag(MapiExtendedEventFlags.PublicFolderMailbox);
                    LatencyTracker.BeginTrackLatency(LatencyComponent.MailboxTransportSubmissionStoreDriverSubmission, latencyTracker);
                    ISubmissionProvider  submissionProvider   = (ISubmissionProvider)Components.StoreDriverSubmission;
                    MailSubmissionResult mailSubmissionResult = submissionProvider.SubmitMessage(Components.Configuration.LocalServer.TransportServer.ExchangeLegacyDN, mapiEvent.MailboxGuid, this.databaseInfo.Guid, this.databaseInfo.DatabaseName, mapiEvent.EventCounter, mapiEvent.ItemEntryId, mapiEvent.ParentEntryId, Components.Configuration.LocalServer.TransportServer.Fqdn, new IPAddress(StoreDriverSubmission.LocalIPAddress.GetAddressBytes()), mapiEvent.CreateTime, isPublicFolder, (mapiEvent.TenantHint == null) ? null : TenantPartitionHint.FromPersistablePartitionHint(mapiEvent.TenantHint), latencyFormatter2.FormatAndUpdatePerfCounters(), MailboxTransportSubmissionService.QuarantineHandler, MailboxTransportSubmissionService.SubmissionPoisonHandler, latencyTracker);
                    MailSubmissionResult result = mailSubmissionResult;
                    LatencyTracker.EndTrackLatency(LatencyComponent.MailboxTransportSubmissionStoreDriverSubmission, latencyTracker);
                    LatencyTracker.EndTrackLatency(LatencyComponent.MailboxTransportSubmissionService, latencyTracker);
                    this.LogAndUpdateCounters(mapiEvent, latencyTracker, createTime, result);
                    this.HandleEventError(mapiEvent, result, latencyTracker, text);
                }
            }
            finally
            {
                MSExchangeSubmission.PendingSubmissions.Decrement();
                Interlocked.Decrement(ref this.concurrentEvents);
                this.SubmissionsInProgress.Remove(currentThread);
            }
        }
        MailboxInformation IMailboxReplicationService.GetMailboxInformation4(string requestJobXml, Guid primaryMailboxGuid, Guid physicalMailboxGuid, byte[] partitionHint, Guid targetMdbGuid, string targetMdbName, string remoteHostName, string remoteOrgName, string remoteDCName, string username, string password, string domain)
        {
            MailboxInformation info = null;

            this.ForwardKnownExceptions(delegate
            {
                TenantPartitionHint partitionHint2 = (partitionHint != null) ? TenantPartitionHint.FromPersistablePartitionHint(partitionHint) : null;
                bool flag = string.IsNullOrEmpty(targetMdbName) && targetMdbGuid == Guid.Empty;
                NetworkCredential networkCredential = (!string.IsNullOrEmpty(username)) ? new NetworkCredential(username, password, domain) : null;
                MailboxType mbxType;
                IMailbox mailbox;
                if (string.IsNullOrEmpty(remoteHostName))
                {
                    if (!string.IsNullOrEmpty(remoteDCName))
                    {
                        if (flag)
                        {
                            mbxType = MailboxType.SourceMailbox;
                            mailbox = new MapiSourceMailbox(LocalMailboxFlags.Move);
                        }
                        else
                        {
                            mbxType = MailboxType.DestMailboxIntraOrg;
                            mailbox = new MapiDestinationMailbox(LocalMailboxFlags.None);
                        }
                        mailbox.ConfigADConnection(remoteDCName, remoteDCName, networkCredential);
                    }
                    else
                    {
                        ProxyServerSettings proxyServerSettings;
                        if (targetMdbGuid != Guid.Empty)
                        {
                            proxyServerSettings = CommonUtils.MapDatabaseToProxyServer(targetMdbGuid);
                        }
                        else
                        {
                            proxyServerSettings = CommonUtils.MapMailboxToProxyServer(new Guid?(physicalMailboxGuid), new Guid?(primaryMailboxGuid), partitionHint);
                        }
                        if (flag)
                        {
                            if (proxyServerSettings.Scenario == ProxyScenarios.LocalMdbAndProxy)
                            {
                                mailbox = new StorageSourceMailbox(LocalMailboxFlags.Move);
                            }
                            else
                            {
                                mailbox = new RemoteSourceMailbox(proxyServerSettings.Fqdn, null, null, ProxyControlFlags.DoNotApplyProxyThrottling, null, false, LocalMailboxFlags.Move);
                            }
                            mbxType = MailboxType.SourceMailbox;
                        }
                        else
                        {
                            if (proxyServerSettings.Scenario == ProxyScenarios.LocalMdbAndProxy)
                            {
                                mailbox = new StorageDestinationMailbox(LocalMailboxFlags.Move);
                            }
                            else
                            {
                                mailbox = new RemoteDestinationMailbox(proxyServerSettings.Fqdn, null, null, ProxyControlFlags.DoNotApplyProxyThrottling, null, false, LocalMailboxFlags.Move);
                            }
                            mbxType = MailboxType.DestMailboxIntraOrg;
                        }
                    }
                }
                else
                {
                    ProxyControlFlags proxyControlFlags = ProxyControlFlags.DoNotApplyProxyThrottling;
                    RequestJobXML requestJobXML         = XMLSerializableBase.Deserialize <RequestJobXML>(requestJobXml, true);
                    if (requestJobXML != null)
                    {
                        using (TransactionalRequestJob transactionalRequestJob = new TransactionalRequestJob(requestJobXML))
                        {
                            transactionalRequestJob.IsFake = true;
                            proxyControlFlags |= transactionalRequestJob.GetProxyControlFlags();
                        }
                    }
                    if (flag)
                    {
                        mailbox = new RemoteSourceMailbox(remoteHostName, remoteOrgName, networkCredential, proxyControlFlags, null, true, LocalMailboxFlags.Move);
                        mbxType = MailboxType.SourceMailbox;
                    }
                    else
                    {
                        mailbox = new RemoteDestinationMailbox(remoteHostName, remoteOrgName, networkCredential, proxyControlFlags, null, true, LocalMailboxFlags.Move);
                        mbxType = MailboxType.DestMailboxCrossOrg;
                    }
                }
                using (mailbox)
                {
                    mailbox.Config(null, primaryMailboxGuid, physicalMailboxGuid, partitionHint2, targetMdbGuid, mbxType, null);
                    if (!string.IsNullOrEmpty(targetMdbName))
                    {
                        mailbox.ConfigMDBByName(targetMdbName);
                    }
                    mailbox.Connect(MailboxConnectFlags.None);
                    using (SettingsContextBase.ActivateContext(mailbox as ISettingsContextProvider))
                    {
                        info          = mailbox.GetMailboxInformation();
                        ADUser aduser = mailbox.GetADUser();
                        if (!this.clientVersion[2] && aduser.HasSeparatedArchive)
                        {
                            throw new UnsupportedClientVersionPermanentException(this.clientVersion.ComputerName, this.clientVersion.ToString(), "ArchiveSeparation");
                        }
                        info.UserDataXML       = ConfigurableObjectXML.Serialize <ADUser>(aduser);
                        info.ServerInformation = mailbox.GetMailboxServerInformation();
                        mailbox.Disconnect();
                    }
                }
            }, null);
            return(info);
        }