Exemplo n.º 1
0
        public static Task CreateAsync(this IBucketManager bucketManager, BucketSettings settings, Action <CreateBucketOptions> configureOptions)
        {
            var options = new CreateBucketOptions();

            configureOptions(options);

            return(bucketManager.CreateAsync(settings, options));
        }
Exemplo n.º 2
0
        public async Task CreateAsync(BucketSettings settings, CreateBucketOptions options)
        {
            var uri = GetUri();

            Logger.LogInformation($"Attempting to create bucket with name {settings.Name} - {uri}");

            try
            {
                // check if bucket already exists, throw BucketAlreadyExistsException if it does
                await GetAsync(settings.Name, GetBucketOptions.Default).ConfigureAwait(false);

                throw new BucketAlreadyExistsException(settings.Name);
            }
            catch (BucketNotFoundException)
            {
                // expected
            }

            try
            {
                // create bucket
                var content = new FormUrlEncodedContent(GetBucketSettingAsFormValues(settings));
                var result  = await _client.PostAsync(uri, content, options.CancellationToken).ConfigureAwait(false);

                result.EnsureSuccessStatusCode();
            }
            catch (BucketAlreadyExistsException)
            {
                Logger.LogError($"Failed to create bucket with name {settings.Name} because it already exists");
                throw;
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to create bucket with name {settings.Name} - {uri}");
                throw;
            }
        }