private AnchorMailbox GetE14CASServer(OABCache.OABCacheEntry oab) { ServiceTopology serviceTopology = ServiceTopology.GetCurrentLegacyServiceTopology("f:\\15.00.1497\\sources\\dev\\cafe\\src\\HttpProxy\\RequestHandlers\\OabProxyRequestHandler.cs", "GetE14CASServer", 287); Site currentSite = HttpProxyGlobals.LocalSite.Member; List <OabService> cheapestCASServers = new List <OabService>(); int cheapestSiteConnectionCost = int.MaxValue; OabProxyRequestHandler.IsEligibleOabService isEligibleOabServiceDelegate = null; if (oab.GlobalWebDistributionEnabled) { isEligibleOabServiceDelegate = new OabProxyRequestHandler.IsEligibleOabService(this.IsEligibleOabServiceBasedOnVersion); } else { if (oab.VirtualDirectories == null || oab.VirtualDirectories.Count <= 0) { ExTraceGlobals.VerboseTracer.TraceError(0L, "[OabProxyRequestHandler::ResolveAnchorMailbox] The OAB is distributed neither globally nor to named vdirs; there is no way to retrieve it"); throw new HttpProxyException(HttpStatusCode.InternalServerError, HttpProxySubErrorCode.ServerNotFound, "The OAB is distributed neither globally nor to named vdirs; there is no way to retrieve it"); } isEligibleOabServiceDelegate = new OabProxyRequestHandler.IsEligibleOabService(this.IsEligibleOabServiceBasedOnVersionAndVirtualDirectory); } serviceTopology.ForEach <OabService>(delegate(OabService oabService) { if (isEligibleOabServiceDelegate(oabService, oab)) { int maxValue = int.MaxValue; if (currentSite != null && oabService.Site != null) { serviceTopology.TryGetConnectionCost(currentSite, oabService.Site, out maxValue, "f:\\15.00.1497\\sources\\dev\\cafe\\src\\HttpProxy\\RequestHandlers\\OabProxyRequestHandler.cs", "GetE14CASServer", 325); } if (maxValue == cheapestSiteConnectionCost) { cheapestCASServers.Add(oabService); return; } if (maxValue < cheapestSiteConnectionCost) { cheapestCASServers.Clear(); cheapestCASServers.Add(oabService); cheapestSiteConnectionCost = maxValue; } } }, "f:\\15.00.1497\\sources\\dev\\cafe\\src\\HttpProxy\\RequestHandlers\\OabProxyRequestHandler.cs", "GetE14CASServer", 316); if (cheapestCASServers.Count == 0) { ExTraceGlobals.VerboseTracer.TraceError(0L, "[OabProxyRequestHandler::ResolveAnchorMailbox] Could not find a valid downlevel CAS server for this OAB"); throw new HttpProxyException(HttpStatusCode.InternalServerError, HttpProxySubErrorCode.ServerNotFound, "Could not find a valid downlevel CAS server for this OAB"); } OabService oabService2; if (cheapestCASServers.Count == 1) { oabService2 = cheapestCASServers[0]; } else { oabService2 = cheapestCASServers[OabProxyRequestHandler.RandomNumberGenerator.Next(cheapestCASServers.Count)]; } BackEndServer backendServer = new BackEndServer(oabService2.ServerFullyQualifiedDomainName, oabService2.ServerVersionNumber); return(new ServerInfoAnchorMailbox(backendServer, this)); }
private static ADUser GetOrganizationMailboxInClosestSite(IRecipientSession recipientSession, OrganizationCapability capability) { if (recipientSession == null) { throw new ArgumentNullException("recipientSession"); } List <ADUser> organizationMailboxesByCapability = OrganizationMailbox.GetOrganizationMailboxesByCapability(recipientSession, capability); if (organizationMailboxesByCapability == null || organizationMailboxesByCapability.Count == 0) { ExTraceGlobals.CafeTracer.TraceError <OrganizationCapability, OrganizationId>(0L, "[HttpProxyBackEndHelper.GetOrganizationMailbox] Unable to find organization mailbox with capability {0} for organization {1}.", capability, recipientSession.SessionSettings.CurrentOrganizationId); return(null); } ADUser aduser; if (organizationMailboxesByCapability.Count == 1) { aduser = organizationMailboxesByCapability[0]; } else { ServiceTopology currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\HttpProxyBackEndHelper.cs", "GetOrganizationMailboxInClosestSite", 753); Site site = currentServiceTopology.GetSite(LocalServerCache.LocalServerFqdn, "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\HttpProxyBackEndHelper.cs", "GetOrganizationMailboxInClosestSite", 754); List <ADUser> list = new List <ADUser>(5); int num = int.MaxValue; foreach (ADUser aduser2 in organizationMailboxesByCapability) { ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(recipientSession.SessionSettings, aduser2, RemotingOptions.AllowCrossSite); Site site2 = currentServiceTopology.GetSite(exchangePrincipal.MailboxInfo.Location.ServerFqdn, "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\HttpProxyBackEndHelper.cs", "GetOrganizationMailboxInClosestSite", 761); if (list.Count == 0) { list.Add(aduser2); currentServiceTopology.TryGetConnectionCost(site, site2, out num, "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\HttpProxyBackEndHelper.cs", "GetOrganizationMailboxInClosestSite", 768); } else { int maxValue = int.MaxValue; currentServiceTopology.TryGetConnectionCost(site, site2, out maxValue, "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\Cafe\\HttpProxyBackEndHelper.cs", "GetOrganizationMailboxInClosestSite", 773); if (maxValue == num) { list.Add(aduser2); } else if (maxValue < num) { list.Clear(); list.Add(aduser2); num = maxValue; } } } if (list.Count == 1) { aduser = list[0]; } else { aduser = list[HttpProxyBackEndHelper.random.Next(list.Count)]; } } ExTraceGlobals.CafeTracer.TraceDebug <ObjectId, OrganizationCapability, OrganizationId>(0L, "[HttpProxyBackEndHelper.GetOrganizationMailbox] Find organization mailbox {0} with capability {1} for organization {2}.", aduser.Identity, capability, recipientSession.SessionSettings.CurrentOrganizationId); return(aduser); }