Esempio n. 1
0
        private static Uri GetFrontEndHttpServiceUrl <ServiceType>(IExchangePrincipal exchangePrincipal) where ServiceType : HttpService
        {
            if (exchangePrincipal == null)
            {
                throw new ArgumentNullException("exchangePrincipal");
            }
            if (exchangePrincipal.MailboxInfo.Location.ServerVersion >= Server.E15MinVersion && FrontEndLocator.IsDatacenter)
            {
                return(GlobalServiceUrls.GetExternalUrl <ServiceType>());
            }
            ServiceTopology     serviceTopology = FrontEndLocator.IsDatacenter ? ServiceTopology.GetCurrentLegacyServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\FrontEndLocator.cs", "GetFrontEndHttpServiceUrl", 276) : ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\FrontEndLocator.cs", "GetFrontEndHttpServiceUrl", 276);
            ServerVersion       serverVersion   = new ServerVersion(exchangePrincipal.MailboxInfo.Location.ServerVersion);
            int                 majorversion    = serverVersion.Major;
            IList <ServiceType> services        = serviceTopology.FindAll <ServiceType>(exchangePrincipal, ClientAccessType.External, (ServiceType service) => new ServerVersion(service.ServerVersionNumber).Major == majorversion, "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\FrontEndLocator.cs", "GetFrontEndHttpServiceUrl", 281);
            Uri                 uri             = FrontEndLocator.FindServiceInList <ServiceType>(services);

            if (uri == null)
            {
                services = serviceTopology.FindAll <ServiceType>(exchangePrincipal, ClientAccessType.Internal, (ServiceType service) => new ServerVersion(service.ServerVersionNumber).Major == majorversion, "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\FrontEndLocator.cs", "GetFrontEndHttpServiceUrl", 285);
                uri      = FrontEndLocator.FindServiceInList <ServiceType>(services);
            }
            if (uri != null)
            {
                ExTraceGlobals.CafeTracer.TraceDebug <string>(0L, "[FrontEndLocator.GetFrontEndHttpServiceUrl] Found HTTP service for the specified back end server {0}.", exchangePrincipal.MailboxInfo.Location.ServerFqdn);
                return(uri);
            }
            throw new ServerNotFoundException("Unable to find proper HTTP service.");
        }
Esempio n. 2
0
        public static Uri GetExternalUrl <Service>() where Service : HttpService
        {
            ServiceType key = GlobalServiceUrls.ConvertHttpServiceType <Service>();

            GlobalServiceUrls.DiscoverUrlsIfNeeded();
            return(GlobalServiceUrls.E15Services[key].ExternalUri);
        }
Esempio n. 3
0
        public static ProtocolConnectionSettings GetInternalProtocolSettingsForLocalServer <ProtocolServiceType>() where ProtocolServiceType : Service
        {
            ServiceType key = GlobalServiceUrls.ConvertProtocolServiceType <ProtocolServiceType>();

            GlobalServiceUrls.DiscoverProtocolSettingsIfNeeded();
            ProtocolConnectionSettings result = null;

            GlobalServiceUrls.E15ProtocolsInternal.TryGetValue(key, out result);
            return(result);
        }
Esempio n. 4
0
        public static Uri GetExternalUrl <Service>(string serverFqdn) where Service : HttpService
        {
            ServiceType key = GlobalServiceUrls.ConvertHttpServiceType <Service>();

            GlobalServiceUrls.DiscoverUrlsIfNeeded();
            VDirInfo   vdirInfo    = GlobalServiceUrls.E15Services[key];
            Uri        externalUri = vdirInfo.ExternalUri;
            UriBuilder uriBuilder  = new UriBuilder(externalUri.Scheme, serverFqdn, 443, vdirInfo.Path);

            return(uriBuilder.Uri);
        }
Esempio n. 5
0
 private static void DiscoverProtocolSettingsIfNeeded()
 {
     if (GlobalServiceUrls.E15Protocols == null)
     {
         ExTraceGlobals.CafeTracer.TraceDebug <int>(0L, "[GlobalServiceUrls.DiscoverProtocolSettingsIfNeeded] Protocol settings information is not yet cached, starting discovery of up to {0} Cafe servers", 20);
         lock (GlobalServiceUrls.protocolLockRoot)
         {
             if (GlobalServiceUrls.E15Protocols != null)
             {
                 ExTraceGlobals.CafeTracer.TraceDebug(0L, "[GlobalServiceUrls.DiscoverProtocolSettingsIfNeeded] Another thread completed discovery first, nothing to do.");
             }
             else if (GlobalServiceUrls.TryDiscoverProtocolSettings(true))
             {
                 ExTraceGlobals.CafeTracer.TraceDebug(0L, "[GlobalServiceUrls.DiscoverProtocolSettingsIfNeeded] Completed the discovery within the local site.");
             }
             else
             {
                 GlobalServiceUrls.TryDiscoverProtocolSettings(false);
             }
         }
     }
 }
Esempio n. 6
0
        internal static Uri GetBackEndServiceUrlByServer <ServiceType>(BackEndServer backEndServer) where ServiceType : HttpService
        {
            if (backEndServer.IsE15OrHigher)
            {
                return(GlobalServiceUrls.GetInternalUrl <ServiceType>(backEndServer.Fqdn));
            }
            HttpProxyBackEndHelper.TopologyWithSites legacyServiceTopologyWithSites = HttpProxyBackEndHelper.GetLegacyServiceTopologyWithSites(backEndServer.Fqdn);
            ServiceType serviceType = legacyServiceTopologyWithSites.ServiceTopology.FindAny <ServiceType>(ClientAccessType.InternalNLBBypass, (ServiceType service) => service != null && !service.IsFrontEnd && service.ServerFullyQualifiedDomainName.Equals(backEndServer.Fqdn, StringComparison.OrdinalIgnoreCase), "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\HttpProxyBackEndHelper.cs", "GetBackEndServiceUrlByServer", 568);

            if (serviceType != null)
            {
                ExTraceGlobals.CafeTracer.TraceDebug <BackEndServer>(0L, "[HttpProxyBackEndHelper.GetBackEndServiceUrlByServer] Found HTTP service on the specified back end server {0}.", backEndServer);
                return(serviceType.Url);
            }
            serviceType = HttpProxyBackEndHelper.GetBestBackEndServiceForVersion <ServiceType>(legacyServiceTopologyWithSites, ClientAccessType.InternalNLBBypass, (int x) => new ServerVersion(x).Major == new ServerVersion(backEndServer.Version).Major);
            ExTraceGlobals.CafeTracer.TraceDebug <string, int>(0L, "[HttpProxyBackEndHelper.GetBackEndServiceByServer] Found HTTP service {0} with version {1}.", serviceType.ServerFullyQualifiedDomainName, serviceType.ServerVersionNumber);
            if (serviceType != null)
            {
                return(serviceType.Url);
            }
            throw new ServerNotFoundException("Unable to find proper HTTP service.");
        }
Esempio n. 7
0
        private static bool TryDiscoverProtocolSettings(bool useLocalSite)
        {
            ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.NonCacheSessionFactory.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 413, "TryDiscoverProtocolSettings", "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\GlobalServiceUrls.cs");
            ADObjectId  id               = LocalSiteCache.LocalSite.Id;
            QueryFilter queryFilter      = new ComparisonFilter(useLocalSite ? ComparisonOperator.Equal : ComparisonOperator.NotEqual, ServerSchema.ServerSite, id);
            QueryFilter additionalFilter = new AndFilter(new QueryFilter[]
            {
                queryFilter,
                GlobalServiceUrls.CafeFilter
            });
            ADPagedReader <MiniServer> adpagedReader = topologyConfigurationSession.FindAllServersWithVersionNumber(Server.E15MinVersion, additionalFilter, null);

            adpagedReader.PageSize = 20;
            int    num   = 0;
            string text  = string.Empty;
            bool   flag  = false;
            bool   flag2 = false;
            bool   flag3 = false;
            bool   flag4 = false;
            bool   flag5 = false;
            Dictionary <ServiceType, ProtocolConnectionSettings> dictionary  = null;
            Dictionary <ServiceType, ProtocolConnectionSettings> dictionary2 = null;

            foreach (MiniServer miniServer in adpagedReader)
            {
                text = miniServer.Name;
                ADEmailTransport[]             source     = topologyConfigurationSession.Find <ADEmailTransport>(miniServer.Id, QueryScope.SubTree, null, null, 1000, null);
                IEnumerable <ADEmailTransport> enumerable = from adEmailTransport in source
                                                            where adEmailTransport is Pop3AdConfiguration
                                                            select adEmailTransport;
                IEnumerable <ADEmailTransport> enumerable2 = from adEmailTransport in source
                                                             where adEmailTransport is Imap4AdConfiguration
                                                             select adEmailTransport;
                ReceiveConnector[] array = topologyConfigurationSession.Find <ReceiveConnector>(miniServer.Id, QueryScope.SubTree, GlobalServiceUrls.ReceiveConnectorFilter, null, 1000, null);
                ExTraceGlobals.CafeTracer.TraceDebug <int, string, int>(0L, "[GlobalServiceUrls.TryDiscoverProtocolSettings] Attempt {0}: Processing {1} and its {2} connectors", num, text, array.Length);
                dictionary  = new Dictionary <ServiceType, ProtocolConnectionSettings>(3);
                dictionary2 = new Dictionary <ServiceType, ProtocolConnectionSettings>(3);
                flag        = false;
                flag2       = false;
                flag3       = false;
                flag4       = false;
                flag5       = false;
                foreach (ADEmailTransport ademailTransport in enumerable)
                {
                    Pop3AdConfiguration popImapConfiguration = (Pop3AdConfiguration)ademailTransport;
                    if (!flag && GlobalServiceUrls.TrySelectProtocolConnectionSettings(ServiceType.Pop3, popImapConfiguration, true, dictionary))
                    {
                        flag = true;
                    }
                    if (!flag2 && GlobalServiceUrls.TrySelectProtocolConnectionSettings(ServiceType.Pop3, popImapConfiguration, false, dictionary2))
                    {
                        flag2 = true;
                    }
                    if (flag && flag2)
                    {
                        break;
                    }
                }
                foreach (ADEmailTransport ademailTransport2 in enumerable2)
                {
                    Imap4AdConfiguration popImapConfiguration2 = (Imap4AdConfiguration)ademailTransport2;
                    if (!flag3 && GlobalServiceUrls.TrySelectProtocolConnectionSettings(ServiceType.Imap4, popImapConfiguration2, true, dictionary))
                    {
                        flag3 = true;
                    }
                    if (!flag4 && GlobalServiceUrls.TrySelectProtocolConnectionSettings(ServiceType.Imap4, popImapConfiguration2, false, dictionary2))
                    {
                        flag4 = true;
                    }
                    if (flag3 && flag4)
                    {
                        break;
                    }
                }
                ProtocolConnectionSettings protocolConnectionSettings = null;
                foreach (ReceiveConnector receiveConnector in array)
                {
                    Hostname hostname;
                    if (!Hostname.TryParse(receiveConnector.ServiceDiscoveryFqdn, out hostname) && !Hostname.TryParse(receiveConnector.Fqdn, out hostname))
                    {
                        ExTraceGlobals.CafeTracer.TraceWarning <ADObjectId>(0L, "[GlobalServiceUrls.TryDiscoverProtocolSettings] Smtp connector {0} has no valid ServiceDiscoveryFqdn or Fqdn", receiveConnector.Id);
                    }
                    else
                    {
                        int  port  = receiveConnector.Bindings[0].Port;
                        bool flag6 = (receiveConnector.AuthMechanism & (AuthMechanisms.Tls | AuthMechanisms.BasicAuthRequireTLS)) != AuthMechanisms.None;
                        if (flag6)
                        {
                            protocolConnectionSettings = new ProtocolConnectionSettings(hostname, port, new EncryptionType?(EncryptionType.TLS));
                            break;
                        }
                        if (protocolConnectionSettings == null)
                        {
                            protocolConnectionSettings = new ProtocolConnectionSettings(hostname, port, null);
                        }
                    }
                }
                if (protocolConnectionSettings != null)
                {
                    dictionary[ServiceType.Smtp]  = protocolConnectionSettings;
                    dictionary2[ServiceType.Smtp] = protocolConnectionSettings;
                    flag5 = true;
                }
                if (flag2 && flag4 && flag5)
                {
                    ExTraceGlobals.CafeTracer.TraceDebug(0L, "[GlobalServiceUrls.TryDiscoverProtocolSettings] Successfully found all needed internal protocol settings");
                    GlobalServiceUrls.E15ProtocolsInternal = dictionary2;
                }
                if (flag && flag3 && flag5)
                {
                    ExTraceGlobals.CafeTracer.TraceDebug(0L, "[GlobalServiceUrls.TryDiscoverProtocolSettings] Successfully found all needed external protocol settings");
                    GlobalServiceUrls.E15Protocols = dictionary;
                    return(true);
                }
                if (++num >= 20)
                {
                    ExTraceGlobals.CafeTracer.TraceError(0L, "[GlobalServiceUrls.TryDiscoverProtocolSettings] Retry limit reached, Could not find all of the needed Protocol configurations.");
                    break;
                }
            }
            if (!GlobalServiceUrls.IsDatacenter)
            {
                if (dictionary != null && dictionary.Count > 0)
                {
                    ExTraceGlobals.CafeTracer.TraceWarning(0L, "[GlobalServiceUrls.TryDiscoverProtocolSettings] Found only some of the needed external protocol settings. Missing:" + (flag ? string.Empty : "POP3,") + (flag3 ? string.Empty : "IMAP4,") + (flag5 ? string.Empty : "SMTP"));
                    GlobalServiceUrls.E15Protocols = dictionary;
                }
                if (dictionary2 != null && dictionary2.Count > 0)
                {
                    ExTraceGlobals.CafeTracer.TraceWarning(0L, "[GlobalServiceUrls.TryDiscoverProtocolSettings] Found only some of the needed internal protocol settings. Missing:" + (flag2 ? string.Empty : "POP3,") + (flag4 ? string.Empty : "IMAP4,") + (flag5 ? string.Empty : "SMTP"));
                    GlobalServiceUrls.E15ProtocolsInternal = dictionary2;
                }
            }
            if (!useLocalSite && GlobalServiceUrls.E15Protocols == null)
            {
                if (GlobalServiceUrls.IsDatacenter)
                {
                    throw new ProtocolConfigurationMissingException(text, "ExternalSettings");
                }
                GlobalServiceUrls.E15Protocols = new Dictionary <ServiceType, ProtocolConnectionSettings>(0);
            }
            if (!useLocalSite && GlobalServiceUrls.E15ProtocolsInternal == null)
            {
                if (GlobalServiceUrls.IsDatacenter)
                {
                    throw new ProtocolConfigurationMissingException(text, "InternalSettings");
                }
                GlobalServiceUrls.E15ProtocolsInternal = new Dictionary <ServiceType, ProtocolConnectionSettings>(0);
            }
            return(false);
        }
Esempio n. 8
0
 public static MiniVirtualDirectory GetRpcHttpVdir()
 {
     GlobalServiceUrls.DiscoverUrlsIfNeeded();
     return(GlobalServiceUrls.rpcHttpVdir);
 }
Esempio n. 9
0
 private static void DiscoverUrlsIfNeeded()
 {
     if (GlobalServiceUrls.E15Services == null)
     {
         ExTraceGlobals.CafeTracer.TraceDebug <int>(0L, "[GlobalServiceUrls.DiscoverUrlsIfNeeded] VDir information is not yet cached, starting discovery of up to {0} Cafe servers", 20);
         lock (GlobalServiceUrls.urlLockRoot)
         {
             if (GlobalServiceUrls.E15Services == null)
             {
                 ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.NonCacheSessionFactory.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 284, "DiscoverUrlsIfNeeded", "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\GlobalServiceUrls.cs");
                 ADPagedReader <MiniServer>    adpagedReader = topologyConfigurationSession.FindAllServersWithVersionNumber(Server.E15MinVersion, GlobalServiceUrls.CafeFilter, null);
                 adpagedReader.PageSize = 20;
                 int    num   = 0;
                 string text  = string.Empty;
                 bool   flag2 = false;
                 bool   flag3 = false;
                 bool   flag4 = false;
                 bool   flag5 = false;
                 bool   flag6 = false;
                 bool   flag7 = false;
                 foreach (MiniServer miniServer in adpagedReader)
                 {
                     text = miniServer.Name;
                     MiniVirtualDirectory[] array = topologyConfigurationSession.FindMiniVirtualDirectories(miniServer.Id);
                     ExTraceGlobals.CafeTracer.TraceDebug <int, string, int>(0L, "[GlobalServiceUrls.DiscoverUrlsIfNeeded] Attempt {0}: Processing {1} and its {2} VDirs", num, text, array.Length);
                     Dictionary <ServiceType, VDirInfo> e15Services = new Dictionary <ServiceType, VDirInfo>(6);
                     flag2 = false;
                     flag3 = false;
                     flag4 = false;
                     flag5 = false;
                     flag6 = false;
                     flag7 = false;
                     bool flag8 = false;
                     foreach (MiniVirtualDirectory miniVirtualDirectory in array)
                     {
                         if (miniVirtualDirectory.IsEcp)
                         {
                             GlobalServiceUrls.SelectUrl(ServiceType.ExchangeControlPanel, miniVirtualDirectory, e15Services, ref flag3);
                         }
                         else if (miniVirtualDirectory.IsOwa)
                         {
                             GlobalServiceUrls.SelectUrl(ServiceType.OutlookWebAccess, miniVirtualDirectory, e15Services, ref flag2);
                         }
                         else if (miniVirtualDirectory.IsWebServices)
                         {
                             GlobalServiceUrls.SelectUrl(ServiceType.WebServices, miniVirtualDirectory, e15Services, ref flag4);
                         }
                         else if (miniVirtualDirectory.IsMobile)
                         {
                             GlobalServiceUrls.SelectUrl(ServiceType.MobileSync, miniVirtualDirectory, e15Services, ref flag5);
                         }
                         else if (miniVirtualDirectory.IsOab)
                         {
                             GlobalServiceUrls.SelectUrl(ServiceType.OfflineAddressBook, miniVirtualDirectory, e15Services, ref flag6);
                         }
                         else if (miniVirtualDirectory.IsMapi)
                         {
                             GlobalServiceUrls.SelectUrl(ServiceType.MapiHttp, miniVirtualDirectory, e15Services, ref flag7);
                         }
                         else if (miniVirtualDirectory.IsRpcHttp)
                         {
                             GlobalServiceUrls.rpcHttpVdir = miniVirtualDirectory;
                             flag8 = true;
                         }
                         if (flag2 && flag3 && flag4 && flag5 && flag6 && flag7 && flag8)
                         {
                             ExTraceGlobals.CafeTracer.TraceDebug(0L, "[GlobalServiceUrls.DiscoverUrlsIfNeeded] Successfully found all needed VDirs");
                             GlobalServiceUrls.E15Services = e15Services;
                             return;
                         }
                     }
                     if (++num >= 20)
                     {
                         ExTraceGlobals.CafeTracer.TraceError(0L, "[GlobalServiceUrls.DiscoverUrlsIfNeeded] Retry limit reached, Could not find needed VDirs.");
                         break;
                     }
                 }
                 throw new VDirConfigurationMissingException(text, GlobalServiceUrls.IsDatacenter ? "ExternalUrl" : "InternalUrl", (flag2 ? string.Empty : "OWA,") + (flag3 ? string.Empty : "ECP,") + (flag4 ? string.Empty : "EWS"));
             }
             ExTraceGlobals.CafeTracer.TraceDebug(0L, "[GlobalServiceUrls.DiscoverUrlsIfNeeded] Another thread completed discovery first, nothing to do.");
         }
     }
 }
Esempio n. 10
0
 public static ProtocolConnectionSettings GetInternalSmtpSettingsForLocalServer()
 {
     return(GlobalServiceUrls.GetInternalProtocolSettingsForLocalServer <SmtpService>());
 }
Esempio n. 11
0
 public static ProtocolConnectionSettings GetFrontEndImap4SettingsForLocalServer()
 {
     return(GlobalServiceUrls.GetExternalProtocolSettingsForLocalServer <Imap4Service>());
 }
Esempio n. 12
0
 public static Uri GetFrontEndWebServicesUrl(string serverFqdn)
 {
     return(GlobalServiceUrls.GetExternalUrl <WebServicesService>(serverFqdn));
 }
Esempio n. 13
0
 public static Uri GetDatacenterFrontEndOabUrl()
 {
     return(GlobalServiceUrls.GetExternalUrl <OabService>());
 }
Esempio n. 14
0
 public static Uri GetDatacenterFrontEndEasUrl()
 {
     return(GlobalServiceUrls.GetExternalUrl <MobileSyncService>());
 }
Esempio n. 15
0
 public static MiniVirtualDirectory GetDatacenterRpcHttpVdir()
 {
     return(GlobalServiceUrls.GetRpcHttpVdir());
 }
Esempio n. 16
0
 public static Uri GetDatacenterMapiHttpUrl()
 {
     return(GlobalServiceUrls.GetExternalUrl <MapiHttpService>());
 }