Esempio n. 1
0
        public static Task DisallowQueryingAsync(this ISearchIndexManager manager, string indexName, Action <DisallowQueryingSearchIndexOptions> configureOptions)
        {
            var options = new DisallowQueryingSearchIndexOptions();

            configureOptions(options);

            return(manager.DisallowQueryingAsync(indexName, options));
        }
        public async Task DisallowQueryingAsync(string indexName, DisallowQueryingSearchIndexOptions options)
        {
            var baseUri = GetQueryControlUri(indexName, false);

            Logger.LogInformation($"Trying to disallow querying for index with name {indexName} - {baseUri}");

            try
            {
                var result = await _client.PostAsync(baseUri, null, options.CancellationToken).ConfigureAwait(false);

                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new SearchIndexNotFound(indexName);
                }

                result.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to disallow querying for index with name {indexName} - {baseUri}");
                throw;
            }
        }