Example #1
0
        // Token: 0x060050D2 RID: 20690 RVA: 0x0012C144 File Offset: 0x0012A344
        public RUSFinder(ExchangeTopology topology)
        {
            this.topo           = topology;
            this.siteDictionary = new Dictionary <TopologySite, List <TopologyServer> >();
            this.siteList       = new List <TopologySite>();
            ReadOnlyCollection <TopologyServer> allTopologyServers = this.topo.AllTopologyServers;
            int num  = 0;
            int num2 = 0;

            foreach (TopologyServer topologyServer in allTopologyServers)
            {
                if (topologyServer.TopologySite != null && topologyServer.IsExchange2007OrLater && topologyServer.IsMailboxServer)
                {
                    List <TopologyServer> list;
                    if (!this.siteDictionary.TryGetValue(topologyServer.TopologySite, out list))
                    {
                        this.siteList.Add(topologyServer.TopologySite);
                        list = new List <TopologyServer>();
                        this.siteDictionary.Add(topologyServer.TopologySite, list);
                        num++;
                    }
                    list.Add(topologyServer);
                    num2++;
                    if (ExTraceGlobals.RecipientUpdateServiceTracer.IsTraceEnabled(TraceType.DebugTrace))
                    {
                        ExTraceGlobals.RecipientUpdateServiceTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "Found RUS Server: {0} ({1}) in site {2}", topologyServer.Name, topologyServer.Fqdn, (topologyServer.TopologySite == null) ? "no site" : topologyServer.TopologySite.Name);
                    }
                }
            }
            ExTraceGlobals.RecipientUpdateServiceTracer.TraceDebug <int, int>((long)this.GetHashCode(), "Found {0} potential RUS Servers in {1} sites.", num2, num);
        }
Example #2
0
        internal static void DiscoverServers(ITopologyConfigurationSession session, bool limitedSearch, out Dictionary <TopologySite, List <TopologyServer> > siteDictionary, out TopologySite localSite)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            ExchangeTopology exchangeTopology = ExchangeTopology.Discover(session, ExchangeTopologyScope.ServerAndSiteTopology);

            localSite      = exchangeTopology.LocalSite;
            siteDictionary = new Dictionary <TopologySite, List <TopologyServer> >();
            if (localSite == null)
            {
                return;
            }
            List <ITopologySite> list = new List <ITopologySite>();

            if (limitedSearch)
            {
                foreach (ITopologySiteLink topologySiteLink in localSite.TopologySiteLinks)
                {
                    foreach (ITopologySite item in topologySiteLink.TopologySites)
                    {
                        if (!list.Contains(item))
                        {
                            list.Add(item);
                        }
                    }
                }
            }
            foreach (TopologyServer topologyServer in exchangeTopology.AllTopologyServers)
            {
                if (topologyServer.TopologySite != null && FederationCertificate.IsServerQualifiedForFederationTrust(topologyServer) && (!limitedSearch || list.Contains(topologyServer.TopologySite)))
                {
                    List <TopologyServer> list2;
                    if (!siteDictionary.TryGetValue(topologyServer.TopologySite, out list2))
                    {
                        list2 = new List <TopologyServer>();
                        siteDictionary.Add(topologyServer.TopologySite, list2);
                    }
                    list2.Add(topologyServer);
                }
            }
        }
Example #3
0
        private void PopulateServiceCache(object obj)
        {
            ServiceCache.CachePopulateReason cachePopulateReason = (ServiceCache.CachePopulateReason)obj;
            Exception ex = null;

            try
            {
                try
                {
                    DateTime dateTime     = (cachePopulateReason == ServiceCache.CachePopulateReason.CacheMissDetected || this.serviceTopologyInstance == null) ? DateTime.MinValue : this.serviceTopologyInstance.DiscoveryStarted;
                    bool     forceRefresh = false;
                    if (this.dropCacheOnInactivity && dateTime != DateTime.MinValue && this.serviceTopologyInstance.TopologyRequestCount <= 1)
                    {
                        this.DropCache();
                        return;
                    }
                    if (cachePopulateReason == ServiceCache.CachePopulateReason.CacheMissDetected || (cachePopulateReason == ServiceCache.CachePopulateReason.CacheNotPresent && this.isFirstLoad))
                    {
                        forceRefresh = true;
                    }
                    ExchangeTopology exchangeTopology = ServiceDiscovery.ExchangeTopologyBridge.ReadExchangeTopology(dateTime, ExchangeTopologyScope.Complete, forceRefresh);
                    if (exchangeTopology != null)
                    {
                        this.serviceTopologyInstance = new ServiceTopology(exchangeTopology, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\ServiceDiscovery\\ServiceCache.cs", "PopulateServiceCache", 426);
                    }
                    else if (this.serviceTopologyInstance != null)
                    {
                        this.serviceTopologyInstance.CreationTime = ExDateTime.Now;
                    }
                    this.isFirstLoad = false;
                    if (this.serviceTopologyInstance != null)
                    {
                        this.cachePresentEvent.Set();
                    }
                    else
                    {
                        ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug(0L, "ServiceCache::ServiceDiscovery.ExchangeTopologyBridge.ReadExchangeTopology returned null. This is unexpected");
                    }
                }
                catch (ServiceDiscoveryPermanentException ex2)
                {
                    ex = ex2;
                }
                catch (ServiceDiscoveryTransientException ex3)
                {
                    ex = ex3;
                }
                this.StartCacheRefreshTimer();
            }
            finally
            {
                this.semaphore.Release();
            }
            if (ex == null)
            {
                ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug <ServiceCache.CachePopulateReason>(0L, "ServiceCache::PopulateServiceCache. Successfully populated ServiceTopology. Reason to populate cache = {0}", cachePopulateReason);
                ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_PopulatedServiceTopology, null, new object[]
                {
                    cachePopulateReason
                });
                return;
            }
            string text = ex.ToString().TruncateToUseInEventLog();

            ExTraceGlobals.ServiceDiscoveryTracer.TraceError <ServiceCache.CachePopulateReason, string>(0L, "ServiceCache::PopulateServiceCache. Failed to populate a ServiceTopology. Reason to populate cache = {0}. Error = {1}.", cachePopulateReason, text);
            ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorPopulatingServiceTopology, null, new object[]
            {
                cachePopulateReason,
                text
            });
        }
Example #4
0
        internal static PublicFolderDatabase FindClosestPublicFolderDatabase(IConfigDataProvider scSession, ADObjectId sourceServerId, Func <PublicFolderDatabase, bool> candidateMatcher)
        {
            if (scSession == null)
            {
                throw new ArgumentNullException("scSession");
            }
            PublicFolderDatabase result = null;

            PublicFolderDatabase[] array = (PublicFolderDatabase[])scSession.Find <PublicFolderDatabase>(null, null, true, null);
            if (candidateMatcher != null && 0 < array.Length)
            {
                array = array.Where(candidateMatcher).ToArray <PublicFolderDatabase>();
            }
            if (1 == array.Length)
            {
                result = array[0];
            }
            else if (array.Length > 1)
            {
                ExchangeTopology exchangeTopology = ExchangeTopology.Discover(null, ExchangeTopologyScope.ADAndExchangeServerAndSiteTopology);
                TopologySite     topologySite     = null;
                TopologySite     topologySite2    = null;
                if (sourceServerId == null)
                {
                    topologySite = exchangeTopology.LocalSite;
                }
                else
                {
                    string text   = null;
                    Server server = (Server)scSession.Read <Server>(sourceServerId);
                    if (server != null)
                    {
                        text = server.Fqdn;
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        topologySite = exchangeTopology.SiteFromADServer(text);
                    }
                }
                if (topologySite != null)
                {
                    ReadOnlyCollection <TopologySite>         allTopologySites     = exchangeTopology.AllTopologySites;
                    ReadOnlyCollection <TopologySiteLink>     allTopologySiteLinks = exchangeTopology.AllTopologySiteLinks;
                    ReadOnlyCollection <TopologyServer>       allTopologyServers   = exchangeTopology.AllTopologyServers;
                    Dictionary <TopologyServer, TopologySite> dictionary           = new Dictionary <TopologyServer, TopologySite>();
                    foreach (TopologyServer topologyServer in allTopologyServers)
                    {
                        if (topologyServer.TopologySite != null)
                        {
                            foreach (TopologySite topologySite3 in allTopologySites)
                            {
                                if (topologySite3.DistinguishedName.Equals(topologyServer.TopologySite.DistinguishedName, StringComparison.OrdinalIgnoreCase))
                                {
                                    dictionary[topologyServer] = topologySite3;
                                    break;
                                }
                            }
                        }
                    }
                    Dictionary <TopologySite, PublicFolderDatabase> dictionary2 = new Dictionary <TopologySite, PublicFolderDatabase>();
                    List <TopologySite> list = new List <TopologySite>();
                    foreach (PublicFolderDatabase publicFolderDatabase in array)
                    {
                        foreach (KeyValuePair <TopologyServer, TopologySite> keyValuePair in dictionary)
                        {
                            if (keyValuePair.Key.DistinguishedName.Equals(publicFolderDatabase.Server.DistinguishedName, StringComparison.OrdinalIgnoreCase))
                            {
                                if (!dictionary2.ContainsKey(keyValuePair.Value))
                                {
                                    dictionary2[keyValuePair.Value] = publicFolderDatabase;
                                    list.Add(keyValuePair.Value);
                                    break;
                                }
                                if (keyValuePair.Key.IsExchange2007OrLater)
                                {
                                    dictionary2[keyValuePair.Value] = publicFolderDatabase;
                                    break;
                                }
                                break;
                            }
                        }
                    }
                    topologySite2 = exchangeTopology.FindClosestDestinationSite(topologySite, list);
                    if (topologySite2 != null)
                    {
                        result = dictionary2[topologySite2];
                    }
                }
                if (topologySite2 == null)
                {
                    result = array[0];
                }
            }
            return(result);
        }
Example #5
0
 public All(ExchangeTopology topology)
 {
     this.Servers   = new Dictionary <string, TopologyServerInfo>((topology != null) ? topology.AllTopologyServers.Count : 0, StringComparer.OrdinalIgnoreCase);
     this.Sites     = new Dictionary <string, Site>((topology != null) ? topology.AllTopologySites.Count : 0, StringComparer.OrdinalIgnoreCase);
     this.SiteLinks = new Dictionary <string, SiteLink>((topology != null) ? topology.AllTopologySiteLinks.Count : 0, StringComparer.OrdinalIgnoreCase);
 }
Example #6
0
        internal ServiceTopology(ExchangeTopology topology, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string memberName = null, [CallerLineNumber] int callerFileLine = 0)
        {
            ServiceTopologyLog.Instance.Append(callerFilePath, memberName, callerFileLine);
            ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug((long)this.GetHashCode(), "ServiceTopology::Constructor. Creating a ServiceTopology object...");
            if (topology.LocalServer == null)
            {
                ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug((long)this.GetHashCode(), "ServiceTopology::ServiceTopology.ctor. Cannot find the local server from ExchangeTopology. topology.LocalServer == null.");
                throw new ServerNotFoundException(ServerStrings.ExServerNotFound("localhost"), "localhost");
            }
            string fqdn = topology.LocalServer.Fqdn;

            this.discoveryStarted = topology.DiscoveryStarted;
            Dictionary <string, TopologyServerInfo> dictionary = new Dictionary <string, TopologyServerInfo>(topology.AllTopologyServers.Count, StringComparer.OrdinalIgnoreCase);
            Dictionary <string, Site> dictionary2 = new Dictionary <string, Site>(topology.AllTopologyServers.Count, StringComparer.OrdinalIgnoreCase);
            List <string>             list        = new List <string>();
            Dictionary <Site, List <TopologyServerInfo> > dictionary3 = new Dictionary <Site, List <TopologyServerInfo> >(topology.AllTopologySites.Count);

            ServiceTopology.All all = new ServiceTopology.All(topology);
            foreach (TopologyServer topologyServer in topology.AllTopologyServers)
            {
                if (topologyServer.TopologySite != null)
                {
                    if (!dictionary2.ContainsKey(topologyServer.Fqdn))
                    {
                        TopologyServerInfo topologyServerInfo = TopologyServerInfo.Get(topologyServer, all);
                        Site site = topologyServerInfo.Site;
                        dictionary.Add(topologyServer.Fqdn, topologyServerInfo);
                        dictionary2.Add(topologyServer.Fqdn, site);
                        List <TopologyServerInfo> list2;
                        if (!dictionary3.TryGetValue(site, out list2))
                        {
                            list2 = new List <TopologyServerInfo>();
                            dictionary3.Add(site, list2);
                        }
                        list2.Add(topologyServerInfo);
                        ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug <string, string, Site>((long)this.GetHashCode(), "ServiceTopology::Constructor. Found Server in topology. ServerDn = {0}. Server Fqdn = {1}. Site = {2}.", topologyServer.DistinguishedName, topologyServer.Fqdn, site);
                    }
                    else
                    {
                        string arg = string.Empty;
                        foreach (KeyValuePair <string, TopologyServerInfo> keyValuePair in all.Servers)
                        {
                            if (keyValuePair.Value.ServerFullyQualifiedDomainName.Equals(topologyServer.Fqdn))
                            {
                                arg = keyValuePair.Key;
                                break;
                            }
                        }
                        ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "ServiceTopology::Constructor. There are two servers with the same fqdn in the topology. The second server was ignored. Fqdn = {0}. Server1Dn = {1}. Server2Dn = {2}.", topologyServer.Fqdn, arg, topologyServer.DistinguishedName);
                    }
                }
                else
                {
                    ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug <string>((long)this.GetHashCode(), "ServiceTopology::Constructor. Found a Server in the topology without a defined Site. Server = {0}.", topologyServer.DistinguishedName);
                    if (fqdn.Equals(topologyServer.Fqdn))
                    {
                        throw new ServerNotInSiteException(ServerStrings.ExCurrentServerNotInSite(fqdn), fqdn);
                    }
                    if (!list.Contains(topologyServer.Fqdn))
                    {
                        list.Add(topologyServer.Fqdn);
                    }
                }
            }
            Dictionary <ServiceType, List <Service> > serviceLists          = new Dictionary <ServiceType, List <Service> >();
            Dictionary <ServiceType, List <Service> > serviceLists2         = new Dictionary <ServiceType, List <Service> >();
            ReadOnlyCollection <MiniVirtualDirectory> allVirtualDirectories = topology.AllVirtualDirectories;

            if (allVirtualDirectories != null)
            {
                foreach (MiniVirtualDirectory miniVirtualDirectory in allVirtualDirectories)
                {
                    TopologyServerInfo serverInfo;
                    if (all.Servers.TryGetValue(miniVirtualDirectory.Server.DistinguishedName, out serverInfo))
                    {
                        if (HttpService.IsFrontEndRole(miniVirtualDirectory, serverInfo))
                        {
                            this.AddHttpServiceToDictionaries(fqdn, serviceLists2, serverInfo, miniVirtualDirectory, ClientAccessType.Unknown, null, AuthenticationMethod.None);
                        }
                        if (miniVirtualDirectory.InternalUrl != null)
                        {
                            AuthenticationMethod authenticationMethod = ServiceTopology.GetAuthenticationMethod(miniVirtualDirectory[MiniVirtualDirectorySchema.InternalAuthenticationMethodFlags]);
                            this.AddHttpServiceToDictionaries(fqdn, serviceLists, serverInfo, miniVirtualDirectory, ClientAccessType.Internal, miniVirtualDirectory.InternalUrl, authenticationMethod);
                        }
                        if (miniVirtualDirectory.IsWebServices && miniVirtualDirectory.InternalNLBBypassUrl != null)
                        {
                            AuthenticationMethod authenticationMethod2 = ServiceTopology.GetAuthenticationMethod(miniVirtualDirectory[MiniVirtualDirectorySchema.InternalAuthenticationMethodFlags]);
                            this.AddHttpServiceToDictionaries(fqdn, serviceLists, serverInfo, miniVirtualDirectory, ClientAccessType.InternalNLBBypass, miniVirtualDirectory.InternalNLBBypassUrl, authenticationMethod2);
                        }
                        if (miniVirtualDirectory.ExternalUrl != null)
                        {
                            AuthenticationMethod authenticationMethod3 = ServiceTopology.GetAuthenticationMethod(miniVirtualDirectory[MiniVirtualDirectorySchema.ExternalAuthenticationMethodFlags]);
                            this.AddHttpServiceToDictionaries(fqdn, serviceLists, serverInfo, miniVirtualDirectory, ClientAccessType.External, miniVirtualDirectory.ExternalUrl, authenticationMethod3);
                        }
                    }
                }
            }
            ReadOnlyCollection <MiniEmailTransport> allEmailTransports = topology.AllEmailTransports;

            if (allEmailTransports != null)
            {
                foreach (MiniEmailTransport miniEmailTransport in allEmailTransports)
                {
                    if (miniEmailTransport.IsPop3 || miniEmailTransport.IsImap4)
                    {
                        MiniEmailTransport miniEmailTransport2 = miniEmailTransport;
                        TopologyServerInfo topologyServerInfo2;
                        if (all.Servers.TryGetValue(miniEmailTransport2.Server.DistinguishedName, out topologyServerInfo2))
                        {
                            bool          flag          = miniEmailTransport2.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2010);
                            ServerVersion serverVersion = new ServerVersion(topologyServerInfo2.VersionNumber);
                            flag |= (VariantConfiguration.InvariantNoFlightingSnapshot.DataStorage.CheckR3Coexistence.Enabled && serverVersion.Major == Server.Exchange2009MajorVersion && serverVersion.Build == 482);
                            if ((miniEmailTransport2.InternalConnectionSettings != null && miniEmailTransport2.InternalConnectionSettings.Count > 0) || flag)
                            {
                                this.AddEmailTransportServiceToDictionaries(fqdn, serviceLists, topologyServerInfo2, miniEmailTransport2, ClientAccessType.Internal, AuthenticationMethod.None);
                            }
                            if ((miniEmailTransport2.ExternalConnectionSettings != null && miniEmailTransport2.ExternalConnectionSettings.Count > 0) || flag)
                            {
                                this.AddEmailTransportServiceToDictionaries(fqdn, serviceLists, topologyServerInfo2, miniEmailTransport2, ClientAccessType.External, AuthenticationMethod.None);
                            }
                        }
                    }
                }
            }
            ReadOnlyCollection <MiniReceiveConnector> allSmtpReceiveConnectors = topology.AllSmtpReceiveConnectors;

            if (allSmtpReceiveConnectors != null)
            {
                foreach (MiniReceiveConnector miniReceiveConnector in allSmtpReceiveConnectors)
                {
                    TopologyServerInfo serverInfo2;
                    if (all.Servers.TryGetValue(miniReceiveConnector.Server.DistinguishedName, out serverInfo2))
                    {
                        this.AddSmtpServiceToDictionaries(fqdn, serviceLists, serverInfo2, miniReceiveConnector, ClientAccessType.External);
                        this.AddSmtpServiceToDictionaries(fqdn, serviceLists, serverInfo2, miniReceiveConnector, ClientAccessType.Internal);
                    }
                }
            }
            Dictionary <string, Site> dictionary4 = new Dictionary <string, Site>(topology.AllTopologySites.Count, StringComparer.OrdinalIgnoreCase);

            foreach (TopologySite topologySite in topology.AllTopologySites)
            {
                dictionary4[topologySite.DistinguishedName] = Site.Get(topologySite, all);
            }
            this.localServerInfo        = TopologyServerInfo.Get(topology.LocalServer, all);
            this.serverToSiteDictionary = dictionary2;
            this.services                 = serviceLists;
            this.cafeServices             = serviceLists2;
            this.serversWithoutSite       = list;
            this.siteToServersDictionary  = dictionary3;
            this.siteDictionary           = dictionary4;
            this.serverFqdnDictionary     = dictionary;
            this.connectionCostCalculator = new ConnectionCostCalculator(topology.AllTopologySites.Count);
        }