public static TargetForestConfiguration FindByDomain(OrganizationId organizationId, string domainName)
 {
     if (!VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled)
     {
         TargetForestConfiguration result;
         if (!TargetForestConfigurationCache.cache.TryGetValue(domainName, out result))
         {
             TargetForestConfigurationCache.ConfigurationTracer.TraceError <object, string>(0L, "{0}: TargetForestConfiguration for domain {1} could not be found in cache", TraceContext.Get(), domainName);
             throw new AddressSpaceNotFoundException(Strings.descConfigurationInformationNotFound(domainName), 51004U);
         }
         return(result);
     }
     else
     {
         if (organizationId == null)
         {
             OrganizationId forestWideOrgId = OrganizationId.ForestWideOrgId;
         }
         OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(organizationId);
         if (organizationIdCacheValue == null)
         {
             TargetForestConfigurationCache.ConfigurationTracer.TraceError <object, OrganizationId>(0L, "{0}: Unable to find organization {1} in the OrgId cache", TraceContext.Get(), organizationId);
             throw new AddressSpaceNotFoundException(Strings.descConfigurationInformationNotFound(domainName), 64316U);
         }
         AvailabilityAddressSpace availabilityAddressSpace = organizationIdCacheValue.GetAvailabilityAddressSpace(domainName);
         if (availabilityAddressSpace != null)
         {
             TargetForestConfiguration result = TargetForestConfigurationCache.ConstructTargetForestConfiguration(availabilityAddressSpace, null);
             return(result);
         }
         TargetForestConfigurationCache.ConfigurationTracer.TraceError <object, string, OrganizationId>(0L, "{0}: TargetForestConfiguration for domain {1} could not be found in cache for organization {2}", TraceContext.Get(), domainName, organizationId);
         throw new AddressSpaceNotFoundException(Strings.descConfigurationInformationNotFound(domainName), 47932U);
     }
 }
        internal static void Populate(DateTime populateDeadline)
        {
            if (VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled)
            {
                return;
            }
            Dictionary <string, TargetForestConfiguration> dictionary = new Dictionary <string, TargetForestConfiguration>(StringComparer.InvariantCultureIgnoreCase);

            AvailabilityAddressSpace[] array = TargetForestConfigurationCache.SearchAddressSpaceForEnterprise();
            if (array != null && array.Length > 0)
            {
                ScpSearch localScpSearch = ScpSearch.FindLocal();
                foreach (AvailabilityAddressSpace availabilityAddressSpace in array)
                {
                    TargetForestConfiguration targetForestConfiguration;
                    if (dictionary.TryGetValue(availabilityAddressSpace.ForestName, out targetForestConfiguration))
                    {
                        TargetForestConfigurationCache.ConfigurationTracer.TraceError <string, string, ADObjectId>(0L, "There are two or more AvailabilityAddressSpace objects in AD with same ForestName {0}. Existing is {1}. Ignoring object {2}", availabilityAddressSpace.ForestName, targetForestConfiguration.Id, availabilityAddressSpace.Id);
                        Globals.AvailabilityLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_DuplicateAvailabilityAddressSpace, null, new object[]
                        {
                            Globals.ProcessId,
                            availabilityAddressSpace.ForestName,
                            targetForestConfiguration.Id,
                            availabilityAddressSpace.Id
                        });
                    }
                    else if (availabilityAddressSpace.AccessMethod == AvailabilityAccessMethod.InternalProxy)
                    {
                        TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Ignoring AvailabilityAddressSpace with ForestName {0} because it is an internal proxy.", availabilityAddressSpace.ForestName);
                    }
                    else
                    {
                        dictionary.Add(availabilityAddressSpace.ForestName, TargetForestConfigurationCache.ConstructTargetForestConfiguration(availabilityAddressSpace, localScpSearch));
                    }
                    if (DateTime.UtcNow > populateDeadline)
                    {
                        TargetForestConfigurationCache.ConfigurationTracer.TraceError(0L, "Unable to continue populating the target forest cache. Deadline has been exceeded.");
                        break;
                    }
                }
            }
            if (dictionary.Count > 0)
            {
                TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <int>(0L, "Updating to new TargetForestConfiguration cache with {0} entries", dictionary.Count);
                TargetForestConfigurationCache.cache = dictionary;
            }
        }