コード例 #1
0
        public async Task DropCollectionAsync(CollectionSpec spec, DropCollectionOptions options)
        {
            var uri = GetUri(spec.ScopeName, spec.Name);

            Logger.LogInformation($"Attempting drop collection {spec.ScopeName}/{spec.Name} - {uri}");

            try
            {
                // check collection exists
                var collectionExists =
                    await CollectionExistsAsync(spec, new CollectionExistsOptions { CancellationToken = options.CancellationToken })
                    .ConfigureAwait(false);

                if (!collectionExists)
                {
                    throw new CollectionNotFoundException(spec.ScopeName, spec.Name);
                }

                // drop collection
                var createResult = await _client.DeleteAsync(uri, options.CancellationToken).ConfigureAwait(false);

                createResult.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to drop collection {spec.ScopeName}/{spec.Name} - {uri}");
                throw;
            }
        }
コード例 #2
0
        public async Task CreateCollectionAsync(CollectionSpec spec, CreateCollectionOptions?options = null)
        {
            options ??= CreateCollectionOptions.Default;
            var uri = GetUri(spec.ScopeName);

            _logger.LogInformation("Attempting create collection {spec.ScopeName}/{spec.Name} - {uri}", spec.ScopeName,
                                   spec.Name, _redactor.SystemData(uri));

            try
            {
                // create collection
                var keys = new Dictionary <string, string>
                {
                    { "name", spec.Name }
                };

                if (spec.MaxExpiry.HasValue)
                {
                    keys.Add("maxTTL", spec.MaxExpiry.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                }
                var content      = new FormUrlEncodedContent(keys);
                var createResult = await _client.PostAsync(uri, content, options.TokenValue).ConfigureAwait(false);

                createResult.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Failed to create collection {spec.ScopeName}/{spec.Name} - {uri}", spec.ScopeName,
                                 spec.Name, _redactor.SystemData(uri));
                throw;
            }
        }
コード例 #3
0
        public async Task <bool> CollectionExistsAsync(CollectionSpec spec, CollectionExistsOptions?options = null)
        {
            options ??= CollectionExistsOptions.Default;
            var uri = GetUri();

            _logger.LogInformation($"Attempting to verify if scope/collection {spec.ScopeName}/{spec.Name} exists - {uri}");

            try
            {
                // get all scopes
                var scopes =
                    await GetAllScopesAsync(new GetAllScopesOptions().CancellationToken(options.TokenValue))
                    .ConfigureAwait(false);

                // try find scope / collection
                return(scopes.Any(scope =>
                                  scope.Name == spec.ScopeName && scope.Collections.Any(collection => collection.Name == spec.Name)
                                  ));
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, $"Failed to verify if collection {spec.ScopeName}/{spec.Name} exists - {uri}");
                throw;
            }
        }
コード例 #4
0
        public async Task CreateCollectionAsync(CollectionSpec spec, CreateCollectionOptions?options = null)
        {
            options ??= CreateCollectionOptions.Default;
            var uri = GetUri(spec.ScopeName);

            _logger.LogInformation($"Attempting create collection {spec.ScopeName}/{spec.Name} - {uri}");

            try
            {
                // create collection
                var keys = new Dictionary <string, string>
                {
                    { "name", spec.Name }
                };
                var content      = new FormUrlEncodedContent(keys);
                var createResult = await _client.PostAsync(uri, content, options.TokenValue).ConfigureAwait(false);

                createResult.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, $"Failed to create collection {spec.ScopeName}/{spec.Name} - {uri}");
                throw;
            }
        }
コード例 #5
0
        public async Task DropCollectionAsync(CollectionSpec spec, DropCollectionOptions?options = null)
        {
            options ??= DropCollectionOptions.Default;
            var uri = GetUri(RestApi.DeleteCollections(_bucketName, spec.ScopeName, spec.Name));

            _logger.LogInformation("Attempting drop collection {spec.ScopeName}/{spec.Name} - {uri}", spec.ScopeName,
                                   spec.Name, _redactor.SystemData(uri));

            try
            {
                // drop collection
                var createResult = await _client.DeleteAsync(uri, options.TokenValue).ConfigureAwait(false);

                if (createResult.StatusCode != HttpStatusCode.OK)
                {
                    var contentBody = await createResult.Content.ReadAsStringAsync();

                    if (contentBody.Contains("collection_not_found"))
                    {
                        throw new CollectionNotFoundException(spec.ScopeName, spec.Name);
                    }
                    throw new CouchbaseException(contentBody);
                }
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Failed to drop collection {spec.ScopeName}/{spec.Name} - {uri}", spec.ScopeName,
                                 spec.Name, _redactor.SystemData(uri));
                throw;
            }
        }
コード例 #6
0
        public static Task DropCollectionAsync(this ICollectionManager manager, CollectionSpec spec, Action <DropCollectionOptions> configureOptions)
        {
            var options = new DropCollectionOptions();

            configureOptions(options);

            return(manager.DropCollectionAsync(spec, options));
        }
コード例 #7
0
        public async Task CreateCollectionAsync(CollectionSpec spec, CreateCollectionOptions?options = null)
        {
            options ??= CreateCollectionOptions.Default;
            var uri = GetUri(RestApi.CreateCollections(_bucketName, spec.ScopeName));

            _logger.LogInformation("Attempting create collection {spec.ScopeName}/{spec.Name} - {uri}", spec.ScopeName,
                                   spec.Name, _redactor.SystemData(uri));

            try
            {
                // create collection
                var keys = new Dictionary <string, string>
                {
                    { "name", spec.Name }
                };

                if (spec.MaxExpiry.HasValue)
                {
                    keys.Add("maxTTL", spec.MaxExpiry.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                }
                var content      = new FormUrlEncodedContent(keys);
                var createResult = await _client.PostAsync(uri, content, options.TokenValue).ConfigureAwait(false);

                if (createResult.StatusCode != HttpStatusCode.OK)
                {
                    var contentBody = await createResult.Content.ReadAsStringAsync();

                    if (contentBody.Contains("already exists"))
                    {
                        throw new CollectionExistsException(spec.ScopeName, spec.Name);
                    }

                    if (contentBody.Contains("not found"))
                    {
                        throw new ScopeNotFoundException(spec.ScopeName);
                    }

                    throw new CouchbaseException(contentBody);
                }
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Failed to create collection {spec.ScopeName}/{spec.Name} - {uri}", spec.ScopeName,
                                 spec.Name, _redactor.SystemData(uri));
                throw;
            }
        }
コード例 #8
0
        public async Task CreateCollectionAsync(CollectionSpec spec, CreateCollectionOptions options = null)
        {
            options = options ?? CreateCollectionOptions.Default;
            var uri = GetUri(spec.ScopeName);

            Logger.LogInformation($"Attempting create collection {spec.ScopeName}/{spec.Name} - {uri}");

            try
            {
                // check scope exists
                var scopeExists =
                    await ScopeExistsAsync(spec.ScopeName, new ScopeExistsOptions { CancellationToken = options.CancellationToken })
                    .ConfigureAwait(false);

                if (!scopeExists)
                {
                    throw new ScopeNotFoundException(spec.ScopeName);
                }

                // check collection doesn't exist
                var collectionExists =
                    await CollectionExistsAsync(spec, new CollectionExistsOptions { CancellationToken = options.CancellationToken })
                    .ConfigureAwait(false);

                if (collectionExists)
                {
                    throw new CollectionExistsException(spec.ScopeName, spec.Name);
                }

                // create collection
                var keys = new Dictionary <string, string>
                {
                    { "name", spec.Name }
                };
                var content      = new FormUrlEncodedContent(keys);
                var createResult = await _client.PostAsync(uri, content, options.CancellationToken).ConfigureAwait(false);

                createResult.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to create collection {spec.ScopeName}/{spec.Name} - {uri}");
                throw;
            }
        }
コード例 #9
0
        public async Task DropCollectionAsync(CollectionSpec spec, DropCollectionOptions?options = null)
        {
            options ??= DropCollectionOptions.Default;
            var uri = GetUri(spec.ScopeName, spec.Name);

            _logger.LogInformation($"Attempting drop collection {spec.ScopeName}/{spec.Name} - {uri}");

            try
            {
                // drop collection
                var createResult = await _client.DeleteAsync(uri, options.TokenValue).ConfigureAwait(false);

                createResult.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, $"Failed to drop collection {spec.ScopeName}/{spec.Name} - {uri}");
                throw;
            }
        }
コード例 #10
0
 public static Task DropCollectionAsync(this ICollectionManager manager, CollectionSpec spec)
 {
     return(manager.DropCollectionAsync(spec, DropCollectionOptions.Default));
 }
コード例 #11
0
        public static Task <bool> CollectionExistsAsync(this ICollectionManager manager, CollectionSpec spec, Action <CollectionExistsOptions> configureOptions)
        {
            var options = new CollectionExistsOptions();

            configureOptions(options);

            return(manager.CollectionExistsAsync(spec, options));
        }
コード例 #12
0
 public static Task <bool> CollectionExistsAsync(this ICollectionManager manager, CollectionSpec spec)
 {
     return(manager.CollectionExistsAsync(spec, CollectionExistsOptions.Default));
 }
コード例 #13
0
 public static Task CreateCollectionAsync(this ICollectionManager manager, CollectionSpec spec)
 {
     return(manager.CreateCollectionAsync(spec, CreateCollectionOptions.Default));
 }
コード例 #14
0
        public static Task CreateCollectionAsync(this ICouchbaseCollectionManager manager, CollectionSpec spec, Action <CreateCollectionOptions> configureOptions)
        {
            var options = new CreateCollectionOptions();

            configureOptions(options);

            return(manager.CreateCollectionAsync(spec, options));
        }