static void Main(string[] args) { IDocumentDbInitializer initializer = new DocumentDbInitializer(); try { Client = initializer.GetClient(EndpointUrl, PrimaryKey); Task program = DemoAsync(args); program.Wait(); } catch (DocumentClientException de) { Exception baseException = de.GetBaseException(); Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message); } catch (Exception e) { Exception baseException = e.GetBaseException(); Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message); } finally { Console.WriteLine("End of demo, press any key to exit."); Console.ReadKey(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { DocumentDbInitializer.Initialize(Configuration); app.UseCors("CorsPolicy"); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "AES API v1.0"); }); var option = new RewriteOptions(); option.AddRedirect("^$", "swagger"); app.UseRewriter(option); app.UseSignalR(routes => { routes.MapHub <AesHub>("/aesHub"); }); app.UseMvc(); }
static void Main(string[] args) { try { IDocumentDbInitializer init = new DocumentDbInitializer(); Client = init.GetClient(EndpointUrl, PrimaryKey); Program p = new Program(); p.DocumentDBDemoWithUOW().Wait(); } catch (DocumentClientException de) { Exception baseException = de.GetBaseException(); Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message); } catch (Exception e) { Exception baseException = e.GetBaseException(); Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message); } finally { Console.WriteLine("Demo is Done. Press any key to continue"); Console.ReadKey(); } }
public Logic(string docDBEndpoint, string docDBKey, string docDbName, string partitionKeyName, string docDbCollectionName) { _partitionKeyName = partitionKeyName; var initializer = new DocumentDbInitializer(); //TODO check out connection policy var client = initializer.GetClient(docDBEndpoint, docDBKey); _repository = new DocumentDbRepository <WordsData>(client, docDbName, _partitionKeyName, () => docDbCollectionName); }
static void Main(string[] args) { IDocumentDbInitializer init = new DocumentDbInitializer(); string endpointUrl = ConfigurationManager.AppSettings["azure.documentdb.endpointUrl"]; string authorizationKey = ConfigurationManager.AppSettings["azure.documentdb.authorizationKey"]; //Get the DB client Client = init.GetClient(endpointUrl, authorizationKey); Task t = MainAsync(args); t.Wait(); }
protected Repository(IDataBaseManager dataBaseManager) { IDocumentDbInitializer init = new DocumentDbInitializer(); string endpoint = dataBaseManager.GetDataBaseEndPoint(); string key = dataBaseManager.GetDataBaseKey(); string databaseId = dataBaseManager.GetDataBaseId(); var client = init.GetClient(endpoint, key); _documentDbRepository = new DocumentDbRepository <T>(client, databaseId); }
public async Task <ActionResult> InitDocumentDb() { string json; using (var fs = new FileStream(this.Server.MapPath("~/Content/Startup/seed.json"), FileMode.Open)) { using (var sr = new StreamReader(fs)) { json = sr.ReadToEnd(); } } var status = await DocumentDbInitializer <SeedModel> .Initialize(json); if (this.Request.IsAjaxRequest()) { return(this.PartialView("_List", this.GetAll())); } return(this.View("InitStatus", status)); }
public void Execute() { var result = DocumentDbInitializer <Tenant> .Initialize(this.Json, DefaultCollection, DefaultDatabase).Result; }
private static async Task Main(string[] args) { IDocumentDbInitializer init = new DocumentDbInitializer(); var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); string endpointUrl = configuration["endpointUrl"]; string authorizationKey = configuration["authorizationKey"]; // get the Azure DocumentDB client Client = init.GetClient(endpointUrl, authorizationKey, new ConnectionPolicy()); // Run demo string databaseId = configuration["databaseId"]; // create repository for persons and set Person.FullName property as identity field (overriding default Id property name) DocumentDbRepository<Person> repo = new DocumentDbRepository<Person>(Client, databaseId, null, p => p.FullName); // output all persons in our database, nothing there yet await PrintPersonCollection(repo); // create a new person Person matt = new Person { FirstName = "m4tt", LastName = "TBA", BirthDayDateTime = new DateTime(1990, 10, 10), PhoneNumbers = new Collection<PhoneNumber> { new PhoneNumber {Number = "555", Type = "Mobile"}, new PhoneNumber {Number = "777", Type = "Landline"} } }; // add person to database's collection (if collection doesn't exist it will be created and named as class name -it's a convenction, that can be configured during initialization of the repository) matt = await repo.AddOrUpdateAsync(matt); // create another person Person jack = new Person { FirstName = "Jack", LastName = "Smith", BirthDayDateTime = new DateTime(1990, 10, 10), PhoneNumbers = new Collection<PhoneNumber>() }; // add jack to collection jack = await repo.AddOrUpdateAsync(jack); // should output person and his two phone numbers await PrintPersonCollection(repo); // change birth date matt.BirthDayDateTime -= new TimeSpan(500, 0, 0, 0); // remove landline phone number matt.PhoneNumbers.RemoveAt(1); // should update person await repo.AddOrUpdateAsync(matt); // should output Matt with just one phone number await PrintPersonCollection(repo); // get Matt by his Id Person justMatt = await repo.GetByIdAsync(matt.FullName); Console.WriteLine("GetByIdAsync result: " + justMatt); // ... or by his first name Person firstMatt = await repo.FirstOrDefaultAsync(p => p.FirstName.Equals("matt", StringComparison.OrdinalIgnoreCase)); Console.WriteLine("First: " + firstMatt); // query all the smiths var smiths = (await repo.WhereAsync(p => p.LastName.Equals("Smith"))).ToList(); Console.WriteLine(smiths.Count); // use IQueryable, as for now supported expressions are 'Queryable.Where', 'Queryable.Select' & 'Queryable.SelectMany' var allSmithsPhones = (await repo.QueryAsync()).SelectMany(p => p.PhoneNumbers).Select(p => p.Type); foreach (var phone in allSmithsPhones) { Console.WriteLine(phone); } // count all persons var personsCount = await repo.CountAsync(); // count all jacks var jacksCount = await repo.CountAsync(p => p.FirstName == "Jack"); // remove matt from collection await repo.RemoveAsync(matt.FullName); // remove jack from collection await repo.RemoveAsync(jack.FullName); // should output nothing await PrintPersonCollection(repo); // remove collection await repo.RemoveAsync(); }