Exemple #1
0
        public void Init()
        {
            var task = _Client.ReadDocumentCollectionAsync(_CollectionLink, new RequestOptions {
                PopulateQuotaInfo = true
            });

            task.Wait();
            Microsoft.Azure.Documents.DocumentCollection response = task.Result;
            _SizeQuotaInKB = Convert.ToInt32(task.Result.CollectionSizeQuota.ToString());
            _SizeUsageInKB = Convert.ToInt32(task.Result.CollectionSizeUsage.ToString());
        }
Exemple #2
0
        private async Task CreateDocumentCollection(string databaseName, string collectionName)
        {
            // Example of creating a DocumentCollection (not used for this demo)
            using (var client = new Microsoft.Azure.Documents.Client.DocumentClient(new Uri(settings.URI), settings.Key))
            {
                var db = await GetOrCreateDatabaseAsync(client, "MoviesDatabase");

                var collection = new Microsoft.Azure.Documents.DocumentCollection {
                    Id = collectionName
                };
                collection.PartitionKey.Paths.Add("/id");
                var c1 = await client.CreateDocumentCollectionAsync(db.SelfLink, collection);
            }
        }
Exemple #3
0
        public async Task OneTimeSetUp()
        {
            _client = new DocumentClient(new Uri("https://localhost:8081"), "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");

            var database = await _client.CreateDatabaseIfNotExistsAsync(new Microsoft.Azure.Documents.Database {
                Id = "CosmosSelectManyRepro"
            });

            _database = database.Resource;

            var collection = await _client.CreateDocumentCollectionIfNotExistsAsync(_database.SelfLink, new Microsoft.Azure.Documents.DocumentCollection {
                Id = "Documents"
            });

            _collection = collection.Resource;

            await _client.UpsertDocumentAsync(_collection.SelfLink, BobContainer);

            await _client.UpsertDocumentAsync(_collection.SelfLink, KristineContainer);
        }
        public async Task ContainerMigrationTest()
        {
            string containerName = "MigrationIndexTest";

            Documents.Index index1 = new Documents.RangeIndex(Documents.DataType.String, -1);
            Documents.Index index2 = new Documents.RangeIndex(Documents.DataType.Number, -1);
            Documents.DocumentCollection documentCollection = new Microsoft.Azure.Documents.DocumentCollection()
            {
                Id             = containerName,
                IndexingPolicy = new Documents.IndexingPolicy()
                {
                    IncludedPaths = new Collection <Documents.IncludedPath>()
                    {
                        new Documents.IncludedPath()
                        {
                            Path    = "/*",
                            Indexes = new Collection <Documents.Index>()
                            {
                                index1,
                                index2
                            }
                        }
                    }
                }
            };

            Documents.DocumentCollection createResponse = await NonPartitionedContainerHelper.CreateNonPartitionedContainer(this.database, documentCollection);

            // Verify the collection was created with deprecated Index objects
            Assert.AreEqual(2, createResponse.IndexingPolicy.IncludedPaths.First().Indexes.Count);
            Documents.Index createIndex = createResponse.IndexingPolicy.IncludedPaths.First().Indexes.First();
            Assert.AreEqual(index1.Kind, createIndex.Kind);

            // Verify v3 can add composite indexes and update the container
            Container           container           = this.database.GetContainer(containerName);
            ContainerProperties containerProperties = await container.ReadContainerAsync();

            Assert.IsNotNull(containerProperties.SelfLink);
            string cPath0 = "/address/city";
            string cPath1 = "/address/state";

            containerProperties.IndexingPolicy.CompositeIndexes.Add(new Collection <CompositePath>()
            {
                new CompositePath()
                {
                    Path  = cPath0,
                    Order = CompositePathSortOrder.Descending
                },
                new CompositePath()
                {
                    Path  = cPath1,
                    Order = CompositePathSortOrder.Ascending
                }
            });

            containerProperties.IndexingPolicy.SpatialIndexes.Add(
                new SpatialPath()
            {
                Path         = "/address/test/*",
                SpatialTypes = new Collection <SpatialType>()
                {
                    SpatialType.Point
                }
            });

            ContainerProperties propertiesAfterReplace = await container.ReplaceContainerAsync(containerProperties);

            Assert.AreEqual(0, propertiesAfterReplace.IndexingPolicy.IncludedPaths.First().Indexes.Count);
            Assert.AreEqual(1, propertiesAfterReplace.IndexingPolicy.CompositeIndexes.Count);
            Collection <CompositePath> compositePaths = propertiesAfterReplace.IndexingPolicy.CompositeIndexes.First();

            Assert.AreEqual(2, compositePaths.Count);
            CompositePath compositePath0 = compositePaths.ElementAt(0);
            CompositePath compositePath1 = compositePaths.ElementAt(1);

            Assert.IsTrue(string.Equals(cPath0, compositePath0.Path) || string.Equals(cPath1, compositePath0.Path));
            Assert.IsTrue(string.Equals(cPath0, compositePath1.Path) || string.Equals(cPath1, compositePath1.Path));

            Assert.AreEqual(1, propertiesAfterReplace.IndexingPolicy.SpatialIndexes.Count);
            Assert.AreEqual("/address/test/*", propertiesAfterReplace.IndexingPolicy.SpatialIndexes.First().Path);
        }
Exemple #5
0
        public async Task <IDocumentCollection <TItemUnderlying> > UpdateAsync(Microsoft.Azure.Documents.DocumentCollection collection)
        {
            await Client.ReplaceDocumentCollectionAsync(await this.GetLinkAsync(), collection);

            return(this);
        }
Exemple #6
0
 public IDocumentCollection <TItemUnderlying> Update(Microsoft.Azure.Documents.DocumentCollection collection)
 {
     return(Helpers.Synchronize(this.UpdateAsync(collection)));
 }
Exemple #7
0
 public async Task <IDocumentCollection <TItemUnderlying> > CreateAsync(Microsoft.Azure.Documents.DocumentCollection collection)
 {
     this.Id = (await Client.CreateDocumentCollectionIfNotExistsAsync(await this.Database.GetLinkAsync(), collection, _requestOptions)).Resource.Id;
     return(this);
 }
Exemple #8
0
        public async Task <IDatabase> AddAsync(Microsoft.Azure.Documents.DocumentCollection collection)
        {
            await Client.CreateDocumentCollectionAsync(await this.GetLinkAsync(), collection);

            return(this);
        }
Exemple #9
0
 public IDatabase Add(Microsoft.Azure.Documents.DocumentCollection collection)
 {
     return(Helpers.Synchronize(this.AddAsync(collection)));
 }