Ejemplo n.º 1
0
        private async Task CreateBucketAsync()
        {
            _logger.LogInformation("Attempting to create bucket...");
            var bucketManager  = _cluster.Buckets;
            var bucketSettings = new BucketSettings
            {
                BucketType = BucketType.Couchbase,
                Name       = _config.TargetBucket,
                RamQuotaMB = _config.TargetBucketRamQuotaMB
            };

            _logger.LogInformation($"Creating bucket `{_config.TargetBucket}`...");
            try
            {
                await bucketManager.CreateBucketAsync(bucketSettings);

                _logger.LogInformation("Bucket creation complete.");
            }
            catch (BucketExistsException)
            {
                _logger.LogInformation("already exists.");
            }

            _bucket = await _cluster.BucketAsync(_config.TargetBucket);

            var opts = new WaitUntilReadyOptions();

            opts.DesiredState(ClusterState.Online);
            opts.ServiceTypes(ServiceType.KeyValue, ServiceType.Query);
            await _bucket.WaitUntilReadyAsync(TimeSpan.FromSeconds(30), opts);

            _collManager = _bucket.Collections;
        }
        public static Task DropCollectionAsync(this ICouchbaseCollectionManager manager, CollectionSpec spec, Action <DropCollectionOptions> configureOptions)
        {
            var options = new DropCollectionOptions();

            configureOptions(options);

            return(manager.DropCollectionAsync(spec, options));
        }
        public static Task <IEnumerable <ScopeSpec> > GetAllScopesAsync(this ICouchbaseCollectionManager manager, Action <GetAllScopesOptions> configureOptions)
        {
            var options = new GetAllScopesOptions();

            configureOptions(options);

            return(manager.GetAllScopesAsync(options));
        }
        public static Task <ScopeSpec> GetScopeAsync(this ICouchbaseCollectionManager manager, string scopeName, Action <GetScopeOptions> configureOptions)
        {
            var options = new GetScopeOptions();

            configureOptions(options);

            return(manager.GetScopeAsync(scopeName, options));
        }
        public static Task CreateScopeAsync(this ICouchbaseCollectionManager manager, ScopeSpec scopeSpec, Action <CreateScopeOptions> configureOptions)
        {
            var options = new CreateScopeOptions();

            configureOptions(options);

            return(manager.CreateScopeAsync(scopeSpec.Name, options));
        }
Ejemplo n.º 6
0
        public static async Task <ScopeSpec> GetScopeUsingGetAllScopesAsync(this ICouchbaseCollectionManager collectionManager, string scopeName)
        {
            var getAllScopesResult = await collectionManager.GetAllScopesAsync().ConfigureAwait(false);

            var scope = getAllScopesResult.SingleOrDefault(x => x.Name == scopeName);

            return(scope);
        }
        async Task <ICouchbaseCollectionManager> getCollectionManager(String username, String password)
        {
            Console.WriteLine("create-collection-manager");

            // tag::create-collection-manager[]
            ICluster cluster = await Cluster.ConnectAsync("couchbase://localhost", username, password);

            IBucket bucket = await cluster.BucketAsync("travel-sample");

            ICouchbaseCollectionManager collectionMgr = bucket.Collections;

            // end::create-collection-manager[]

            return(collectionMgr);
        }
Ejemplo n.º 8
0
        public async Task ExecuteAsync()
        {
            Console.WriteLine("scopeAdmin");
            {
                // tag::scopeAdmin[]
                ICluster clusterAdmin = await Cluster.ConnectAsync(
                    "couchbase://localhost", "Administrator", "password");

                IUserManager users = clusterAdmin.Users;

                var user = new User("scopeAdmin")
                {
                    Password    = "******",
                    DisplayName = "Manage Scopes [travel-sample:*]",
                    Roles       = new List <Role>()
                    {
                        new Role("scope_admin", "travel-sample"),
                        new Role("data_reader", "travel-sample")
                    }
                };

                await users.UpsertUserAsync(user);

                // end::scopeAdmin[]
            }

            ICluster cluster = await Cluster.ConnectAsync("couchbase://localhost", "scopeAdmin", "password");

            IBucket bucket = await cluster.BucketAsync("travel-sample");

            // tag::create-collection-manager[]
            ICouchbaseCollectionManager collectionMgr = bucket.Collections;
            // end::create-collection-manager[]
            {
                Console.WriteLine("create-scope");
                // tag::create-scope[]
                try {
                    await collectionMgr.CreateScopeAsync("example-scope");
                }
                catch (ScopeExistsException) {
                    Console.WriteLine("The scope already exists");
                }
                // end::create-scope[]
            }
            {
                Console.WriteLine("create-collection");
                // tag::create-collection[]
                var spec = new CollectionSpec("example-scope", "example-collection");

                try {
                    await collectionMgr.CreateCollectionAsync(spec);
                }
                catch (CollectionExistsException) {
                    Console.WriteLine("Collection already exists");
                }
                catch (ScopeNotFoundException) {
                    Console.WriteLine("The specified parent scope doesn't exist");
                }
                // end::create-collection[]

                Console.WriteLine("listing-scope-collection");
                // tag::listing-scope-collection[]
                var scopes = await collectionMgr.GetAllScopesAsync();

                foreach (ScopeSpec scopeSpec in scopes)
                {
                    Console.WriteLine($"Scope: {scopeSpec.Name}");

                    foreach (CollectionSpec collectionSpec in scopeSpec.Collections)
                    {
                        Console.WriteLine($" - {collectionSpec.Name}");
                    }
                }
                // end::listing-scope-collection[]

                Console.WriteLine("drop-collection");
                // tag::drop-collection[]
                try {
                    await collectionMgr.DropCollectionAsync(spec);
                }
                catch (CollectionNotFoundException) {
                    Console.WriteLine("The specified collection doesn't exist");
                }
                catch (ScopeNotFoundException) {
                    Console.WriteLine("The specified parent scope doesn't exist");
                }
                // end::drop-collection[]
            }
            {
                Console.WriteLine("drop-scope");
                // tag::drop-scope[]
                try {
                    await collectionMgr.DropScopeAsync("example-scope");
                }
                catch (ScopeNotFoundException) {
                    Console.WriteLine("The specified scope doesn't exist");
                }
                // end::drop-scope[]
            }
        }
 public static Task DropScopeAsync(this ICouchbaseCollectionManager manager, string scopeName)
 {
     return(manager.DropScopeAsync(scopeName, DropScopeOptions.Default));
 }
 public static Task DropCollectionAsync(this ICouchbaseCollectionManager manager, CollectionSpec spec)
 {
     return(manager.DropCollectionAsync(spec, DropCollectionOptions.Default));
 }
 public static Task <IEnumerable <ScopeSpec> > GetAllScopesAsync(this ICouchbaseCollectionManager manager)
 {
     return(manager.GetAllScopesAsync(GetAllScopesOptions.Default));
 }
 public static Task <ScopeSpec> GetScopeAsync(this ICouchbaseCollectionManager manager, string scopeName)
 {
     return(manager.GetScopeAsync(scopeName, GetScopeOptions.Default));
 }
 public static Task CreateScopeAsync(this ICouchbaseCollectionManager manager, ScopeSpec scopeSpec)
 {
     return(manager.CreateScopeAsync(scopeSpec.Name, CreateScopeOptions.Default));
 }
Ejemplo n.º 14
0
 public static IAsyncDisposable DropScopeOnDispose(ICouchbaseCollectionManager collectionManager, string scopeName, ITestOutputHelper?outputHelper = null)
 {
     return(new DisposeCleanerAsync(() => collectionManager.DropScopeAsync(scopeName), outputHelper));
 }