Пример #1
0
        public static string DiscoverEwsUrl(IExchangePrincipal mailbox)
        {
            Uri uri;

            if (!EwsHelper.IsDatacenter)
            {
                EwsHelper.Tracer.TraceDebug(0L, "Not running in DC. Will use ServiceTopology to discover the url");
                ServerVersion mailboxVersion = new ServerVersion(mailbox.MailboxInfo.Location.ServerVersion);
                IList <WebServicesService> list;
                try
                {
                    ClientAccessType clientAccessType = EwsHelper.ClientAccessType;
                    EwsHelper.Tracer.TraceDebug <ClientAccessType>(0L, "Will try to discover the URL for EWS with the following client access type: {0}", clientAccessType);
                    ServiceTopology currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Management\\EwsDriver\\EwsHelper.cs", "DiscoverEwsUrl", 119);
                    list = currentServiceTopology.FindAll <WebServicesService>(mailbox, clientAccessType, delegate(WebServicesService service)
                    {
                        ServerVersion serverVersion = new ServerVersion(service.ServerVersionNumber);
                        return(mailboxVersion.Major == serverVersion.Major && mailboxVersion.Minor <= serverVersion.Minor && !service.IsOutOfService);
                    }, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Management\\EwsDriver\\EwsHelper.cs", "DiscoverEwsUrl", 121);
                }
                catch (LocalizedException arg)
                {
                    EwsHelper.Tracer.TraceError <IExchangePrincipal, LocalizedException>(0L, "Unable to discover internal URL for EWS for mailbox {0} due exception {1}", mailbox, arg);
                    return(null);
                }
                if (list.Count == 0)
                {
                    EwsHelper.Tracer.TraceError <IExchangePrincipal>(0L, "Unable to find internal URL for EWS for mailbox {0}", mailbox);
                    return(null);
                }
                WebServicesService webServicesService;
                if ((webServicesService = list.FirstOrDefault((WebServicesService service) => string.Equals(service.ServerFullyQualifiedDomainName, mailbox.MailboxInfo.Location.ServerFqdn, StringComparison.OrdinalIgnoreCase) && service.Url != null)) == null && (webServicesService = list.FirstOrDefault(delegate(WebServicesService service)
                {
                    ServerVersion serverVersion = new ServerVersion(service.ServerVersionNumber);
                    return(service.Url != null && mailboxVersion.Major == serverVersion.Major && mailboxVersion.Minor == serverVersion.Minor);
                })) == null)
                {
                    webServicesService = list.FirstOrDefault((WebServicesService service) => service.Url != null);
                }
                WebServicesService webServicesService2 = webServicesService;
                uri = ((webServicesService2 == null) ? null : webServicesService2.Url);
                goto IL_1EA;
            }
            EwsHelper.Tracer.TraceDebug(0L, "Running in DC. Will use BackEndLocator to discover the url");
            if (EwsHelper.discoveryEwsInternalUrl == null)
            {
                EwsHelper.discoveryEwsInternalUrl = (Func <IMailboxInfo, Uri>)Delegate.CreateDelegate(typeof(Func <IMailboxInfo, Uri>), Type.GetType("Microsoft.Exchange.Data.ApplicationLogic.Cafe.BackEndLocator, Microsoft.Exchange.Data.ApplicationLogic").GetMethod("GetBackEndWebServicesUrl", BindingFlags.Static | BindingFlags.Public, null, new Type[]
                {
                    typeof(IMailboxInfo)
                }, null));
            }
            uri = EwsHelper.discoveryEwsInternalUrl(mailbox.MailboxInfo);
IL_1EA:
            if (!(uri == null))
            {
                return(uri.ToString());
            }
            return(null);
        }
Пример #2
0
        public Uri GetCasServerUri(ADObjectId site, int minServerVersionRequested, out int serverVersion)
        {
            SortedDictionary <int, List <WebServicesService> > uriVersions = null;

            serverVersion = 0;
            try
            {
                ServiceTopology currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\MessageTracking\\ServerCache.cs", "GetCasServerUri", 673);
                currentServiceTopology.ForEach <WebServicesService>(delegate(WebServicesService service)
                {
                    if (service.ServerVersionNumber >= minServerVersionRequested && service.Site.Id.Equals(site) && service.ClientAccessType == ClientAccessType.InternalNLBBypass)
                    {
                        if (uriVersions == null)
                        {
                            uriVersions = new SortedDictionary <int, List <WebServicesService> >();
                        }
                        int key2 = service.ServerVersionNumber >> 16;
                        if (!uriVersions.ContainsKey(key2))
                        {
                            uriVersions[key2] = new List <WebServicesService>();
                        }
                        uriVersions[key2].Add(service);
                    }
                }, "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\MessageTracking\\ServerCache.cs", "GetCasServerUri", 674);
            }
            catch (ServiceDiscoveryTransientException ex)
            {
                TraceWrapper.SearchLibraryTracer.TraceError <ServiceDiscoveryTransientException>(this.GetHashCode(), "Transient exception getting Internal CAS URI: {0}", ex);
                TrackingTransientException.RaiseETX(ErrorCode.CASUriDiscoveryFailure, site.ToString(), ex.ToString());
            }
            catch (ServiceDiscoveryPermanentException ex2)
            {
                TraceWrapper.SearchLibraryTracer.TraceError <ServiceDiscoveryPermanentException>(this.GetHashCode(), "Permanent exception getting Internal CAS URI: {0}", ex2);
                TrackingFatalException.RaiseETX(ErrorCode.CASUriDiscoveryFailure, site.ToString(), ex2.ToString());
            }
            if (uriVersions != null && uriVersions.Count > 0)
            {
                int key = uriVersions.Last <KeyValuePair <int, List <WebServicesService> > >().Key;
                List <WebServicesService> value = uriVersions.Last <KeyValuePair <int, List <WebServicesService> > >().Value;
                int index = ServerCache.rand.Next(value.Count);
                WebServicesService webServicesService = value.ElementAt(index);
                TraceWrapper.SearchLibraryTracer.TraceDebug <Uri, string>(this.GetHashCode(), "Using CAS URI: {0}, Version {1}", webServicesService.Url, new ServerVersion(webServicesService.ServerVersionNumber).ToString());
                serverVersion = webServicesService.ServerVersionNumber;
                return(webServicesService.Url);
            }
            TraceWrapper.SearchLibraryTracer.TraceError <string, string>(this.GetHashCode(), "Failed to find any CAS server in site: {0}, with min version {1}", site.ToString(), new ServerVersion(minServerVersionRequested).ToString());
            return(null);
        }