Exemplo n.º 1
0
        public static Task FlushBucketAsync(this IBucketManager bucketManager, string bucketName, Action <FlushBucketOptions> configureOptions)
        {
            var options = new FlushBucketOptions();

            configureOptions(options);

            return(bucketManager.FlushBucketAsync(bucketName, options));
        }
Exemplo n.º 2
0
        public async Task FlushBucketAsync(string bucketName, FlushBucketOptions options = null)
        {
            options = options ?? new FlushBucketOptions();
            // get uri and amend path to flush endpoint
            var builder = new UriBuilder(GetUri(bucketName));

            builder.Path = Path.Combine(builder.Path, "controller/doFlush");
            var uri = builder.Uri;

            Logger.LogInformation($"Attempting to flush bucket with name {bucketName} - {uri}");

            try
            {
                // try do flush
                var result = await _client.PostAsync(uri, null, options.CancellationToken).ConfigureAwait(false);

                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new BucketNotFoundException(bucketName);
                }

                if (result.StatusCode == HttpStatusCode.BadRequest)
                {
                    var json = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

                    if (json.IndexOf("Flush is disabled for the bucket", StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        throw new BucketIsNotFlushableException(bucketName);
                    }
                }

                result.EnsureSuccessStatusCode();
            }
            catch (BucketNotFoundException)
            {
                Logger.LogError($"Unable to flush bucket with name {bucketName} because it does not exist");
                throw;
            }
            catch (BucketIsNotFlushableException)
            {
                Logger.LogError($"Failed to flush bucket with name {bucketName} because it is not flushable");
                throw;
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to flush bucket with name {bucketName}");
                throw;
            }
        }