private static TargetForestConfiguration ConstructTargetForestConfiguration(AvailabilityAddressSpace addressSpace, ScpSearch localScpSearch)
        {
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Processing AvailabilityAddressSpace name: {0}", addressSpace.ForestName);
            NetworkCredential     networkCredential     = null;
            AutodiscoverUrlSource autodiscoverUrlSource = AutodiscoverUrlSource.Unknown;
            Uri uri = null;

            if (addressSpace.AccessMethod != AvailabilityAccessMethod.OrgWideFB && addressSpace.AccessMethod != AvailabilityAccessMethod.PerUserFB)
            {
                if (addressSpace.AccessMethod != AvailabilityAccessMethod.OrgWideFBBasic)
                {
                    goto IL_1B2;
                }
            }
            try
            {
                networkCredential = TargetForestConfigurationCache.GetCredentials(addressSpace);
            }
            catch (InvalidCrossForestCredentialsException exception)
            {
                return(new TargetForestConfiguration(addressSpace.Id.ToString(), addressSpace.ForestName, exception));
            }
            if (addressSpace.TargetAutodiscoverEpr != null)
            {
                uri = addressSpace.TargetAutodiscoverEpr;
                TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <Uri>(0L, "Retrieved Autodiscover URL {0} from address space.", uri);
                goto IL_1B2;
            }
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Searching for SCP objects for domain {0}", addressSpace.ForestName);
            uri = localScpSearch.FindRemote(addressSpace.ForestName, networkCredential);
            if (uri != null)
            {
                TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string, Uri>(0L, "Found autodiscover URL from SCP objects for domain {0}. Url is: {1}", addressSpace.ForestName, uri);
                autodiscoverUrlSource = AutodiscoverUrlSource.SCP;
                goto IL_1B2;
            }
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Found no suitable autodiscover URL from SCP objects for domain {0}. Trying well-known endpoints.", addressSpace.ForestName);
            uri = TargetForestConfigurationCache.DiscoverFromWellKnown(addressSpace.ForestName, networkCredential);
            if (uri != null)
            {
                TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string, Uri>(0L, "Found autodiscover URL from well-known endpoints for domain {0}. Url is: {1}", addressSpace.ForestName, uri);
                autodiscoverUrlSource = AutodiscoverUrlSource.WellKnown;
                goto IL_1B2;
            }
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Found no suitable autodiscover URL from well-known endpoints for domain {0}. Trying SRV records from DNS.", addressSpace.ForestName);
            uri = AutoDiscoverDnsReader.Query(addressSpace.ForestName);
            if (uri != null)
            {
                TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string, Uri>(0L, "Found autodiscover URL from SRV records from DNS for domain {0}. Url is: {1}", addressSpace.ForestName, uri);
                autodiscoverUrlSource = AutodiscoverUrlSource.SRV;
                goto IL_1B2;
            }
            TargetForestConfigurationCache.ConfigurationTracer.TraceDebug <string>(0L, "Found no suitable autodiscover URL from well-known endpoint lookup for domain {0}.", addressSpace.ForestName);
            return(new TargetForestConfiguration(addressSpace.Id.ToString(), addressSpace.ForestName, new AutoDiscoverFailedException(Strings.descAvailabilityAddressSpaceFailed(addressSpace.Id.ToString()))));

IL_1B2:
            return(new TargetForestConfiguration(addressSpace.Id.ToString(), addressSpace.ForestName, addressSpace.AccessMethod, networkCredential, uri, autodiscoverUrlSource));
        }