public ExternalSearchService(IAppConfiguration config, IDiagnosticsService diagnostics)
        {
            ServiceUri = config.ServiceDiscoveryUri;

            Trace = diagnostics.SafeGetSource("ExternalSearchService");

            // Extract credentials
            var userInfo = ServiceUri.UserInfo;
            ICredentials credentials = null;
            if (!String.IsNullOrEmpty(userInfo))
            {
                var split = userInfo.Split(':');
                if (split.Length != 2)
                {
                    throw new FormatException("Invalid user info in SearchServiceUri!");
                }

                // Split the credentials out
                credentials = new NetworkCredential(split[0], split[1]);
                ServiceUri = new UriBuilder(ServiceUri)
                {
                    UserName = null,
                    Password = null
                }.Uri;
            }

            if (_healthIndicatorStore == null)
            {
                _healthIndicatorStore = new BaseUrlHealthIndicatorStore(new AppInsightsHealthIndicatorLogger());
            }

            _client = new SearchClient(ServiceUri, config.SearchServiceResourceType, credentials, _healthIndicatorStore, new TracingHttpHandler(Trace));
        }
Example #2
0
        public ExternalSearchService(IAppConfiguration config, IDiagnosticsService diagnostics)
        {
            ServiceUri = config.ServiceDiscoveryUri;

            Trace = diagnostics.SafeGetSource("ExternalSearchService");

            // Extract credentials
            var          userInfo    = ServiceUri.UserInfo;
            ICredentials credentials = null;

            if (!String.IsNullOrEmpty(userInfo))
            {
                var split = userInfo.Split(':');
                if (split.Length != 2)
                {
                    throw new FormatException("Invalid user info in SearchServiceUri!");
                }

                // Split the credentials out
                credentials = new NetworkCredential(split[0], split[1]);
                ServiceUri  = new UriBuilder(ServiceUri)
                {
                    UserName = null,
                    Password = null
                }.Uri;
            }

            if (_healthIndicatorStore == null)
            {
                _healthIndicatorStore = new BaseUrlHealthIndicatorStore(new AppInsightsHealthIndicatorLogger());
            }

            _client = new SearchClient(ServiceUri, config.SearchServiceResourceType, credentials, _healthIndicatorStore, new TracingHttpHandler(Trace));
        }
 public ExternalSearchService()
 {
     // used for testing
     if (_healthIndicatorStore == null)
     {
         _healthIndicatorStore = new BaseUrlHealthIndicatorStore(new NullHealthIndicatorLogger());
     }
     if (_client == null)
     {
         _client = new SearchClient(ServiceUri, "SearchGalleryQueryService/3.0.0-rc", null, _healthIndicatorStore, new TracingHttpHandler(Trace));
     }
 }
        public ExternalSearchService()
        {
            // used for testing
            if (_healthIndicatorStore == null)
            {
                _healthIndicatorStore = new BaseUrlHealthIndicatorStore(new NullHealthIndicatorLogger());
            }

            if (_client == null)
            {
                _client = new SearchClient(ServiceUri, "SearchGalleryQueryService/3.0.0-rc", null, _healthIndicatorStore, new TracingHttpHandler(Trace), new CorrelatingHttpClientHandler());
            }
        }
Example #5
0
        public ExternalSearchService(IAppConfiguration config, IDiagnosticsService diagnostics, ISearchClient searchClient, IFeatureFlagService featureFlagService)
        {
            ServiceUri          = config.ServiceDiscoveryUri;
            _searchClient       = searchClient ?? throw new ArgumentNullException(nameof(searchClient));
            _featureFlagService = featureFlagService ?? throw new ArgumentNullException(nameof(featureFlagService));

            Trace = diagnostics.SafeGetSource("ExternalSearchService");

            // Extract credentials
            var          userInfo    = ServiceUri.UserInfo;
            ICredentials credentials = null;

            if (!String.IsNullOrEmpty(userInfo))
            {
                var split = userInfo.Split(':');
                if (split.Length != 2)
                {
                    throw new FormatException("Invalid user info in SearchServiceUri!");
                }

                // Split the credentials out
                credentials = new NetworkCredential(split[0], split[1]);
                ServiceUri  = new UriBuilder(ServiceUri)
                {
                    UserName = null,
                    Password = null
                }.Uri;
            }

            // note: intentionally not locking the next two assignments to avoid blocking calls
            if (_healthIndicatorStore == null)
            {
                _healthIndicatorStore = new BaseUrlHealthIndicatorStore(new AppInsightsHealthIndicatorLogger());
            }

            if (_deprecatedSearchClient == null)
            {
                _deprecatedSearchClient = new SearchClient(
                    ServiceUri,
                    config.SearchServiceResourceType,
                    credentials,
                    _healthIndicatorStore,
                    QuietLog.LogHandledException,
                    new TracingHttpHandler(Trace),
                    new CorrelatingHttpClientHandler());
            }
        }
Example #6
0
        public ExternalSearchService()
        {
            // used for testing
            if (_healthIndicatorStore == null)
            {
                _healthIndicatorStore = new BaseUrlHealthIndicatorStore(new NullHealthIndicatorLogger());
            }

            if (_deprecatedSearchClient == null)
            {
                _deprecatedSearchClient = new SearchClient(
                    ServiceUri,
                    "SearchGalleryQueryService/3.0.0-rc",
                    null,
                    _healthIndicatorStore,
                    QuietLog.LogHandledException,
                    new TracingHttpHandler(Trace),
                    new CorrelatingHttpClientHandler());
            }
        }
Example #7
0
        /// <summary>
        /// Create a search service client from the specified base uri and credentials.
        /// </summary>
        /// <param name="baseUri">The URL to the root of the service</param>
        /// <param name="resourceType">Resource type to query against</param>
        /// <param name="credentials">The credentials to connect to the service with</param>
        /// <param name="healthIndicatorStore">Health indicator store</param>
        /// <param name="handlers">Handlers to apply to the request in order from first to last</param>
        public SearchClient(Uri baseUri, string resourceType, ICredentials credentials, IEndpointHealthIndicatorStore healthIndicatorStore, params DelegatingHandler[] handlers)
        {
            _resourceType = resourceType;

            // Link the handlers
            HttpMessageHandler handler = new HttpClientHandler()
            {
                Credentials = credentials,
                AllowAutoRedirect = true,
                UseDefaultCredentials = credentials == null
            };

            foreach (var providedHandler in handlers.Reverse())
            {
                providedHandler.InnerHandler = handler;
                handler = providedHandler;
            }

            var httpClient = new HttpClient(handler, disposeHandler: true);

            _retryingHttpClientWrapper = new RetryingHttpClientWrapper(httpClient, healthIndicatorStore);
            _discoveryClient = new ServiceDiscoveryClient(httpClient, baseUri);
        }
Example #8
0
 public RetryingHttpClientWrapper(HttpClient httpClient, IEndpointHealthIndicatorStore endpointHealthIndicatorStore)
 {
     _httpClient = httpClient;
     _endpointHealthIndicatorStore = endpointHealthIndicatorStore;
 }
Example #9
0
        /// <summary>
        /// Create a search service client from the specified base uri and credentials.
        /// </summary>
        /// <param name="baseUri">The URL to the root of the service</param>
        /// <param name="resourceType">Resource type to query against</param>
        /// <param name="credentials">The credentials to connect to the service with</param>
        /// <param name="healthIndicatorStore">Health indicator store</param>
        /// <param name="handlers">Handlers to apply to the request in order from first to last</param>
        public SearchClient(Uri baseUri, string resourceType, ICredentials credentials, IEndpointHealthIndicatorStore healthIndicatorStore, Action <Exception> onException, params DelegatingHandler[] handlers)
        {
            _resourceType = resourceType;

            // Link the handlers
            HttpMessageHandler handler = new HttpClientHandler()
            {
                Credentials           = credentials,
                AllowAutoRedirect     = true,
                UseDefaultCredentials = credentials == null
            };

            foreach (var providedHandler in handlers.Reverse())
            {
                providedHandler.InnerHandler = handler;
                handler = providedHandler;
            }

            _httpClient = new HttpClient(handler, disposeHandler: true);

            _retryingHttpClientWrapper = new RetryingHttpClientWrapper(_httpClient, healthIndicatorStore, onException);
            _discoveryClient           = new ServiceDiscoveryClient(_httpClient, baseUri);
        }
Example #10
0
 public RetryingHttpClientWrapper(HttpClient httpClient, IEndpointHealthIndicatorStore endpointHealthIndicatorStore, Action <Exception> onException)
 {
     _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
     _endpointHealthIndicatorStore = endpointHealthIndicatorStore ?? throw new ArgumentNullException(nameof(endpointHealthIndicatorStore));
     _onException = onException ?? throw new ArgumentNullException(nameof(onException));
 }