Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy(AllowAllOriginsPolicy,
                                  builder =>
                {
                    builder
                    .WithOrigins("http://localhost:3000", "https://localhost:3000")
                    .AllowAnyMethod()
                    .AllowAnyHeader();
                });
            });

            services.AddControllers();

            services.AddSingleton <ICosmosDBService>(CosmosDBInitializer.InitializeCosmosClientInstanceAsync(new VersesDBConfiguration
            {
                ConnectionString = Configuration.GetSection("CosmosDB").GetSection("ConnectionString").Value,
                DatabaseName     = Configuration.GetSection("CosmosDB").GetSection("DatabaseName").Value,
                ContainerName    = Configuration.GetSection("CosmosDB").GetSection("ContainerName").Value,
            }).GetAwaiter().GetResult());
        }
Esempio n. 2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello Seeder! Waiting for initializing DB...");

            var versesDBConfiguration = GetCosmosDBConfiguration();

            var cosmosDBService = CosmosDBInitializer.InitializeCosmosClientInstanceAsync(versesDBConfiguration).GetAwaiter().GetResult();

            Console.WriteLine("Ready! Press enter to start seeding!");
            Console.ReadLine();

            var poem = @"
Forever we remain oblivious to the future,
lost to the past and enduring our torture.
Forever we take chances to settle our scores,
losing some battles and winning some wars.
Forever praying out loud hoping someone will hear,
forever crying softly but never shedding a tear.
Forever exists behind a disguise,
but the belief in forever keeps our hearts alive.
".Split(',', '.').ToList();

            poem.ForEach(async line =>
            {
                Console.WriteLine($"Adding line '{line}'");
                await cosmosDBService.AddItemAsync(new InfinitePoem.DAO.Verse
                {
                    CreatedAt = DateTime.UtcNow.ToString(),
                    Id        = Guid.NewGuid().ToString(),
                    Text      = line,
                }, "en");
            });

            Console.WriteLine("Poem added!");
            Console.ReadLine();
        }