public static void Main(string[] args)
        {
            Console.WriteLine("Create Sample Data");

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            Configuration = builder.Build();

            var services = new ServiceCollection();

            ConfigureServices(services);
            serviceProvider = services.BuildServiceProvider();

            var dataInitializer         = new BikesDataInitializer();
            var searchDataInitializer   = new SearchServiceDataInitializer(Configuration);
            var cosmosDBDataInitializer = new CosmosDBDataInitializer(Configuration);

            Console.WriteLine("Creating Search Service sample data");
            searchDataInitializer.Initialize().Wait();
            searchDataInitializer.Initialize("products", "index.json", false).Wait();

            Console.WriteLine("Creating Cosmos DB sample data");
            cosmosDBDataInitializer.Initialize().Wait();

            Console.WriteLine("Creating SQL Database sample data");
            dataInitializer.InitializeDatabase(serviceProvider, Directory.GetCurrentDirectory()).Wait();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app,
                                    IHostingEnvironment env,
                                    ILoggerFactory loggerFactory,
                                    AuthorizationProvider authorizationProvider,
                                    BikesDataInitializer dataInitializer, SearchServiceDataInitializer searchDataInitializer,
                                    CosmosDBDataInitializer cosmosDBDataInitializer)
        {
            // Add Application Insights monitoring to the request pipeline as a very first middleware.
            app.UseApplicationInsightsRequestTelemetry();

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            // Default is index
            app.UseDefaultFiles(
                new DefaultFilesOptions()
            {
                DefaultFileNames = new[] { "index.html" }
            }
                );

            // Add Application Insights exceptions handling to the request pipeline.
            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

            app.UseCors("AllowAllOrigins");

            //Basic openId.connect server
            app.UseOpenIdConnectServer(options =>
            {
                options.Provider                    = authorizationProvider;
                options.AllowInsecureHttp           = true;
                options.ApplicationCanDisplayErrors = true;
            });

            app.UseOAuthValidation(new OAuthValidationOptions
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge    = true,
            });

            app.UseMiddleware <RequiredScopesMiddleware>(new List <string> {
                "api"
            });

            app.UseMvc();

            app.UseSwagger();
            app.UseSwaggerUi();

            await searchDataInitializer.Initialize();

            await cosmosDBDataInitializer.Initialize();

            await dataInitializer.InitializeDatabase(app.ApplicationServices, env.ContentRootPath);
        }