// 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);
        }
        internal override void ProcessRedirectionEntry(IGlobalDirectorySession session)
        {
            string memberName     = string.Format("E5CB63F56E8B4b69A1F70C192276D6AD@{0}", this.DomainName);
            string redirectServer = session.GetRedirectServer(memberName);

            if (string.IsNullOrEmpty(redirectServer))
            {
                base.WriteError(new CannotDetermineManagementEndpointException(Strings.ErrorCannotDetermineEndpointForTenant(this.DomainName.ToString())), ErrorCategory.InvalidData, null);
            }
            string             remotePowershellUrl = string.Format("https://{0}/PowerShell/", redirectServer);
            ManagementEndpoint managementEndpoint  = new ManagementEndpoint(remotePowershellUrl, ManagementEndpointVersion.Version3)
            {
                DomainName = this.DomainName
            };
            Guid   guid;
            string resourceForest;
            string accountPartition;
            string smtpNextHopDomain;
            string text;
            bool   flag;

            if (((GlsMServDirectorySession.GlsLookupMode != GlsLookupMode.MServOnly && session is GlsMServDirectorySession) || session is GlsDirectorySession) && session.TryGetTenantForestsByDomain(this.DomainName.ToString(), out guid, out resourceForest, out accountPartition, out smtpNextHopDomain, out text, out flag) && Guid.Empty != guid)
            {
                managementEndpoint.AccountPartition  = accountPartition;
                managementEndpoint.SmtpNextHopDomain = smtpNextHopDomain;
                managementEndpoint.ResourceForest    = resourceForest;
                managementEndpoint.ExternalDirectoryOrganizationId = guid;
            }
            ExTraceGlobals.LogTracer.Information <string, ManagementEndpointVersion>(0L, "Get-ManagementEndPoint URL/Version {0}/{1}", managementEndpoint.RemotePowershellUrl, managementEndpoint.Version);
            base.WriteObject(managementEndpoint);
        }