// Token: 0x0600032C RID: 812 RVA: 0x00011758 File Offset: 0x0000F958
        private static TenantPartitionCacheItem FindTenantInfoByAcceptedDomain(string acceptedDomain)
        {
            PartitionId partitionId;

            if (!ADSessionSettings.IsGlsDisabled)
            {
                TenantPartitionCacheItem tenantPartitionCacheItem;
                if (ADAccountPartitionLocator.TryLookUpAccountForest(Guid.Empty, acceptedDomain, null, out tenantPartitionCacheItem))
                {
                    return(tenantPartitionCacheItem);
                }
            }
            else if (ADAccountPartitionLocator.IsSingleForestTopology(out partitionId))
            {
                ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "GLS is disabled, performing the only partition lookup for {0}", acceptedDomain);
                return(ADAccountPartitionLocator.SearchForTenantInfoByOrganizationName(acceptedDomain, partitionId));
            }
            if (GlsMServDirectorySession.ShouldScanAllForests)
            {
                ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
                PartitionId[] array = ADAccountPartitionLocator.allAccountPartitionIds;
                foreach (PartitionId partitionId2 in array)
                {
                    TenantPartitionCacheItem tenantPartitionCacheItem = ADAccountPartitionLocator.SearchForTenantInfoByOrganizationName(acceptedDomain, partitionId2);
                    if (tenantPartitionCacheItem != null)
                    {
                        ADAccountPartitionLocator.InsertCacheMaps(tenantPartitionCacheItem, acceptedDomain, null);
                        return(tenantPartitionCacheItem);
                    }
                }
            }
            return(null);
        }
        // Token: 0x0600031E RID: 798 RVA: 0x00010DF0 File Offset: 0x0000EFF0
        public static Guid GetExternalDirectoryOrganizationIdByTenantName(string tenantName, PartitionId partitionId)
        {
            if (string.IsNullOrEmpty(tenantName))
            {
                throw new ArgumentNullException("tenantName");
            }
            if (partitionId == null)
            {
                throw new ArgumentNullException("partitionId");
            }
            ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
            TenantPartitionCacheItem tenantPartitionCacheItem;

            if (!ADAccountPartitionLocator.tenantNamePartitionCache.TryGetValue(tenantName, out tenantPartitionCacheItem))
            {
                tenantPartitionCacheItem = ADAccountPartitionLocator.SearchForTenantInfoByOrganizationName(tenantName, partitionId);
                if (tenantPartitionCacheItem != null)
                {
                    ADAccountPartitionLocator.InsertCacheMaps(tenantPartitionCacheItem, null, null);
                }
            }
            if (tenantPartitionCacheItem != null)
            {
                ADAccountPartitionLocator.EnsureRegisteredAccountPartition(tenantPartitionCacheItem);
                return(tenantPartitionCacheItem.ExternalOrgId);
            }
            throw new CannotResolveTenantNameException(DirectoryStrings.CannotResolveTenantNameByAcceptedDomain(tenantName));
        }
 // Token: 0x06000333 RID: 819 RVA: 0x00011C51 File Offset: 0x0000FE51
 private static void CheckAccountPartitionIsRegistered(string accountForestFqdn, out Guid accountPartitionGuid)
 {
     ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
     if (!ADAccountPartitionLocator.partitionsFQDNToGuid.TryGetValue(accountForestFqdn, out accountPartitionGuid))
     {
         throw new CannotResolvePartitionException(DirectoryStrings.CannotResolvePartitionFqdnError(accountForestFqdn));
     }
 }
 // Token: 0x06000322 RID: 802 RVA: 0x00010F32 File Offset: 0x0000F132
 internal static PartitionId[] GetAllAccountPartitionIds(bool includeSecondaryPartitions)
 {
     ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
     if (!includeSecondaryPartitions)
     {
         return(ADAccountPartitionLocator.allExplicitlyConfiguredPrimaryAccountPartitionIds);
     }
     return(ADAccountPartitionLocator.allExplicitlyConfiguredAccountPartitionIds);
 }
        // Token: 0x06000324 RID: 804 RVA: 0x00010FCC File Offset: 0x0000F1CC
        internal static string GetAccountPartitionFqdnByPartitionGuid(Guid partitionGuid)
        {
            ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
            string result;

            if (!ADAccountPartitionLocator.partitionsGuidToFQDN.TryGetValue(partitionGuid, out result))
            {
                throw new CannotResolvePartitionException(DirectoryStrings.CannotResolvePartitionGuidError(partitionGuid.ToString()));
            }
            return(result);
        }
 // Token: 0x06000316 RID: 790 RVA: 0x00010B78 File Offset: 0x0000ED78
 public static bool IsKnownPartition(PartitionId partitionId)
 {
     if (TopologyProvider.IsAdamTopology())
     {
         return(true);
     }
     if (!Globals.IsMicrosoftHostedOnly && partitionId.PartitionObjectId == null)
     {
         return(false);
     }
     ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
     return(partitionId.IsLocalForestPartition() || ADAccountPartitionLocator.partitionsFQDNToGuid.ContainsKey(partitionId.ForestFQDN));
 }
        // Token: 0x06000325 RID: 805 RVA: 0x00011008 File Offset: 0x0000F208
        internal static bool IsSingleForestTopology(out PartitionId singleForestPartition)
        {
            ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
            singleForestPartition = null;
            PartitionId[] array  = ADAccountPartitionLocator.allExplicitlyConfiguredAccountPartitionIds;
            bool          result = false;

            if (array.Length == 1)
            {
                singleForestPartition = array[0];
                result = true;
            }
            return(result);
        }
        // Token: 0x06000329 RID: 809 RVA: 0x00011358 File Offset: 0x0000F558
        private static TenantPartitionCacheItem FindTenantInfoByExternalOrgId(Guid externalOrgId)
        {
            TenantPartitionCacheItem tenantPartitionCacheItem = null;

            if (externalOrgId == TemplateTenantConfiguration.TemplateTenantExternalDirectoryOrganizationIdGuid)
            {
                ExchangeConfigurationUnit localTemplateTenant = TemplateTenantConfiguration.GetLocalTemplateTenant();
                if (localTemplateTenant != null)
                {
                    ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "FindTenantInfoByExternalOrgId() asked for Consumer Template tenant, returning {0}", localTemplateTenant.Id.Parent.DistinguishedName);
                    string name = localTemplateTenant.Id.Parent.Name;
                    tenantPartitionCacheItem = new TenantPartitionCacheItem(Guid.Empty, localTemplateTenant.OrganizationId.PartitionId.ForestFQDN, PartitionId.LocalForest.ForestFQDN, externalOrgId, name, false);
                }
                return(tenantPartitionCacheItem);
            }
            PartitionId partitionId;

            if (!ADSessionSettings.IsGlsDisabled)
            {
                if (ADAccountPartitionLocator.TryLookUpAccountForest(externalOrgId, null, null, out tenantPartitionCacheItem))
                {
                    return(tenantPartitionCacheItem);
                }
            }
            else if (ADAccountPartitionLocator.IsSingleForestTopology(out partitionId))
            {
                ExTraceGlobals.GLSTracer.TraceDebug <Guid>(0L, "GLS is disabled, performing the only partition lookup for {0}", externalOrgId);
                return(ADAccountPartitionLocator.SearchForTenantInfoByExternalOrgId(externalOrgId, partitionId));
            }
            if (GlsMServDirectorySession.ShouldScanAllForests)
            {
                ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
                PartitionId[] array = ADAccountPartitionLocator.allAccountPartitionIds;
                foreach (PartitionId partitionId2 in array)
                {
                    tenantPartitionCacheItem = ADAccountPartitionLocator.SearchForTenantInfoByExternalOrgId(externalOrgId, partitionId2);
                    if (tenantPartitionCacheItem != null)
                    {
                        ADAccountPartitionLocator.InsertCacheMaps(tenantPartitionCacheItem, null, null);
                        return(tenantPartitionCacheItem);
                    }
                }
            }
            return(null);
        }
        // Token: 0x0600032E RID: 814 RVA: 0x00011838 File Offset: 0x0000FA38
        private static Guid?GetPartitionGuid(PartitionId partitionId)
        {
            if (partitionId == null)
            {
                throw new ArgumentNullException("partitionId");
            }
            Guid guid = (partitionId.PartitionObjectId == null) ? Guid.Empty : partitionId.PartitionObjectId.Value;

            if (guid == Guid.Empty)
            {
                ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
                if (!ADAccountPartitionLocator.partitionsFQDNToGuid.TryGetValue(partitionId.ForestFQDN, out guid))
                {
                    return(null);
                }
            }
            return(new Guid?(guid));
        }
        // Token: 0x06000323 RID: 803 RVA: 0x00010F48 File Offset: 0x0000F148
        internal static Guid GetAccountPartitionGuidByPartitionId(PartitionId partitionId)
        {
            if (partitionId == null)
            {
                throw new ArgumentNullException("partitionId");
            }
            if (partitionId.PartitionObjectId != null)
            {
                return(partitionId.PartitionObjectId.Value);
            }
            if (string.IsNullOrEmpty(partitionId.ForestFQDN))
            {
                throw new ArgumentNullException("ForestFQDN");
            }
            ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
            Guid result;

            if (!ADAccountPartitionLocator.partitionsFQDNToGuid.TryGetValue(partitionId.ForestFQDN, out result))
            {
                throw new CannotResolvePartitionException(DirectoryStrings.CannotResolvePartitionFqdnError(partitionId.ForestFQDN));
            }
            return(result);
        }
        // Token: 0x0600032A RID: 810 RVA: 0x00011460 File Offset: 0x0000F660
        private static bool TryLookUpAccountForest(Guid externalDirectoryOrganizationId, string acceptedDomain, string msaUserNetID, out TenantPartitionCacheItem cacheItem)
        {
            cacheItem = null;
            Exception ex = null;

            if (acceptedDomain == string.Empty)
            {
                throw new ArgumentException(acceptedDomain);
            }
            if (msaUserNetID == string.Empty)
            {
                throw new ArgumentException(msaUserNetID);
            }
            try
            {
                IGlobalDirectorySession globalSession = DirectorySessionFactory.GetGlobalSession(null);
                bool   dataFromOfflineService         = false;
                string resourceForestFqdn;
                string text;
                string tenantName;
                bool   flag;
                if (acceptedDomain != null)
                {
                    if (ADAccountPartitionLocator.acceptedDomainPartitionCache.TryGetValue(acceptedDomain, out cacheItem))
                    {
                        ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.AcceptedDomain, true);
                        return(true);
                    }
                    ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.AcceptedDomain, false);
                    string text2;
                    flag = globalSession.TryGetTenantForestsByDomain(acceptedDomain, out externalDirectoryOrganizationId, out resourceForestFqdn, out text, out text2, out tenantName, out dataFromOfflineService);
                }
                else if (externalDirectoryOrganizationId != Guid.Empty)
                {
                    if (ADAccountPartitionLocator.externalOrgIdPartitionCache.TryGetValue(externalDirectoryOrganizationId, out cacheItem))
                    {
                        ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.ExternalDirectoryObjectId, true);
                        return(true);
                    }
                    ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.ExternalDirectoryObjectId, false);
                    flag = globalSession.TryGetTenantForestsByOrgGuid(externalDirectoryOrganizationId, out resourceForestFqdn, out text, out tenantName, out dataFromOfflineService);
                }
                else
                {
                    if (ADAccountPartitionLocator.msaUserNetIdPartitionCache.TryGetValue(msaUserNetID, out cacheItem))
                    {
                        ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.MSAUserNetID, true);
                        return(true);
                    }
                    ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.MSAUserNetID, false);
                    flag = globalSession.TryGetTenantForestsByMSAUserNetID(msaUserNetID, out externalDirectoryOrganizationId, out resourceForestFqdn, out text, out tenantName);
                }
                if (flag)
                {
                    ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
                    Guid accountPartitionGuid;
                    ADAccountPartitionLocator.partitionsFQDNToGuid.TryGetValue(text, out accountPartitionGuid);
                    cacheItem = new TenantPartitionCacheItem(accountPartitionGuid, text, resourceForestFqdn, externalDirectoryOrganizationId, tenantName, dataFromOfflineService);
                    ADAccountPartitionLocator.InsertCacheMaps(cacheItem, acceptedDomain, msaUserNetID);
                    return(true);
                }
            }
            catch (MServTransientException ex2)
            {
                ex = ex2;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (MServPermanentException ex3)
            {
                ex = ex3;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (TransientException ex4)
            {
                ex = ex4;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (GlsPermanentException ex5)
            {
                ex = ex5;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (GlsTenantNotFoundException ex6)
            {
                ex = ex6;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            if (ex != null)
            {
                ExTraceGlobals.GLSTracer.TraceWarning <Exception>(0L, "Got exception while doing GLS lookup in ADAccountPartitionLocator, ignoring it until 2605034 is fixed {0}", ex);
            }
            return(false);
        }
 // Token: 0x06000314 RID: 788 RVA: 0x00010B26 File Offset: 0x0000ED26
 public static PartitionId[] GetAllAccountPartitionIdsEnabledForProvisioning()
 {
     ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
     return(ADAccountPartitionLocator.allAccountPartitionIdsEnabledForProvisioning);
 }