Beispiel #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);
        }
Beispiel #2
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));
            }
        }