예제 #1
0
        public static DatabaseInformation FindServerForMdb(ADObjectId database, string dcName, NetworkCredential cred, FindServerFlags flags)
        {
            if (!ConfigBase <MRSConfigSchema> .GetConfig <bool>("CrossResourceForestEnabled"))
            {
                return(MapiUtils.FindServerForMdb(database.ObjectGuid, dcName, cred, flags));
            }
            Guid empty = Guid.Empty;
            DatabaseInformation result;

            try
            {
                if (database.GetPartitionId().IsLocalForestPartition())
                {
                    result = MapiUtils.FindServerForMdb(database.ObjectGuid, dcName, cred, flags);
                }
                else
                {
                    BackEndServer backEndServer = BackEndLocator.GetBackEndServer(database);
                    result = DatabaseInformation.FromBackEndServer(database, backEndServer);
                }
            }
            catch (BackEndLocatorException)
            {
                MrsTracer.Common.Debug("BE Locator was unable to locate MDB {0}.", new object[]
                {
                    database.ObjectGuid
                });
                if ((flags & FindServerFlags.AllowMissing) == FindServerFlags.None)
                {
                    throw;
                }
                result = DatabaseInformation.Missing(database.ObjectGuid, database.PartitionFQDN);
            }
            return(result);
        }
예제 #2
0
        private XElement GetQueueDiagnosticInfo(MRSDiagnosticArgument arguments)
        {
            DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(this.MdbGuid, null, null, FindServerFlags.AllowMissing);
            string argument = arguments.GetArgument <string>("queues");

            if (!string.IsNullOrEmpty(argument) && (databaseInformation.IsMissing || !CommonUtils.IsValueInWildcardedList(databaseInformation.DatabaseName, argument)))
            {
                return(null);
            }
            MRSQueueDiagnosticInfoXML mrsqueueDiagnosticInfoXML = new MRSQueueDiagnosticInfoXML
            {
                MdbGuid                  = this.MdbGuid,
                MdbName                  = databaseInformation.DatabaseName,
                LastJobPickup            = this.LastJobPickup,
                LastInteractiveJobPickup = this.LastInteractiveJobPickup,
                QueuedJobsCount          = this.QueuedJobsCount,
                InProgressJobsCount      = this.InProgressJobsCount,
                LastScanFailure          = this.LastScanFailure,
                MdbDiscoveryTimestamp    = this.MdbDiscoveryTimestamp,
                LastScanTimestamp        = this.LastScanTimestamp,
                LastScanDurationMs       = (int)this.LastScanDuration.TotalMilliseconds,
                NextRecommendedScan      = this.NextRecommendedScan,
                LastActiveJobFinishTime  = this.LastActiveJobFinishTime,
                LastActiveJobFinished    = this.LastActiveJobFinished
            };

            if (arguments.HasArgument("pickupresults"))
            {
                mrsqueueDiagnosticInfoXML.LastScanResults = this.LastScanResults;
            }
            return(mrsqueueDiagnosticInfoXML.ToDiagnosticInfo(null));
        }
예제 #3
0
        public static List <Guid> GetDatabasesOnThisServer()
        {
            if (MapiUtils.localMDBs != null && DateTime.UtcNow - MapiUtils.LocalMDBRefreshInterval < MapiUtils.lastLocalMDBRefresh)
            {
                return(MapiUtils.localMDBs);
            }
            List <Guid> list = new List <Guid>();

            MdbStatus[] mdbStatuses = null;
            CommonUtils.ProcessKnownExceptions(delegate
            {
                using (ExRpcAdmin exRpcAdmin = ExRpcAdmin.Create("Client=MSExchangeMigration", null, null, null, null))
                {
                    mdbStatuses = exRpcAdmin.ListMdbStatus(true);
                }
            }, delegate(Exception failure)
            {
                LocalizedString localizedString = CommonUtils.FullExceptionMessage(failure);
                CommonUtils.LogEvent(MRSEventLogConstants.Tuple_UnableToDetermineHostedMdbsOnServer, new object[]
                {
                    CommonUtils.LocalComputerName,
                    localizedString.ToString()
                });
                return(false);
            });
            if (mdbStatuses == null)
            {
                MrsTracer.Common.Debug("MapiUtils.GetDatabasesOnServer() returned null.", new object[0]);
                return(list);
            }
            foreach (MdbStatus mdbStatus in mdbStatuses)
            {
                if (mdbStatus.Status.HasFlag(MdbStatusFlags.Online))
                {
                    list.Add(mdbStatus.MdbGuid);
                }
            }
            if (list.Count == 0)
            {
                MrsTracer.Common.Debug("MapiUtils.GetDatabasesOnServer() found {0} databases, but none of them are online.", new object[]
                {
                    mdbStatuses.Length
                });
            }
            foreach (Guid mdbGuid in list)
            {
                DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.AllowMissing);
                if (!databaseInformation.IsMissing && !databaseInformation.IsOnThisServer)
                {
                    databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.ForceRediscovery | FindServerFlags.AllowMissing);
                }
            }
            MapiUtils.localMDBs           = list;
            MapiUtils.lastLocalMDBRefresh = DateTime.UtcNow;
            return(list);
        }
예제 #4
0
        private static bool ShouldRemovePerfCounter(Guid mdbGuid, MDBPerfCounterHelper perfCounter)
        {
            bool result = false;

            CommonUtils.CatchKnownExceptions(delegate
            {
                DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.AllowMissing);
                result = (databaseInformation.IsMissing || !databaseInformation.IsOnThisServer);
            }, null);
            return(result);
        }
        internal static MailboxReplicationServiceClient Create(IConfigurationSession session, MRSJobType jobType, Guid mdbGuid, List <string> unreachableMrsServers)
        {
            MRSCapabilities     requiredCapability = RequestJobXML.MapJobTypeToCapability(jobType);
            string              text = null;
            DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.None);

            if (!string.IsNullOrEmpty(databaseInformation.ServerFqdn))
            {
                text = databaseInformation.ServerFqdn.ToLower(CultureInfo.InvariantCulture);
            }
            List <string> mrsServers = MailboxReplicationServiceClient.GetMrsServers(session, mdbGuid);
            List <string> list       = new List <string>(mrsServers.Count);

            foreach (string text2 in mrsServers)
            {
                string text3 = text2.ToLower(CultureInfo.InvariantCulture);
                if (string.Compare(text3, text, CultureInfo.InvariantCulture, CompareOptions.Ordinal) != 0 && !unreachableMrsServers.Contains(text3))
                {
                    list.Add(text2);
                }
            }
            List <string> list2 = CommonUtils.RandomizeSequence <string>(list);

            if (text != null)
            {
                list2.Insert(0, text);
            }
            foreach (string text4 in list2)
            {
                try
                {
                    return(MailboxReplicationServiceClient.Create(text4, requiredCapability));
                }
                catch (MailboxReplicationPermanentException ex)
                {
                    MrsTracer.Common.Warning("Attempt to connect to CAS Server {0} failed with error: {1}", new object[]
                    {
                        text4,
                        CommonUtils.FullExceptionMessage(ex)
                    });
                }
                catch (MailboxReplicationTransientException ex2)
                {
                    MrsTracer.Common.Warning("Attempt to connect to CAS Server {0} failed with error: {1}", new object[]
                    {
                        text4,
                        CommonUtils.FullExceptionMessage(ex2)
                    });
                }
                unreachableMrsServers.Add(text4.ToLower(CultureInfo.InvariantCulture));
            }
            throw new NoMRSAvailableTransientException();
        }
 public static void CleanADOrphanAndInconsistency()
 {
     PartitionId[] allAccountPartitionIds = ADAccountPartitionLocator.GetAllAccountPartitionIds();
     for (int i = 0; i < allAccountPartitionIds.Length; i++)
     {
         PartitionId partitionId = allAccountPartitionIds[i];
         CommonUtils.CheckForServiceStopping();
         ADSessionSettings adsessionSettings = ADSessionSettings.FromAllTenantsPartitionId(partitionId);
         adsessionSettings.IncludeSoftDeletedObjects = true;
         adsessionSettings.IncludeInactiveMailbox    = true;
         IRecipientSession     recipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, false, ConsistencyMode.PartiallyConsistent, null, adsessionSettings, 45, "CleanADOrphanAndInconsistency", "f:\\15.00.1497\\sources\\dev\\mrs\\src\\Service\\ADInconsistencyCheck.cs");
         IConfigurationSession configSession    = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(null, false, ConsistencyMode.PartiallyConsistent, null, adsessionSettings, 52, "CleanADOrphanAndInconsistency", "f:\\15.00.1497\\sources\\dev\\mrs\\src\\Service\\ADInconsistencyCheck.cs");
         using (List <Guid> .Enumerator enumerator = MapiUtils.GetDatabasesOnThisServer().GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 Guid dbGuid = enumerator.Current;
                 CommonUtils.CheckForServiceStopping();
                 DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(dbGuid, null, null, FindServerFlags.AllowMissing);
                 if (databaseInformation.IsMissing)
                 {
                     MrsTracer.Service.Debug("CleanADOrphanAndInconsistency Database {0} in Forest {1} is missing, skip it", new object[]
                     {
                         dbGuid,
                         databaseInformation.ForestFqdn
                     });
                 }
                 else
                 {
                     CommonUtils.CatchKnownExceptions(delegate
                     {
                         ADInconsistencyCheck.CleanADOrphanAndInconsistencyForRequests(recipientSession, configSession, dbGuid);
                     }, delegate(Exception f)
                     {
                         MrsTracer.Service.Error("CleanADOrphanAndInconsistency() failed for DB {0}. Error: {1}", new object[]
                         {
                             dbGuid,
                             CommonUtils.FullExceptionMessage(f, true)
                         });
                         MRSService.LogEvent(MRSEventLogConstants.Tuple_ScanADInconsistencyRequestFailEvent, new object[]
                         {
                             dbGuid,
                             string.Empty,
                             string.Empty,
                             CommonUtils.FullExceptionMessage(f, true)
                         });
                     });
                 }
             }
         }
     }
 }
        private bool InitializeIdentity()
        {
            DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(this.DatabaseGuid, null, null, FindServerFlags.AllowMissing);

            if (databaseInformation.IsMissing)
            {
                this.databaseName = string.Format("LegacyMdblCiUnresolved({0}{1})", this.DatabaseGuid.ToString(), databaseInformation.ForestFqdn);
            }
            else
            {
                this.databaseName = string.Format("LegacyMdblCi({0})", databaseInformation.DatabaseName);
            }
            return(!databaseInformation.IsMissing);
        }
예제 #8
0
        protected override ICollection <ServiceIssue> RunFullIssueScan()
        {
            ICollection <ServiceIssue> collection = new List <ServiceIssue>();

            foreach (Guid mdbGuid in MapiUtils.GetDatabasesOnThisServer())
            {
                using (new DatabaseSettingsContext(mdbGuid, null).Activate())
                {
                    try
                    {
                        DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.None);
                        string databaseName = databaseInformation.DatabaseName;
                        if (!databaseInformation.IsOnThisServer)
                        {
                            return(null);
                        }
                        using (MapiStore systemMailbox = MapiUtils.GetSystemMailbox(mdbGuid, false))
                        {
                            using (MapiFolder requestJobsFolder = RequestJobXML.GetRequestJobsFolder(systemMailbox))
                            {
                                using (MapiTable contentsTable = requestJobsFolder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                                {
                                    if (contentsTable.GetRowCount() > 0)
                                    {
                                        RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(systemMailbox);
                                        contentsTable.SetColumns(requestJobNamedPropertySet.PropTags);
                                        Restriction    restriction = Restriction.GT(requestJobNamedPropertySet.PropTags[23], ConfigBase <MRSConfigSchema> .GetConfig <int>("PoisonLimit"));
                                        List <MoveJob> allMoveJobs = SystemMailboxJobs.GetAllMoveJobs(restriction, null, contentsTable, mdbGuid, null);
                                        if (allMoveJobs != null)
                                        {
                                            foreach (MoveJob job in allMoveJobs)
                                            {
                                                collection.Add(new MRSPoisonedJobIssue(job));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (LocalizedException lastScanError)
                    {
                        base.LastScanError = lastScanError;
                    }
                }
            }
            return(collection);
        }
예제 #9
0
        public static MDBPerfCounterHelper GetMDBHelper(Guid mdbGuid, bool createIfNotPresent)
        {
            MDBPerfCounterHelper mdbperfCounterHelper = null;
            MDBPerfCounterHelper result;

            lock (MDBPerfCounterHelperCollection.locker)
            {
                if (!MDBPerfCounterHelperCollection.data.TryGetValue(mdbGuid, out mdbperfCounterHelper) && createIfNotPresent)
                {
                    DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.AllowMissing);
                    mdbperfCounterHelper = new MDBPerfCounterHelper(databaseInformation.DatabaseName ?? MrsStrings.MissingDatabaseName2(mdbGuid, databaseInformation.ForestFqdn));
                    MDBPerfCounterHelperCollection.data.TryInsertSliding(mdbGuid, mdbperfCounterHelper, MDBPerfCounterHelperCollection.RefreshInterval);
                }
                result = mdbperfCounterHelper;
            }
            return(result);
        }
예제 #10
0
        public void ReserveResource(Guid mailboxGuid, TenantPartitionHint partitionHint, ADObjectId resourceId, ReservationFlags flags)
        {
            string serverFQDN = null;

            if (!(resourceId.ObjectGuid == MRSResource.Id.ObjectGuid))
            {
                DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(resourceId, null, null, FindServerFlags.None);
                if (databaseInformation.ServerVersion < Server.E15MinVersion)
                {
                    return;
                }
                if (!databaseInformation.IsOnThisServer)
                {
                    serverFQDN = databaseInformation.ServerFqdn;
                }
            }
            this.AddReservation(ReservationWrapper.CreateReservation(serverFQDN, null, mailboxGuid, partitionHint, resourceId.ObjectGuid, flags));
        }
        internal static List <string> GetMrsServers(IConfigurationSession session, Guid mdbGuid)
        {
            DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, FindServerFlags.None);

            if (databaseInformation.ServerSite == null)
            {
                throw new UnableToDetermineMDBSitePermanentException(mdbGuid);
            }
            MrsTracer.Common.Debug("MDB '{0}' ({1}) found to belong to Site: '{2}'", new object[]
            {
                databaseInformation.DatabaseName,
                mdbGuid,
                databaseInformation.ServerSite
            });
            ServerVersion serverVersion = MailboxReplicationServiceClient.minRequiredVersion;
            QueryFilter   filter        = new AndFilter(new QueryFilter[]
            {
                new BitMaskAndFilter(ServerSchema.CurrentServerRole, 4UL),
                new ComparisonFilter(ComparisonOperator.NotEqual, ActiveDirectoryServerSchema.IsOutOfService, true),
                new ComparisonFilter(ComparisonOperator.GreaterThanOrEqual, ServerSchema.VersionNumber, serverVersion.ToInt()),
                new ComparisonFilter(ComparisonOperator.Equal, ServerSchema.ServerSite, databaseInformation.ServerSite.DistinguishedName)
            });

            Server[] array = session.Find <Server>(null, QueryScope.SubTree, filter, null, 0);
            if (array == null || array.Length == 0)
            {
                MrsTracer.Common.Error("No Client Access servers running an appropriate version of Exchange 2010 (or later) were found in site '{0}'.", new object[]
                {
                    databaseInformation.ServerSite.ToString()
                });
                throw new ErrorNoCASServersInSitePermanentException(databaseInformation.ServerSite.ToString(), serverVersion.ToString());
            }
            List <string> list = new List <string>(array.Length);

            foreach (Server server in array)
            {
                string fqdn = server.Fqdn;
                if (!string.IsNullOrEmpty(fqdn))
                {
                    list.Add(fqdn);
                }
            }
            return(list);
        }
예제 #12
0
        public void PickupJobs(out string failure)
        {
            string dbName      = null;
            string scanFailure = null;

            failure = null;
            using (new DatabaseSettingsContext(this.MdbGuid, null).Activate())
            {
                CommonUtils.CatchKnownExceptions(delegate
                {
                    DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(this.MdbGuid, null, null, FindServerFlags.None);
                    dbName = databaseInformation.DatabaseName;
                    if (!databaseInformation.IsOnThisServer)
                    {
                        scanFailure = string.Format("MDB is mounted on remote server {0}", databaseInformation.ServerFqdn);
                        MRSQueue.RemoveQueue(this.MdbGuid);
                        return;
                    }
                    MrsTracer.Service.Debug("Picking up jobs from '{0}' ({1})", new object[]
                    {
                        dbName,
                        this.MdbGuid
                    });
                    using (MapiStore systemMailbox = MapiUtils.GetSystemMailbox(this.MdbGuid, false))
                    {
                        using (MapiFolder requestJobsFolder = RequestJobXML.GetRequestJobsFolder(systemMailbox))
                        {
                            using (MapiTable contentsTable = requestJobsFolder.GetContentsTable(ContentsTableFlags.DeferredErrors))
                            {
                                if (contentsTable.GetRowCount() > 0)
                                {
                                    RequestJobNamedPropertySet requestJobNamedPropertySet = RequestJobNamedPropertySet.Get(systemMailbox);
                                    contentsTable.SetColumns(requestJobNamedPropertySet.PropTags);
                                    this.ProcessJobs(systemMailbox, contentsTable, requestJobNamedPropertySet);
                                }
                            }
                        }
                    }
                    MrsTracer.Service.Debug("Pick up jobs from Mdb: '{0}' - complete.", new object[]
                    {
                        dbName
                    });
                }, delegate(Exception f)
                {
                    if (dbName == null)
                    {
                        dbName = MrsStrings.MissingDatabaseName(this.MdbGuid).ToString();
                    }
                    MrsTracer.Service.Debug("PickupJobs() failed for mdb '{0}'. Error: {1}", new object[]
                    {
                        dbName,
                        CommonUtils.FullExceptionMessage(f)
                    });
                    scanFailure = CommonUtils.FullExceptionMessage(f, true);
                    MRSService.LogEvent(MRSEventLogConstants.Tuple_UnableToProcessJobsInDatabase, new object[]
                    {
                        dbName,
                        CommonUtils.FullExceptionMessage(f)
                    });
                });
            }
            failure = scanFailure;
        }
예제 #13
0
        public static DatabaseInformation FindServerForMdb(Guid mdbGuid, string dcName, NetworkCredential cred, FindServerFlags flags)
        {
            Guid systemMailboxGuid = Guid.Empty;

            if (flags.HasFlag(FindServerFlags.FindSystemMailbox))
            {
                systemMailboxGuid = MapiUtils.GetSystemMailboxGuid(mdbGuid, dcName, cred, flags);
            }
            if (cred == null)
            {
                try
                {
                    GetServerForDatabaseFlags getServerForDatabaseFlags = GetServerForDatabaseFlags.IgnoreAdSiteBoundary;
                    if (flags.HasFlag(FindServerFlags.ForceRediscovery))
                    {
                        MrsTracer.Common.Debug("Looking up MDB {0} with rediscovery", new object[]
                        {
                            mdbGuid
                        });
                        getServerForDatabaseFlags |= GetServerForDatabaseFlags.ReadThrough;
                    }
                    DatabaseLocationInfo serverForDatabase = ActiveManager.GetCachingActiveManagerInstance().GetServerForDatabase(mdbGuid, getServerForDatabaseFlags);
                    if (serverForDatabase != null)
                    {
                        return(DatabaseInformation.FromDatabaseLocationInfo(mdbGuid, serverForDatabase, systemMailboxGuid));
                    }
                }
                catch (ObjectNotFoundException)
                {
                }
                MrsTracer.Common.Debug("ActiveManager was unable to locate MDB {0}, will search AD instead.", new object[]
                {
                    mdbGuid
                });
            }
            ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(dcName, true, ConsistencyMode.PartiallyConsistent, cred, ADSessionSettings.FromRootOrgScopeSet(), 686, "FindServerForMdb", "f:\\15.00.1497\\sources\\dev\\mrs\\src\\Common\\MapiUtils.cs");
            Database database = topologyConfigurationSession.FindDatabaseByGuid <Database>(mdbGuid);

            if (database == null)
            {
                MrsTracer.Common.Error("Unable to locate MDB by guid {0}", new object[]
                {
                    mdbGuid
                });
                if (!flags.HasFlag(FindServerFlags.AllowMissing))
                {
                    throw new DatabaseNotFoundByGuidPermanentException(mdbGuid);
                }
                return(DatabaseInformation.Missing(mdbGuid, PartitionId.LocalForest.ForestFQDN));
            }
            else
            {
                PropertyDefinition[] properties = new PropertyDefinition[]
                {
                    ServerSchema.ExchangeLegacyDN,
                    ServerSchema.Fqdn,
                    ServerSchema.ServerSite,
                    ServerSchema.VersionNumber,
                    ActiveDirectoryServerSchema.MailboxRelease
                };
                MiniServer miniServer = topologyConfigurationSession.ReadMiniServer(database.Server, properties);
                if (miniServer != null)
                {
                    return(DatabaseInformation.FromAD(database, miniServer, systemMailboxGuid));
                }
                MrsTracer.Common.Error("Unable to locate DB server {0}", new object[]
                {
                    database.Server.DistinguishedName
                });
                if ((flags & FindServerFlags.AllowMissing) == FindServerFlags.None)
                {
                    throw new UnexpectedErrorPermanentException(-2147221233);
                }
                return(DatabaseInformation.Missing(mdbGuid, PartitionId.LocalForest.ForestFQDN));
            }
        }
예제 #14
0
        public static MapiStore GetUserMailbox(Guid mailboxGuid, Guid mdbGuid, UserMailboxFlags umFlags)
        {
            OpenStoreFlag openStoreFlag = OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.NoLocalization | OpenStoreFlag.MailboxGuid;
            ConnectFlag   connectFlags  = ConnectFlag.UseAdminPrivilege | ConnectFlag.UseRpcContextPool | ConnectFlag.AllowLegacyStore;

            if (umFlags.HasFlag(UserMailboxFlags.RecoveryMDB))
            {
                openStoreFlag |= OpenStoreFlag.RestoreDatabase;
            }
            if (umFlags.HasFlag(UserMailboxFlags.Disconnected) || umFlags.HasFlag(UserMailboxFlags.SoftDeleted) || umFlags.HasFlag(UserMailboxFlags.MoveDestination))
            {
                openStoreFlag |= (OpenStoreFlag.OverrideHomeMdb | OpenStoreFlag.DisconnectedMailbox);
            }
            bool      flag = false;
            TimeSpan  localMailboxConnectionTimeout = TestIntegration.Instance.LocalMailboxConnectionTimeout;
            TimeSpan  localMailboxCallTimeout       = TestIntegration.Instance.LocalMailboxCallTimeout;
            MapiStore result;

            for (;;)
            {
                FindServerFlags findServerFlags = FindServerFlags.None;
                if (flag)
                {
                    findServerFlags |= FindServerFlags.ForceRediscovery;
                }
                DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, findServerFlags);
                try
                {
                    MrsTracer.Common.Debug("Opening MapiStore: serverFqdn=\"{0}\", mailboxGuid=\"{1}\", mdbGuid=\"{2}\", flags=[{3}].", new object[]
                    {
                        databaseInformation.ServerFqdn,
                        mailboxGuid,
                        mdbGuid,
                        openStoreFlag
                    });
                    MapiStore mapiStore = MapiStore.OpenMailbox(databaseInformation.ServerFqdn, Server.GetSystemAttendantLegacyDN(databaseInformation.ServerDN), mailboxGuid, mdbGuid, null, null, null, connectFlags, openStoreFlag, null, null, "Client=MSExchangeMigration", localMailboxConnectionTimeout, localMailboxCallTimeout, null);
                    MapiUtils.StartMapiDeadSessionChecking(mapiStore, mailboxGuid.ToString());
                    result = mapiStore;
                }
                catch (MapiExceptionWrongServer)
                {
                    if (!flag)
                    {
                        MrsTracer.Common.Debug("OpenMailbox returned WrongServer, forcing AM rediscovery", new object[0]);
                        flag = true;
                        continue;
                    }
                    throw;
                }
                catch (MapiExceptionLogonFailed)
                {
                    if (!flag)
                    {
                        MrsTracer.Common.Debug("OpenMailbox returned LogonFailed, forcing AM rediscovery", new object[0]);
                        flag = true;
                        continue;
                    }
                    throw;
                }
                break;
            }
            return(result);
        }
예제 #15
0
        public override void Run()
        {
            Guid currentQueueGuid        = this.CurrentRequestQueue.ObjectGuid;
            Guid newQueueGuid            = this.NewRequestQueue.ObjectGuid;
            RequestJobObjectId currentId = new RequestJobObjectId(base.RequestGuid, currentQueueGuid, this.MessageId);
            RequestJobObjectId newId     = new RequestJobObjectId(base.RequestGuid, newQueueGuid, null);

            CommonUtils.CatchKnownExceptions(delegate
            {
                DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(this.NewRequestQueue, null, null, FindServerFlags.None);
                if (databaseInformation.ServerVersion < Server.E15MinVersion)
                {
                    throw new UnsupportedRehomeTargetVersionPermanentException(newQueueGuid.ToString(), new ServerVersion(databaseInformation.ServerVersion).ToString());
                }
                this.NewSystemMailbox = MapiUtils.GetSystemMailbox(newQueueGuid);
                using (RequestJobProvider currentQueueProvider = new RequestJobProvider(currentQueueGuid, this.CurrentSystemMailbox))
                {
                    using (RequestJobProvider newQueueProvider = new RequestJobProvider(newQueueGuid, this.NewSystemMailbox))
                    {
                        using (TransactionalRequestJob requestJob = (TransactionalRequestJob)currentQueueProvider.Read <TransactionalRequestJob>(currentId))
                        {
                            if (requestJob != null)
                            {
                                RequestJobProvider origProvider       = requestJob.Provider;
                                MoveObjectInfo <RequestJobXML> origMO = requestJob.MoveObject;
                                ReportData currentReport = new ReportData(requestJob.IdentifyingGuid, requestJob.ReportVersion);
                                currentReport.Load(currentQueueProvider.SystemMailbox);
                                ReportData newReport = new ReportData(currentReport.IdentifyingGuid, requestJob.ReportVersion);
                                newReport.Append(currentReport.Entries);
                                try
                                {
                                    requestJob.Provider           = null;
                                    requestJob.MoveObject         = null;
                                    requestJob.RequestQueue       = this.NewRequestQueue;
                                    requestJob.Identity           = newId;
                                    requestJob.OriginatingMDBGuid = Guid.Empty;
                                    requestJob.RehomeRequest      = false;
                                    if (requestJob.IndexEntries != null)
                                    {
                                        foreach (IRequestIndexEntry requestIndexEntry in requestJob.IndexEntries)
                                        {
                                            requestIndexEntry.StorageMDB = this.NewRequestQueue;
                                        }
                                    }
                                    newQueueProvider.Save(requestJob);
                                    CommonUtils.CatchKnownExceptions(delegate
                                    {
                                        newReport.Append(MrsStrings.ReportJobRehomed(currentQueueGuid.ToString(), newQueueGuid.ToString()));
                                        newReport.Flush(newQueueProvider.SystemMailbox);
                                    }, null);
                                    CommonUtils.CatchKnownExceptions(delegate
                                    {
                                        requestJob.Provider           = origProvider;
                                        requestJob.MoveObject         = origMO;
                                        requestJob.RequestQueue       = this.CurrentRequestQueue;
                                        requestJob.Identity           = currentId;
                                        requestJob.OriginatingMDBGuid = currentQueueGuid;
                                        requestJob.RehomeRequest      = true;
                                        MapiUtils.RetryOnObjectChanged(delegate
                                        {
                                            currentQueueProvider.Delete(requestJob);
                                        });
                                        currentReport.Delete(currentQueueProvider.SystemMailbox);
                                    }, null);
                                }
                                catch
                                {
                                    requestJob.Provider           = origProvider;
                                    requestJob.MoveObject         = origMO;
                                    requestJob.RequestQueue       = this.CurrentRequestQueue;
                                    requestJob.Identity           = currentId;
                                    requestJob.OriginatingMDBGuid = currentQueueGuid;
                                    requestJob.RehomeRequest      = true;
                                    throw;
                                }
                            }
                        }
                    }
                }
            }, delegate(Exception failure)
            {
                MrsTracer.Service.Warning("Failed to rehome request.", new object[0]);
                this.RehomeFailure = failure;
            });
            base.Run();
        }