public async Task CreateCollectionIfNotExistsAsync() { DocumentCollection collection = new DocumentCollection(); collection.Id = GameCollectionName; collection.PartitionKey.Paths.Add("/playerId"); collection.IndexingPolicy.Automatic = true; collection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; collection.IndexingPolicy.IncludedPaths.Clear(); IncludedPath path = new IncludedPath(); path.Path = "/*"; path.Indexes.Add(new RangeIndex(DataType.String) { Precision = -1 }); collection.IndexingPolicy.IncludedPaths.Add(path); collection.IndexingPolicy.ExcludedPaths.Clear(); //TIP: Exclude large subtrees from indexing if not queried collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/bigGameState/*" }); await this.client.CreateDocumentCollectionIfNotExistsAsync( UriFactory.CreateDatabaseUri(DatabaseName), collection, new RequestOptions { OfferThroughput = 10000 }); }
private async Task CreateCollectionIfNotExists(IncludedPath indexPolicy = null) { try { await Client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName)); } catch (DocumentClientException ex) { if (ex.StatusCode == System.Net.HttpStatusCode.NotFound) { DocumentCollection coll = new DocumentCollection { Id = CollectionName }; if (indexPolicy != null) { coll.IndexingPolicy.IncludedPaths.Add(indexPolicy); } await Client.CreateDocumentCollectionAsync(UriFactory.CreateDatabaseUri(DatabaseName), coll, new RequestOptions { OfferThroughput = 400 }); } else { throw ex; } } }
public async void EnsureConfigCurrentWithUnchangedSignature() { var dbConfig = CreateDbConfig(); string signature = "sig"; var configDoc = CreateConfigDoc("Test", signature); _signatureGenerator.CreateSignature(Arg.Any <IList <DocumentStoreConfig> >()).Returns(signature); _documentClient.ReadDocumentAsync(Arg.Any <Uri>(), Arg.Is <RequestOptions>(x => x.PartitionKey != null)).Returns(WrapResource(configDoc)); // Existing index that should remain. var includeIdx1 = new IncludedPath(); includeIdx1.Path = "/content_Test_StoreA_DocA/*"; includeIdx1.Indexes.Add(new HashIndex(DataType.String, -1)); // Existing index that should be removed. It is no longer present. var includeIdx2 = new IncludedPath(); includeIdx2.Path = "/content_Test_StoreB_DocA/PropA/*"; includeIdx2.Indexes.Add(new RangeIndex(DataType.String)); var manager = new ServiceDbConfigManager("Test", _signatureGenerator); _documentClient.UpsertDocumentAsync(Arg.Any <Uri>(), Arg.Is <Document>(x => x.GetPropertyValue <string>("Signature") == signature)) .Returns(WrapResource(CreateConfigDoc(configDoc.Id, signature))); manager.RegisterStoreConfigSource(CreateConfigSource("A")); manager.RegisterStoreConfigSource(CreateConfigSource("B")); manager.EnsureConfigCurrent(_documentClient, dbConfig); await AssertNoUpdateTriggered(); }
private void AddIndexes(DocumentCollection collection, List <DocumentStoreConfig> storeConfigs) { foreach (var storeConfig in storeConfigs) { foreach (var config in storeConfig.Documents) { var documentKey = CreateDocumentContentKey(storeConfig.StoreName, config.DocumentName); foreach (var path in config.InclusionIndexes) { // Update the path to include the full content path. var newPath = new IncludedPath { Path = $"/{documentKey}{path.Path}", Indexes = path.Indexes }; collection.IndexingPolicy.IncludedPaths.Add(newPath); } foreach (var path in config.ExclusionIndexes) { // Update the path to include the full content path. var newPath = new ExcludedPath { Path = $"/{documentKey}{path.Path}" }; collection.IndexingPolicy.ExcludedPaths.Add(newPath); } } } }
public async Task CreateCollectionIfNotExistsAsync() { DocumentCollection collection = new DocumentCollection(); // TIP: If queries are known upfront, index just the properties you need collection.Id = CollectionName; collection.PartitionKey.Paths.Add("/playerId"); collection.IndexingPolicy.Automatic = true; collection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; collection.IndexingPolicy.IncludedPaths.Clear(); IncludedPath path = new IncludedPath(); path.Path = "/playerId/?"; path.Indexes.Add(new RangeIndex(DataType.String) { Precision = -1 }); collection.IndexingPolicy.IncludedPaths.Add(path); collection.IndexingPolicy.ExcludedPaths.Clear(); collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/*" }); await this.client.CreateDocumentCollectionIfNotExistsAsync( UriFactory.CreateDatabaseUri(DatabaseName), collection, new RequestOptions { OfferThroughput = 10000 }); }
public async Task CreateCollectionIfNotExistsAsync() { await documentClient.CreateDatabaseIfNotExistsAsync( new Database { Id = this.databaseName }); DocumentCollection collection = new DocumentCollection(); collection.Id = this.collectionName; if (!string.IsNullOrEmpty(this.partitionKey)) { collection.PartitionKey.Paths.Add(string.Format("/{0}", this.partitionKey)); } if (this.includePaths != null) { collection.IndexingPolicy.Automatic = true; collection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; collection.IndexingPolicy.IncludedPaths.Clear(); foreach (var includePath in includePaths) { IncludedPath path = new IncludedPath(); string[] pathInfo = includePath.Split('|'); path.Path = string.Format("/{0}/?", pathInfo[0]); if (pathInfo[1].ToLower() == "string") { path.Indexes.Add(new RangeIndex(DataType.String) { Precision = -1 }); } else if (pathInfo[1].ToLower() == "number") { path.Indexes.Add(new RangeIndex(DataType.Number) { Precision = -1 }); } collection.IndexingPolicy.IncludedPaths.Add(path); } collection.IndexingPolicy.ExcludedPaths.Clear(); collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/*" }); } if (this.ttlInDays > 0) { collection.DefaultTimeToLive = (this.ttlInDays * 86400); } await documentClient.CreateDocumentCollectionIfNotExistsAsync( UriFactory.CreateDatabaseUri(this.databaseName), collection, new RequestOptions { OfferThroughput = this.throughput }); }
public async Task CreateIndex(IncludedPath index) { var collection = new DocumentCollection { Id = _configurationService.DocumentDb.Collection }; collection.IndexingPolicy.IncludedPaths.Add(index); await DocumentDbClient.ReplaceDocumentCollectionAsync(collection); }
public static void AddRange(this IList <IncludedPath> collection, Dictionary <String, IndexAttribute> pathAndBehaviour) { foreach (var item in pathAndBehaviour) { var includedPath = new IncludedPath(); includedPath.Path = String.Format("/{0}/?", item.Key); includedPath.Indexes.AddFromMetaData(item.Value); collection.Add(includedPath); } }
public PSIncludedPath(IncludedPath includedPath) { Path = includedPath.Path; if (includedPath.Indexes != null) { Indexes = new List <PSIndexes>(); foreach (Indexes indexes in includedPath.Indexes) { Indexes.Add(new PSIndexes(indexes)); } } }
public void SetIncludedPath(IncludedPath includedPath) { this.includedPath = includedPath; // init the path tbIncludedPathPath.Text = includedPath.Path; lbIndexes.Items.Clear(); foreach (Index index in includedPath.Indexes) { lbIndexes.Items.Add(index); } }
public void SetIncludedPath(IncludedPath includedPath) { this.includedPath = includedPath; // init the path tbIncludedPathPath.Text = includedPath.Path; this.lbIndexes.Items.Clear(); foreach (Index index in includedPath.Indexes) { this.lbIndexes.Items.Add(index); } }
/// <summary> /// Builds a <see cref="DocumentConfig"/> class. /// </summary> /// <returns>The document configuration.</returns> public DocumentConfig Finish() { var path = new IncludedPath { Path = "/*" }; path.Indexes.Add(new HashIndex(DataType.String)); var attachments = _attachments.Values .Select(a => a.Finish()) .ToImmutableList(); return(new DocumentConfig(_name, attachments, ImmutableList.Create(path), null)); }
public async Task CreateCollectionIfNotExistsAsync(String collectionName, int throughput, int expirationDays) { DocumentCollection collection = new DocumentCollection(); collection.Id = collectionName; collection.PartitionKey.Paths.Add("/partitionKey"); collection.IndexingPolicy.Automatic = true; collection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; collection.IndexingPolicy.IncludedPaths.Clear(); IncludedPath path = new IncludedPath(); path.Path = "/partitionKey/?"; path.Indexes.Add(new RangeIndex(DataType.String) { Precision = -1 }); collection.IndexingPolicy.IncludedPaths.Add(path); path = new IncludedPath(); path.Path = "/sensorId/?"; path.Indexes.Add(new RangeIndex(DataType.String) { Precision = -1 }); collection.IndexingPolicy.IncludedPaths.Add(path); path = new IncludedPath(); path.Path = "/ts/?"; path.Indexes.Add(new RangeIndex(DataType.Number) { Precision = -1 }); collection.IndexingPolicy.IncludedPaths.Add(path); collection.IndexingPolicy.ExcludedPaths.Clear(); collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/*" }); collection.DefaultTimeToLive = (expirationDays * 86400); await this.client.CreateDocumentCollectionIfNotExistsAsync( UriFactory.CreateDatabaseUri(DatabaseName), collection, new RequestOptions { OfferThroughput = throughput }); }
public async Task CreateCollectionIfNotExistsAsync() { //TIP: Consider the event-sourcing pattern if your workload is ~50% writes DocumentCollection collection = new DocumentCollection(); collection.Id = EventsCollectionName; collection.PartitionKey.Paths.Add("/orderId"); collection.IndexingPolicy.Automatic = true; collection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; collection.IndexingPolicy.IncludedPaths.Clear(); IncludedPath path = new IncludedPath(); path.Path = "/orderId/?"; path.Indexes.Add(new RangeIndex(DataType.String) { Precision = -1 }); collection.IndexingPolicy.IncludedPaths.Add(path); path = new IncludedPath(); path.Path = "/eventType/?"; path.Indexes.Add(new RangeIndex(DataType.String) { Precision = -1 }); collection.IndexingPolicy.IncludedPaths.Add(path); path = new IncludedPath(); path.Path = "/eventTime/?"; path.Indexes.Add(new RangeIndex(DataType.String) { Precision = -1 }); collection.IndexingPolicy.IncludedPaths.Add(path); collection.IndexingPolicy.ExcludedPaths.Clear(); collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/*" }); await this.client.CreateDocumentCollectionIfNotExistsAsync( UriFactory.CreateDatabaseUri(DatabaseName), collection, new RequestOptions { OfferThroughput = 10000 }); }
private void btnEdit_Click(object sender, EventArgs e) { IncludedPath includedPath = this.lbIncludedPath.SelectedItem as IncludedPath; IncludedPathForm dlg = new IncludedPathForm(); dlg.StartPosition = FormStartPosition.CenterParent; dlg.SetIncludedPath(includedPath); DialogResult dr = dlg.ShowDialog(this); if (dr == DialogResult.OK) { this.lbIncludedPath.Items[this.lbIncludedPath.SelectedIndex] = dlg.IncludedPath; } }
public IncludedPathViewModel(IncludedPath includedPath) { IncludedPath = includedPath; Indexes = new BindingList <IndexViewModel>(IncludedPath.Indexes.Select(i => new IndexViewModel(i)).ToList()); Indexes.ListChanged += (s, e) => { if (Indexes.Any(i => i.HasErrors)) { return; } IncludedPath.Indexes.Clear(); foreach (var item in Indexes) { IncludedPath.Indexes.Add(item.GetIndex()); } RaisePropertyChanged(nameof(Indexes)); }; }
public static async Task CreateCollectionAsync() { IndexingPolicy policy = new IndexingPolicy(new RangeIndex(DataType.String, -1), new RangeIndex(DataType.Number)); policy.IndexingMode = IndexingMode.Consistent; policy.ExcludedPaths.Add(new ExcludedPath { Path = "/modulehistory/*" }); IncludedPath documentTypePath = new IncludedPath(); documentTypePath.Path = "/entitytype/?"; documentTypePath.Indexes.Add(new HashIndex(DataType.String, -1)); policy.IncludedPaths.Add(documentTypePath); IncludedPath clientIdPath = new IncludedPath(); clientIdPath.Path = "/clientid/?"; clientIdPath.Indexes.Add(new HashIndex(DataType.String, -1)); policy.IncludedPaths.Add(clientIdPath); IncludedPath farmIdPath = new IncludedPath(); farmIdPath.Path = "/farmid/?"; farmIdPath.Indexes.Add(new HashIndex(DataType.String, -1)); policy.IncludedPaths.Add(farmIdPath); IncludedPath fieldIdPath = new IncludedPath(); fieldIdPath.Path = "/fieldid/?"; fieldIdPath.Indexes.Add(new HashIndex(DataType.String, -1)); policy.IncludedPaths.Add(fieldIdPath); var result = await client.CreateDocumentCollectionAsync( UriFactory.CreateDatabaseUri(DatabaseId), new DocumentCollection { Id = CollectionId, IndexingPolicy = policy }, new RequestOptions { OfferThroughput = 800, ConsistencyLevel = ConsistencyLevel.Session }); }
private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbIncludedPathPath.Text)) { MessageBox.Show("Please input the valid path"); this.DialogResult = DialogResult.None; return; } this.includedPath = new IncludedPath(); includedPath.Path = tbIncludedPathPath.Text; foreach (object item in this.lbIndexes.Items) { Index index = item as Index; this.includedPath.Indexes.Add(index); } this.DialogResult = DialogResult.OK; return; }
private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbIncludedPathPath.Text)) { MessageBox.Show("Please input the valid path"); DialogResult = DialogResult.None; return; } includedPath = new IncludedPath(); includedPath.Path = tbIncludedPathPath.Text; foreach (object item in lbIndexes.Items) { Index index = item as Index; includedPath.Indexes.Add(index); } DialogResult = DialogResult.OK; return; }
private IndexPath FillIndexInformation(IncludedPath includedPath) { var ip = new IndexPath() { Path = includedPath.Path, Indexes = new List <My.Index>() }; foreach (var ind in includedPath.Indexes) { var index = new My.Index() { Kind = ind.Kind.ToString() }; switch (ind) { case HashIndex hi: index.DataType = hi.DataType.ToString(); index.Precision = hi.Precision; break; case RangeIndex ri: index.DataType = ri.DataType.ToString(); index.Precision = ri.Precision; break; case SpatialIndex si: index.DataType = si.DataType.ToString(); break; default: index.DataType = "unknown"; break; } ip.Indexes.Add(index); } return(ip); }
public async Task ContainerContractTest() { ClientEncryptionIncludedPath clientEncryptionIncludedPath1 = new ClientEncryptionIncludedPath() { Path = "/path", ClientEncryptionKeyId = "dekId", EncryptionAlgorithm = "AEAD_AES_256_CBC_HMAC_SHA256", EncryptionType = "Randomized" }; Collection <ClientEncryptionIncludedPath> paths = new Collection <ClientEncryptionIncludedPath>() { clientEncryptionIncludedPath1 }; ContainerProperties containerProperties = new ContainerProperties(Guid.NewGuid().ToString(), "/users") { IndexingPolicy = new IndexingPolicy() { Automatic = true, IndexingMode = IndexingMode.Consistent, IncludedPaths = new Collection <IncludedPath>() { new IncludedPath() { Path = "/*" } }, ExcludedPaths = new Collection <ExcludedPath>() { new ExcludedPath() { Path = "/test/*" } }, CompositeIndexes = new Collection <Collection <CompositePath> >() { new Collection <CompositePath>() { new CompositePath() { Path = "/address/city", Order = CompositePathSortOrder.Ascending }, new CompositePath() { Path = "/address/zipcode", Order = CompositePathSortOrder.Descending } } }, SpatialIndexes = new Collection <SpatialPath>() { new SpatialPath() { Path = "/address/spatial/*", SpatialTypes = new Collection <SpatialType>() { SpatialType.LineString } } } }, ClientEncryptionPolicy = new ClientEncryptionPolicy(paths) }; CosmosJsonDotNetSerializer serializer = new CosmosJsonDotNetSerializer(); Stream stream = serializer.ToStream(containerProperties); ContainerProperties deserialziedTest = serializer.FromStream <ContainerProperties>(stream); ContainerResponse response = await this.database.CreateContainerAsync(containerProperties); Assert.IsNotNull(response); Assert.IsTrue(response.RequestCharge > 0); Assert.IsNotNull(response.Headers); Assert.IsNotNull(response.Headers.ActivityId); ContainerProperties responseProperties = response.Resource; Assert.IsNotNull(responseProperties.Id); Assert.IsNotNull(responseProperties.ResourceId); Assert.IsNotNull(responseProperties.ETag); Assert.IsTrue(responseProperties.LastModified.HasValue); Assert.IsTrue(responseProperties.LastModified.Value > new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), responseProperties.LastModified.Value.ToString()); Assert.AreEqual(1, responseProperties.IndexingPolicy.IncludedPaths.Count); IncludedPath includedPath = responseProperties.IndexingPolicy.IncludedPaths.First(); Assert.AreEqual("/*", includedPath.Path); Assert.AreEqual("/test/*", responseProperties.IndexingPolicy.ExcludedPaths.First().Path); Assert.AreEqual(1, responseProperties.IndexingPolicy.CompositeIndexes.Count); Assert.AreEqual(2, responseProperties.IndexingPolicy.CompositeIndexes.First().Count); CompositePath compositePath = responseProperties.IndexingPolicy.CompositeIndexes.First().First(); Assert.AreEqual("/address/city", compositePath.Path); Assert.AreEqual(CompositePathSortOrder.Ascending, compositePath.Order); Assert.AreEqual(1, responseProperties.IndexingPolicy.SpatialIndexes.Count); SpatialPath spatialPath = responseProperties.IndexingPolicy.SpatialIndexes.First(); Assert.AreEqual("/address/spatial/*", spatialPath.Path); Assert.AreEqual(4, spatialPath.SpatialTypes.Count); // All SpatialTypes are returned Assert.AreEqual(1, responseProperties.ClientEncryptionPolicy.IncludedPaths.Count()); Assert.AreEqual(1, responseProperties.ClientEncryptionPolicy.PolicyFormatVersion); ClientEncryptionIncludedPath clientEncryptionIncludedPath = responseProperties.ClientEncryptionPolicy.IncludedPaths.First(); Assert.IsTrue(this.VerifyClientEncryptionIncludedPath(clientEncryptionIncludedPath1, clientEncryptionIncludedPath)); }
static async Task MainAsync(string[] args) { var endpoint = ConfigurationManager.AppSettings["DocumentDbEndPoint"]; var endpointUri = new Uri(endpoint); var authKey = ConfigurationManager.AppSettings["DocumentDbAuthKey"]; var client = new DocumentClient(endpointUri, authKey); //var adventureWorksLT = // client.CreateDatabaseQuery() // .Where(xx => xx.Id == "AdventureWorksLT") // .ToList() // .FirstOrDefault(); //var collectionId = "documents"; //var documents = // client.CreateDocumentCollectionQuery(adventureWorksLT.SelfLink) // .Where(xx => xx.Id == collectionId) // .ToList() // .FirstOrDefault(); //var collectionLink = documents.SelfLink; var databaseUri = new Uri("/dbs/AdventureWorks", UriKind.Relative); var documents = client.CreateDocumentCollectionQuery(databaseUri) .Where(xx => xx.Id == "documents") .ToList() .FirstOrDefault(); documents.IndexingPolicy.IndexingMode = IndexingMode.Lazy; documents = await client.ReplaceDocumentCollectionAsync(documents); RangePartitionResolver <string> rangeResolver = new RangePartitionResolver <string>( p => ((ProductDetailDTO)p).ProductModel.Name, new Dictionary <Range <string>, string>() { { new Range <string>("A", "M\uffff"), "/dbs/AdventureWorksLT/colls/productsA-M" }, { new Range <string>("N", "Z\uffff"), "/dbs/AdventureWorksLT/colls/productsN-Z" }, }); client.PartitionResolvers["/dbs/AdventureWorks"] = rangeResolver; var dbContext = new AdventureWorksLTDataModel(); var products = dbContext.Product.ToDTO().ToList(); var i = 1; foreach (var productDto in products) { var response = await client.CreateDocumentAsync(documents.SelfLink, productDto); //var response = await client.CreateDocumentAsync("/dbs/AdventureWorks", productDto); Console.Write("{0}", response.Resource.SelfLink); Console.WriteLine("...done"); i++; } documents.IndexingPolicy.IndexingMode = IndexingMode.Consistent; documents.IndexingPolicy.IncludedPaths.Clear(); // "root" var rootPath = new IncludedPath { Path = "/" }; rootPath.Indexes.Add(new HashIndex(DataType.String)); rootPath.Indexes.Add(new HashIndex(DataType.Number)); documents.IndexingPolicy.IncludedPaths.Add(rootPath); // Type var typePath = new IncludedPath { Path = "/Type/?" }; typePath.Indexes.Add(new HashIndex(DataType.String)); documents.IndexingPolicy.IncludedPaths.Add(typePath); // excluded documents.IndexingPolicy.ExcludedPaths.Clear(); // ProductCategory documents.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/ProductCategory/*" }); var productCategoryIdPath = new IncludedPath { Path = "/ProductCategory/Id/?" }; productCategoryIdPath.Indexes.Add(new HashIndex(DataType.String)); documents.IndexingPolicy.IncludedPaths.Add(productCategoryIdPath); // ProductModel documents.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/ProductModel/*" }); var productModelIdPath = new IncludedPath { Path = "/ProductModel/Id/?" }; productModelIdPath.Indexes.Add(new HashIndex(DataType.String)); documents.IndexingPolicy.IncludedPaths.Add(productModelIdPath); // make effective documents = await client.ReplaceDocumentCollectionAsync(documents); }
public async Task ContainerContractTest() { ContainerProperties containerProperties = new ContainerProperties(Guid.NewGuid().ToString(), "/users") { IndexingPolicy = new IndexingPolicy() { Automatic = true, IndexingMode = IndexingMode.Consistent, IncludedPaths = new Collection <IncludedPath>() { new IncludedPath() { Path = "/*" } }, ExcludedPaths = new Collection <ExcludedPath>() { new ExcludedPath() { Path = "/test/*" } }, CompositeIndexes = new Collection <Collection <CompositePath> >() { new Collection <CompositePath>() { new CompositePath() { Path = "/address/city", Order = CompositePathSortOrder.Ascending }, new CompositePath() { Path = "/address/zipcode", Order = CompositePathSortOrder.Descending } } }, SpatialIndexes = new Collection <SpatialPath>() { new SpatialPath() { Path = "/address/spatial/*", SpatialTypes = new Collection <SpatialType>() { SpatialType.LineString } } } } }; var serializer = new CosmosJsonDotNetSerializer(); Stream stream = serializer.ToStream(containerProperties); ContainerProperties deserialziedTest = serializer.FromStream <ContainerProperties>(stream); ContainerResponse response = await this.database.CreateContainerAsync(containerProperties); Assert.IsNotNull(response); Assert.IsTrue(response.RequestCharge > 0); Assert.IsNotNull(response.Headers); Assert.IsNotNull(response.Headers.ActivityId); ContainerProperties responseProperties = response.Resource; Assert.IsNotNull(responseProperties.Id); Assert.IsNotNull(responseProperties.ResourceId); Assert.IsNotNull(responseProperties.ETag); Assert.IsTrue(responseProperties.LastModified.HasValue); Assert.IsTrue(responseProperties.LastModified.Value > new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), responseProperties.LastModified.Value.ToString()); Assert.AreEqual(1, responseProperties.IndexingPolicy.IncludedPaths.Count); IncludedPath includedPath = responseProperties.IndexingPolicy.IncludedPaths.First(); Assert.AreEqual("/*", includedPath.Path); Assert.AreEqual("/test/*", responseProperties.IndexingPolicy.ExcludedPaths.First().Path); Assert.AreEqual(1, responseProperties.IndexingPolicy.CompositeIndexes.Count); Assert.AreEqual(2, responseProperties.IndexingPolicy.CompositeIndexes.First().Count); CompositePath compositePath = responseProperties.IndexingPolicy.CompositeIndexes.First().First(); Assert.AreEqual("/address/city", compositePath.Path); Assert.AreEqual(CompositePathSortOrder.Ascending, compositePath.Order); Assert.AreEqual(1, responseProperties.IndexingPolicy.SpatialIndexes.Count); SpatialPath spatialPath = responseProperties.IndexingPolicy.SpatialIndexes.First(); Assert.AreEqual("/address/spatial/*", spatialPath.Path); Assert.AreEqual(1, spatialPath.SpatialTypes.Count); Assert.AreEqual(SpatialType.LineString, spatialPath.SpatialTypes.First()); }
public async void EnsureConfigCurrentWithChangedSignature() { var dbConfig = CreateDbConfig(); string oldSig = "old_sig"; string newSig = "new_sig"; var configDoc = CreateConfigDoc("Test", oldSig); DocumentStoreConfigBuilder storeABuilder = new DocumentStoreConfigBuilder("StoreA"); storeABuilder.AddDocument("DocA"); DocumentStoreConfigBuilder storeBBuilder = new DocumentStoreConfigBuilder("StoreB"); storeBBuilder.AddDocument("DocA"); storeBBuilder.AddDocument("DocB"); var configSourceA = CreateConfigSource(storeABuilder); var configSourceB = CreateConfigSource(storeBBuilder); _signatureGenerator.CreateSignature(Arg.Any <IList <DocumentStoreConfig> >()).Returns(newSig); _documentClient.ReadDocumentAsync(Arg.Any <Uri>(), Arg.Is <RequestOptions>(x => x.PartitionKey != null)).Returns(WrapResource(configDoc)); // Existing index that should remain. var includeIdx1 = new IncludedPath(); includeIdx1.Path = "/content_Test_StoreA_DocA/*"; includeIdx1.Indexes.Add(new HashIndex(DataType.String, -1)); // Existing index that should be removed. It is no longer present. var includeIdx2 = new IncludedPath(); includeIdx2.Path = "/content_Test_StoreB_DocA/PropA/*"; includeIdx2.Indexes.Add(new RangeIndex(DataType.String)); var col1 = new DocumentCollection(); col1.IndexingPolicy.IncludedPaths.Add(includeIdx1); col1.IndexingPolicy.IncludedPaths.Add(includeIdx2); _documentClient.ReadDocumentCollectionAsync(Arg.Any <Uri>()).Returns(WrapResource(col1)); var manager = new ServiceDbConfigManager("Test", _signatureGenerator); var foo = WrapResource(col1); _documentClient.ReplaceDocumentCollectionAsync(Arg.Any <DocumentCollection>(), Arg.Any <RequestOptions>()).Returns(foo); _documentClient.UpsertDocumentAsync( Arg.Any <Uri>(), Arg.Is <object>(r => ((ServiceDbConfigManager.ServiceConfigRecord)r).Signature == newSig), Arg.Any <RequestOptions>()) .Returns(WrapResource(CreateConfigDoc(configDoc.Id, newSig))); manager.RegisterStoreConfigSource(configSourceA); manager.RegisterStoreConfigSource(configSourceB); manager.EnsureConfigCurrent(_documentClient, dbConfig); await _documentClient.Received(1).UpsertDocumentAsync(Arg.Any <Uri>(), Arg.Any <object>(), Arg.Any <RequestOptions>()); await _documentClient.Received().ReplaceDocumentCollectionAsync( Arg.Is <DocumentCollection>(c => IncludedPathCheck( c.IndexingPolicy.IncludedPaths, "/content_Test_StoreA_DocA/*", "/content_Test_StoreB_DocA/*", "/content_Test_StoreB_DocB/*")), Arg.Any <RequestOptions>()); }
public IndexingPolicyImpl <ParentImplT, IParentT, DefinitionParentT, UpdateParentT> WithIncludedPath(IncludedPath includedPath) { if (Inner.IncludedPaths == null) { Inner.IncludedPaths = new List <IncludedPath>(); } Inner.IncludedPaths.Add(includedPath); return(this); }
IndexingPolicy.Definition.IWithAttach <DefinitionParentT> IndexingPolicy.Definition.IWithIncludedPaths <DefinitionParentT> .WithIncludedPath(IncludedPath includedPath) { return(this.WithIncludedPath(includedPath)); }
IndexingPolicy.Update.IUpdate <UpdateParentT> IndexingPolicy.Update.IWithIncludedPaths <UpdateParentT> .WithIncludedPath(IncludedPath includedPath) { return(this.WithIncludedPath(includedPath)); }
public void Init(IncludedPath indexPolicy) { Client = new DocumentClient(new Uri(DatabaseUri), DatabaseKey); CreateDatabaseIfNotExists().Wait(); CreateCollectionIfNotExists(indexPolicy).Wait(); }
/// <summary> /// Creates the collection. /// </summary> /// <param name="db">The database.</param> /// <param name="collection">The collection</param> /// <param name="allowUpdate">if set to <c>true</c> [allow updates].</param> /// <returns> /// The Resource Response for collection /// </returns> /// <exception cref="InvalidOperationException">Document collection partition key cannot be changed.</exception> private async Task <DocumentCollection> CreateCollectionAsync(Microsoft.Azure.Documents.Database db, Collection collection, bool allowUpdate) { ResourceResponse <DocumentCollection> response = null; this.logger.Info("Checking whether {0} collection exists or not", collection.Name); var existingColl = this.client.CreateDocumentCollectionQuery(db.SelfLink).Where(x => x.Id == collection.Name).AsEnumerable().SingleOrDefault(); this.logger.Info("Initializing {0} collection", collection.Name); var documentCollection = new DocumentCollection { Id = collection.Name, DefaultTimeToLive = collection.Ttl }; // Setting up Partition Key if (collection.Partitioned && !string.IsNullOrEmpty(collection.PartitionKey)) { this.logger.Info("Setting up Partition Key for the {0} collection", collection.Name); documentCollection.PartitionKey = new PartitionKeyDefinition(); documentCollection.PartitionKey.Paths.Add(collection.PartitionKey); } // Excluded Paths foreach (var path in collection.ExcludedPaths) { this.logger.Info("Setting up excluded paths for the {0} collection", collection.Name); var excludedPaths = new ExcludedPath() { Path = path }; documentCollection.IndexingPolicy.ExcludedPaths.Add(excludedPaths); } // Included Paths foreach (var path in collection.IncludedPaths) { this.logger.Info("Setting up included path {0} for the {1} collection", path, collection.Name); var includedPaths = new IncludedPath() { Path = path }; documentCollection.IndexingPolicy.IncludedPaths.Add(includedPaths); } // Range Index Path foreach (var path in collection.RangeIndexIncludedPaths) { this.logger.Info("Setting up range included path {0} for the {1} collection", path, collection.Name); var includedPaths = new IncludedPath() { Path = path, Indexes = new System.Collections.ObjectModel.Collection <Index> { new RangeIndex(DataType.String) { Precision = -1 } } }; documentCollection.IndexingPolicy.IncludedPaths.Add(includedPaths); } documentCollection.IndexingPolicy.IndexingMode = this.GetIndexingMode(collection.IndexingMode); if (existingColl == null) { this.logger.Info("{0} Collection doesn't exist, Creating it", collection.Name); response = await this.client.CreateDocumentCollectionAsync(db.SelfLink, documentCollection, new RequestOptions { OfferThroughput = collection.ResourceUnits }).ConfigureAwait(false); } else if (allowUpdate) { this.logger.Info("{0} Collection exists, Updating the collection", collection.Name); var validationResult = ValidatePartitionKey(existingColl.PartitionKey, documentCollection.PartitionKey); if (validationResult) { existingColl.PartitionKey = documentCollection.PartitionKey; } else { throw new InvalidOperationException("Document collection partition key cannot be changed."); } existingColl.IndexingPolicy = documentCollection.IndexingPolicy; response = await this.client.ReplaceDocumentCollectionAsync(existingColl).ConfigureAwait(false); this.logger.Info("Updating throughput of the collection"); var offer = this.client.CreateOfferQuery().Where(t => t.ResourceLink == existingColl.SelfLink).AsEnumerable().SingleOrDefault(); if (offer != null) { offer = new OfferV2(offer, collection.ResourceUnits); await this.client.ReplaceOfferAsync(offer).ConfigureAwait(false); } } else { this.logger.Info("{0} Collection exists. Skipping update", collection.Name); response = new ResourceResponse <DocumentCollection>(existingColl); } if (response != null) { return(response.Resource); } return(null); }
private void toolStripBtnExecute_Click(object sender, EventArgs e) { this.SetLoadingState(); if (string.Compare(this.currentCrudName, "Create documentCollection", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(this.currentCrudName, "Replace documentCollection", StringComparison.OrdinalIgnoreCase) == 0) { this.collectionToCreate.IndexingPolicy.IncludedPaths.Clear(); foreach (object item in lbIncludedPath.Items) { IncludedPath includedPath = item as IncludedPath; this.collectionToCreate.IndexingPolicy.IncludedPaths.Add(includedPath); } this.collectionToCreate.IndexingPolicy.ExcludedPaths.Clear(); foreach (object item in lbExcludedPath.Items) { String excludedPath = item as String; this.collectionToCreate.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath() { Path = excludedPath }); } this.collectionToCreate.Id = tbCollectionId.Text; this.currentOperation(null, collectionToCreate); } else if (this.currentCrudName.StartsWith("Create trigger", StringComparison.OrdinalIgnoreCase)) { Trigger trigger = new Documents.Trigger(); trigger.Body = this.tbCrudContext.Text; trigger.Id = this.textBoxforId.Text; trigger.TriggerOperation = Documents.TriggerOperation.All; if (rbPreTrigger.Checked) { trigger.TriggerType = Documents.TriggerType.Pre; } else if (rbPostTrigger.Checked) { trigger.TriggerType = Documents.TriggerType.Post; } this.currentOperation(null, trigger); } else { if (!string.IsNullOrEmpty(this.tbCrudContext.SelectedText)) { this.currentOperation(this.tbCrudContext.SelectedText, this.textBoxforId.Text); } else { if (this.currentCrudName.StartsWith("Execute StoredProcedure", StringComparison.Ordinal) && !this.tbCrudContext.Modified) { this.currentOperation(null, this.textBoxforId.Text); } else { this.currentOperation(this.tbCrudContext.Text, this.textBoxforId.Text); } } } }