public T FindAnyCafeService <T>(Predicate <T> serviceFilter, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string memberName = null, [CallerLineNumber] int callerFileLine = 0) where T : Service { Func <Service, T> func = null; ServiceTopologyLog.Instance.Append(callerFilePath, memberName, callerFileLine); if (serviceFilter == null) { throw new ArgumentNullException("serviceFilter"); } ServiceType serviceType = ServiceTopology.ServiceTypeMapper <T> .GetServiceType(); List <Service> list = null; if (this.cafeServices.TryGetValue(serviceType, out list) && list != null && list.Count > 0) { IEnumerable <Service> source = from service in list where serviceFilter((T)((object)service)) select service; if (func == null) { func = ((Service service) => (T)((object)service)); } List <T> list2 = source.Select(func).ToList <T>(); if (list2.Count > 0) { int index = ServiceTopology.Random.Next(list2.Count); return(list2[index]); } } ServiceCache.TriggerCacheRefreshDueToCacheMiss(this); return(default(T)); }
public Site GetSite(string serverFullyQualifiedDomainName, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string memberName = null, [CallerLineNumber] int callerFileLine = 0) { ServiceTopologyLog.Instance.Append(callerFilePath, memberName, callerFileLine); Site result; if (this.serverToSiteDictionary.TryGetValue(serverFullyQualifiedDomainName, out result)) { return(result); } if (this.serversWithoutSite.Contains(serverFullyQualifiedDomainName)) { ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug <string>((long)this.GetHashCode(), "ServiceTopology::FindServices. The server does not have a site defined. Server = {0}.", serverFullyQualifiedDomainName); throw new ServerNotInSiteException(ServerStrings.ExServerNotInSite(serverFullyQualifiedDomainName), serverFullyQualifiedDomainName); } ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug <string>((long)this.GetHashCode(), "ServiceTopology::FindServices. The server we are accessing is not found in the Topology. Server = {0}.", serverFullyQualifiedDomainName); ServiceCache.TriggerCacheRefreshDueToCacheMiss(this); throw new ServerNotFoundException(ServerStrings.ExServerNotFound(serverFullyQualifiedDomainName), serverFullyQualifiedDomainName); }