Example #1
0
        /// <summary>
        /// Check if a private bucket with the given name exists.
        /// </summary>
        /// <param name="args">BucketExistsArgs Arguments Object which has bucket identifier information - bucket name, region</param>
        /// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
        /// <returns> Task </returns>
        public async Task <bool> BucketExistsAsync(BucketExistsArgs args, CancellationToken cancellationToken = default(CancellationToken))
        {
            args.Validate();
            try
            {
                RestRequest request = await this.CreateRequest(Method.HEAD, args.BucketName).ConfigureAwait(false);

                await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
            }
            catch (InternalClientException ice)
            {
                if ((ice.ServerResponse != null && HttpStatusCode.NotFound.Equals(ice.ServerResponse.StatusCode)) ||
                    ice.ServerResponse == null)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(BucketNotFoundException))
                {
                    return(false);
                }
                throw;
            }
            return(true);
        }
Example #2
0
        public async Task <bool> BucketExistsAsync(string bucketName, CancellationToken cancellationToken = default(CancellationToken))
        {
            BucketExistsArgs args = new BucketExistsArgs()
                                    .WithBucket(bucketName);

            return(await BucketExistsAsync(args, cancellationToken));
        }