public static async Task PopulateCollectionWithDifferentDataType() { using (var client = new DocumentClient(_endpointUri, _primaryKey)) { await client.OpenAsync(); var collectionLink = UriFactory.CreateDocumentCollectionUri( "EntertainmentDatabase", "CustomCollection"); var tvInteractions = new Bogus.Faker <WatchLiveTelevisionChannel>() .RuleFor(i => i.type, (fake) => nameof(WatchLiveTelevisionChannel)) .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45)) .RuleFor(i => i.channelName, (fake) => fake.PickRandom(new List <string> { "NEWS-6", "DRAMA-15", "ACTION-12", "DOCUMENTARY-4", "SPORTS-8" })) .Generate(500); foreach (var interaction in tvInteractions) { var result = await client.CreateDocumentAsync(collectionLink, interaction); await Console.Out.WriteLineAsync( $"Document #{tvInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); } } }
public static async Task addDocuments() { DateTime start = DateTime.Today.AddDays(-30); DateTime end = DateTime.Today; using (DocumentClient client = new DocumentClient(_endpoint, _primaryKey)) { await client.OpenAsync(); Uri collection = UriFactory.CreateDocumentCollectionUri("SparkDatabase", "Twitter"); var tweets_Generated = new Bogus.Faker <Tweet>() .RuleFor(i => i.like_Count, (fake) => fake.Random.Number(0, 100000)) .RuleFor(i => i.comments_Count, (fake) => fake.Random.Number(0, 100000)) .RuleFor(i => i.repost_Count, (fake) => fake.Random.Number(0, 100000)) .RuleFor(i => i.deleted, (fake) => fake.Random.Bool()) .RuleFor(i => i.tweetID, (fake) => fake.Random.Uuid().ToString()) .RuleFor(i => i.userID, (fake) => fake.Random.Uuid().ToString()) .RuleFor(i => i.created_At, (fake) => fake.Date.Between(start, end)) .RuleFor(i => i.tweet_Content, (fake) => fake.Lorem.Text()) .RuleFor(i => i.type, f => f.PickRandom <Type>().ToString()) .Generate(10000000); foreach (var tweets in tweets_Generated) { tweets.sequenceNumber = countOfRecords++; ResourceResponse <Document> result = await client.CreateDocumentAsync(collection, tweets); await Console.Out.WriteLineAsync($"Document #{tweets_Generated.IndexOf(tweets):000} Created\t{result.Resource.Id}\t with sequence number:{tweets.sequenceNumber}"); } } }
public static async Task PopulateCollection() { using (var client = new DocumentClient(_endpointUri, _primaryKey)) { await client.OpenAsync(); var collectionLink = UriFactory.CreateDocumentCollectionUri( "EntertainmentDatabase", "CustomCollection"); var foodInteractions = new Bogus.Faker <PurchaseFoodOrBeverage>() .RuleFor(i => i.type, (fake) => nameof(PurchaseFoodOrBeverage)) .RuleFor(i => i.unitPrice, (fake) => Math.Round(fake.Random.Decimal(1.99m, 15.99m), 2)) .RuleFor(i => i.quantity, (fake) => fake.Random.Number(1, 5)) .RuleFor(i => i.totalPrice, (fake, user) => Math.Round(user.unitPrice * user.quantity, 2)) .Generate(500); foreach (var interaction in foodInteractions) { var result = await client.CreateDocumentAsync(collectionLink, interaction); await Console.Out.WriteLineAsync( $"Document #{foodInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); } } }
private static async Task createPurchaseFoodOrBeverage(DocumentClient client, String collectionLink, String databaseLink) { var foodInteractions = new Bogus.Faker <PurchaseFoodOrBeverage>() .RuleFor(i => i.type, (fake) => nameof(PurchaseFoodOrBeverage)) .RuleFor(i => i.unitPrice, (fake) => Math.Round(fake.Random.Decimal(1.99m, 15.99m), 2)) .RuleFor(i => i.quantity, (fake) => fake.Random.Number(1, 5)) .RuleFor(i => i.totalPrice, (fake, user) => Math.Round(user.unitPrice * user.quantity, 2)) .Generate(20); foreach (var interaction in foodInteractions) { ResourceResponse <Document> result = await client.CreateDocumentAsync(createCollectionLink(databaseLink, collectionLink), interaction); await Console.Out.WriteLineAsync($"Document #{foodInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); } }
internal static async Task PopulateUnlimitedCollectionWithData(DocumentClient client) { await client.OpenAsync(); Uri collectionLink = UriFactory.CreateDocumentCollectionUri("EntertainmentDatabase", "CustomCollection"); var foodInteractions = new Bogus.Faker <PurchaseFoodOrBeverage>() .RuleFor(i => i.type, (fake) => nameof(PurchaseFoodOrBeverage)) .RuleFor(i => i.unitPrice, (fake) => Math.Round(fake.Random.Decimal(1.99m, 15.99m))) .RuleFor(i => i.quantity, (fake) => fake.Random.Number(1, 5)) .RuleFor(i => i.totalPrice, (fake, user) => Math.Round(user.unitPrice * user.quantity, 5)) .Generate(100); foreach (var interaction in foodInteractions) { ResourceResponse <Document> result = await client.CreateDocumentAsync(collectionLink, interaction); await Console.Out.WriteLineAsync($"Document #{foodInteractions.IndexOf(interaction):000} created. Id {result.Resource.Id}"); } DocumentCollection coll = await client.ReadDocumentCollectionAsync(collectionLink); await Console.Out.WriteLineAsync(coll.SelfLink); }
public static async Task PopulateCollectionWithAnotherDifferentDataType() { using (var client = new DocumentClient(_endpointUri, _primaryKey)) { await client.OpenAsync(); var collectionLink = UriFactory.CreateDocumentCollectionUri( "EntertainmentDatabase", "CustomCollection"); var mapInteractions = new Bogus.Faker <ViewMap>() .RuleFor(i => i.type, (fake) => nameof(ViewMap)) .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45)) .Generate(500); foreach (var interaction in mapInteractions) { var result = await client.CreateDocumentAsync(collectionLink, interaction); await Console.Out.WriteLineAsync( $"Document #{mapInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); } } }
public static async Task Main(string[] args) { using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) { //Database targetDatabase = new Database { Id = "EntertainmentDatabase" }; //targetDatabase = await client.CreateDatabaseIfNotExistsAsync(targetDatabase); //await Console.Out.WriteLineAsync($"Database Self-Link:\t{targetDatabase.SelfLink}"); await client.OpenAsync(); //Uri databaseLink = UriFactory.CreateDatabaseUri("EntertainmentDatabase"); //DocumentCollection defaultCollection = new DocumentCollection //{ // Id = "DefaultCollection" //}; //defaultCollection = await client.CreateDocumentCollectionIfNotExistsAsync(databaseLink, defaultCollection); //await Console.Out.WriteLineAsync($"Default Collection Self-Link:\t{defaultCollection.SelfLink}"); //IndexingPolicy indexingPolicy = new IndexingPolicy //{ // IndexingMode = IndexingMode.Consistent, // Automatic = true, // IncludedPaths = new Collection<IncludedPath> // { // new IncludedPath // { // Path = "/*", // Indexes = new Collection<Index> // { // new RangeIndex(DataType.Number, -1), // new RangeIndex(DataType.String, -1) // } // } // } //}; //PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition //{ // Paths = new Collection<string> { "/type" } //}; //DocumentCollection customCollection = new DocumentCollection //{ // Id = "CustomCollection", // PartitionKey = partitionKeyDefinition, // IndexingPolicy = indexingPolicy //}; //RequestOptions requestOptions = new RequestOptions //{ // OfferThroughput = 10000 //}; //customCollection = await client.CreateDocumentCollectionIfNotExistsAsync(databaseLink, customCollection, requestOptions); //await Console.Out.WriteLineAsync($"Custom Collection Self-Link:\t{customCollection.SelfLink}"); Uri collectionLink = UriFactory.CreateDocumentCollectionUri("EntertainmentDatabase", "CustomCollection"); var foodInteractions = new Bogus.Faker <PurchaseFoodOrBeverage>() .RuleFor(i => i.type, (fake) => nameof(PurchaseFoodOrBeverage)) .RuleFor(i => i.unitPrice, (fake) => Math.Round(fake.Random.Decimal(1.99m, 15.99m), 2)) .RuleFor(i => i.quantity, (fake) => fake.Random.Number(1, 5)) .RuleFor(i => i.totalPrice, (fake, user) => Math.Round(user.unitPrice * user.quantity, 2)) .Generate(500); foreach (var interaction in foodInteractions) { ResourceResponse <Document> result = await client.CreateDocumentAsync(collectionLink, interaction); await Console.Out.WriteLineAsync($"Document #{foodInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); } Console.ReadKey(); } }
public static async Task Main(string[] args) { //use below code only once to connect or to create a db using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) { // creating new database instance Database targetDB = new Database { Id = "EntertainmentDatabase" }; // create if targetDB doesnot exist targetDB = await client.CreateDatabaseIfNotExistsAsync(targetDB); await Console.Out.WriteLineAsync($"Database Self-link:\t{targetDB.SelfLink}"); } //Fixed Collection creation using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) { await client.OpenAsync(); Uri databaseLink = UriFactory.CreateDatabaseUri("EntertainmentDatabase"); DocumentCollection defaultCollection = new DocumentCollection { Id = "DefaultCollection" }; defaultCollection = await client.CreateDocumentCollectionAsync(databaseLink, defaultCollection); await Console.Out.WriteLineAsync($"Default Collection Self-Link\t{defaultCollection.SelfLink}"); } //Unlimited Collection or Custome Collection using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) { await client.OpenAsync(); Uri databaseLink = UriFactory.CreateDatabaseUri("EntertainmentDatabase"); IndexingPolicy indexingPolicy = new IndexingPolicy { IndexingMode = IndexingMode.Consistent, Automatic = true, IncludedPaths = new Collection <IncludedPath> { new IncludedPath { Path = "/*", Indexes = new Collection <Index> { new RangeIndex(DataType.Number, -1), new RangeIndex(DataType.String, -1) } } } }; PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition { Paths = new Collection <string> { "/type" } }; DocumentCollection customCollection = new DocumentCollection { Id = "CustomCollection", PartitionKey = partitionKeyDefinition, IndexingPolicy = indexingPolicy }; RequestOptions requestOptions = new RequestOptions { OfferThroughput = 10000 }; customCollection = await client.CreateDocumentCollectionIfNotExistsAsync(databaseLink, customCollection, requestOptions); await Console.Out.WriteLineAsync($"Custom Collection Self-Link:\t{customCollection.SelfLink}"); } //populating foodInteractions using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) { await client.OpenAsync(); Uri collectionLink = UriFactory.CreateDocumentCollectionUri("EntertainmentDatabase", "CustomCollection"); var foodInteractions = new Bogus.Faker <PurchaseFoodOrBeverage>() .RuleFor(i => i.type, (fake) => nameof(PurchaseFoodOrBeverage)) .RuleFor(i => i.unitPrice, (fake) => Math.Round(fake.Random.Decimal(1.99m, 15.9m), 2)) .RuleFor(i => i.quantity, (fake) => fake.Random.Number(1, 5)) .RuleFor(i => i.totalPrice, (fake, user) => Math.Round(user.unitPrice * user.quantity, 2)) .Generate(500); foreach (var interaction in foodInteractions) { ResourceResponse <Document> result = await client.CreateDocumentAsync(collectionLink, interaction); await Console.Out.WriteLineAsync($"Document #{foodInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); } ; } //populating tv interactions using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) { await client.OpenAsync(); Uri collectionLink = UriFactory.CreateDocumentCollectionUri("EntertainmentDatabase", "CustomCollection"); var tvInteractions = new Bogus.Faker <WatchLiveTelevisionChannel>() .RuleFor(i => i.type, (fake) => nameof(WatchLiveTelevisionChannel)) .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45)) .RuleFor(i => i.channelName, (fake) => fake.PickRandom(new List <string> { "NEWS-6", "DRAMA-15", "ACTION-12", "DOCUMENTARY-4", "SPORTS-8" })) .Generate(500); foreach (var interaction in tvInteractions) { ResourceResponse <Document> result = await client.CreateDocumentAsync(collectionLink, interaction); await Console.Out.WriteLineAsync($"Document #{tvInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); } } //populating Map interactions using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) { await client.OpenAsync(); Uri collectionLink = UriFactory.CreateDocumentCollectionUri("EntertainmentDatabase", "CustomCollection"); var mapInteractions = new Bogus.Faker <ViewMap>() .RuleFor(i => i.type, (fake) => nameof(ViewMap)) .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45)) .Generate(500); foreach (var interaction in mapInteractions) { ResourceResponse <Document> result = await client.CreateDocumentAsync(collectionLink, interaction); await Console.Out.WriteLineAsync($"Document #{mapInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); } } }
public static async Task Main(string[] args) { using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) { await client.OpenAsync(); Uri collectionLink = UriFactory.CreateDocumentCollectionUri("EntertainmentDatabase", "CustomCollection"); var tvInteractions = new Bogus.Faker <WatchLiveTelevisionChannel>() .RuleFor(i => i.type, (fake) => nameof(WatchLiveTelevisionChannel)) .RuleFor(i => i.minutesViewed, (fake) => fake.Random.Number(1, 45)) .RuleFor(i => i.channelName, (fake) => fake.PickRandom(new List <string> { "NEWS-6", "DRAMA-15", "ACTION-12", "DOCUMENTARY-4", "SPORTS-8" })) .Generate(500); foreach (var interaction in tvInteractions) { ResourceResponse <Document> result = await client.CreateDocumentAsync(collectionLink, interaction); await Console.Out.WriteLineAsync($"Document #{tvInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); } } /* Lab 2 * * using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) * { * await client.OpenAsync(); * Uri collectionLink = UriFactory.CreateDocumentCollectionUri("EntertainmentDatabase", "CustomCollection"); * var foodInteractions = new Bogus.Faker<PurchaseFoodOrBeverage>() * .RuleFor(i => i.type, (fake) => nameof(PurchaseFoodOrBeverage)) * .RuleFor(i => i.unitPrice, (fake) => Math.Round(fake.Random.Decimal(1.99m, 15.99m), 2)) * .RuleFor(i => i.quantity, (fake) => fake.Random.Number(1, 5)) * .RuleFor(i => i.totalPrice, (fake, user) => Math.Round(user.unitPrice * user.quantity, 2)) * .Generate(500); * foreach(var interaction in foodInteractions) * { * ResourceResponse<Document> result = await client.CreateDocumentAsync(collectionLink, interaction); * await Console.Out.WriteLineAsync($"Document #{foodInteractions.IndexOf(interaction):000} Created\t{result.Resource.Id}"); * } * } * * */ /* Lab 1 * * * * using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) * { * * } * * using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) * { * * * Database targetDatabase = new Database { Id = "EntertainmentDatabase" }; * targetDatabase = await client.CreateDatabaseIfNotExistsAsync(targetDatabase); * await Console.Out.WriteLineAsync($"Database Self-Link:\t{targetDatabase.SelfLink}"); * * * * * } * * * using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) * { * * await client.OpenAsync(); * Uri databaseLink = UriFactory.CreateDatabaseUri("EntertainmentDatabase"); * * DocumentCollection defaultCollection = new DocumentCollection * { Id = "DefaultCollection" }; * * defaultCollection = await client.CreateDocumentCollectionIfNotExistsAsync(databaseLink, defaultCollection); * await Console.Out.WriteLineAsync($"Default Collection Self-Link:\t{defaultCollection.SelfLink}"); * * * } * * // Create an Unlimited Collection using the SDK * * using (DocumentClient client = new DocumentClient(_endpointUri, _primaryKey)) * { * * await client.OpenAsync(); * Uri databaseLink = UriFactory.CreateDatabaseUri("EntertainmentDatabase"); * * IndexingPolicy indexingPolicy = new IndexingPolicy * { * IndexingMode = IndexingMode.Consistent, * Automatic = true, * IncludedPaths = new Collection<IncludedPath> * { * new IncludedPath * { * Path = "/*", * Indexes = new Collection<Index> * { * new RangeIndex(DataType.Number, -1), * new RangeIndex(DataType.String, -1) * } * } * } * }; * * PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition * { * Paths = new Collection<string> { "/type" } * }; * * * DocumentCollection customCollection = new DocumentCollection * { * Id = "CustomCollection", * PartitionKey = partitionKeyDefinition, * IndexingPolicy = indexingPolicy * }; * * RequestOptions requestOptions = new RequestOptions * { * OfferThroughput = 10000 * }; * * * customCollection = await client.CreateDocumentCollectionIfNotExistsAsync(databaseLink, customCollection, requestOptions); * * await Console.Out.WriteLineAsync($"Custom Collection Self-Link:\t{customCollection.SelfLink}"); * * * } * * */ }