Пример #1
0
        public void Configure(IApplicationBuilder app,
                              IWebHostEnvironment env,
                              TaskManagerDbContext context,
                              UserManager <ApplicationUser> userManager,
                              RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();

                InitializeDb.SeedDatabase(context, userManager, roleManager);
            }

            app.UseHttpsRedirection();

            app.UseRouting();
            app.UseStaticFiles(); // wwwroot folder access

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseSwagger();

            app.UseSwaggerUI(c => { c.SwaggerEndpoint("v1/swagger.json", "TaskManager"); }); // http://localhost/swagger
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            // populate
            InitializeDb.EnsurePopulated(app);
        }
Пример #3
0
        public static async System.Threading.Tasks.Task Main(string[] args)
        {
            var hostBuilder = CreateHostBuilder(args).Build();

            using (var scope = hostBuilder.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <FormulaOneDbContext>();
                    await context.Database.EnsureCreatedAsync();

                    InitializeDb.Initialize(context);

                    var userSeeder = services.GetRequiredService <IUserRepository>();
                    await userSeeder.SeedUserAsync();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            hostBuilder.Run();
        }
Пример #4
0
        private void InitilizeDb()
        {
            var initializeDb = new InitializeDb(
                Configuration.GetConnectionString("stockTickerConnectionString"),
                Configuration.GetConnectionString("adminConnectionString"));

            initializeDb.InitializeDbAndTablesAsync().Wait();
        }
Пример #5
0
 public Task Invoke(HttpContext httpContext, courseworkDbContext db)
 {
     if (!(httpContext.Session.Keys.Contains("starting")))
     {
         InitializeDb.Initialize(db);
         httpContext.Session.SetString("starting", "Yes");
     }
     return(_next.Invoke(httpContext));
 }
Пример #6
0
        static void Main()
        {
            InitializeDb initializeDb = new InitializeDb();

            conn = initializeDb.getConnection();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new WelcomeScreen());
        }
Пример #7
0
        protected void Application_Start()
        {
            InitializeDb initializeDb = new InitializeDb();

            conn = initializeDb.getConnection();
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Пример #8
0
        public override async void OnNavigatingTo(NavigationParameters parameters)
        {
            base.OnNavigatingTo(parameters);
            var itemsList = await context.Items.GetAllAsync();

            if (itemsList.Count == 0)
            {
                await InitializeDb.Initialize(context);

                itemsList = await context.Items.GetAllAsync();
            }
            Items = new ObservableCollection <Item>(itemsList);
        }
Пример #9
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var context = services.GetRequiredService <MovieContext>();
                    // using ContosoUniversity.Data;
                    InitializeDb.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred creating the DB.");
                }
            }
            host.Run();
        }
Пример #10
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            // Get db context and make sure db created.
            using (var scope = host.Services.CreateScope()) {
                var services = scope.ServiceProvider;

                // Perform database setup.
                try
                {
                    // Get database context from services.
                    var context     = services.GetRequiredService <AppDbContext>();
                    var dbNotExists = context.Database.EnsureCreated();

                    if (dbNotExists)
                    {
                        // Create user roles.
                        // Call this method before creating any account.
                        InitializeDb.CreateUserRoles(services.GetRequiredService <RoleManager <IdentityRole> >()).Wait();

                        // Add administrators accounts if db was successfully created.
                        InitializeDb.CreateAdministratorAccounts(services.GetRequiredService <UserManager <User> >()).Wait();

                        // Add test users
                        InitializeDb.CreateTestUsers(services.GetRequiredService <UserManager <User> >(), context);

                        // Create test help pages.
                        InitializeDb.CreateTestHelpPages(context).Wait();
                    }
                }
                catch (Exception e) {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, "Error occurred during db creation process.");
                }
            }
            host.Run();
        }
Пример #11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, QuizDITDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Quiz DIT Managment Service 1.0");
                });
            }
            app.UseCors("AllowAll");

            app.UseMvc();

            InitializeDb.LoadQuiz(context);
            InitializeDb.LoadAnswers(context);
            InitializeDb.LoadQuestions(context);
            InitializeDb.LoadQuestionMappings(context);
            InitializeDb.LoadQuestionAnswerMappings(context);
            InitializeDb.LoadUsers(context);
            InitializeDb.LoadUserQuiz(context);
        }
Пример #12
0
        public async Task <IActionResult> initializeDb()
        {
            try
            {
                var clientes = InitializeDb.GetClientes();

                foreach (var cliente in clientes)
                {
                    _repo.Add(cliente);
                }

                if (await _repo.SaveChangesAsync())
                {
                    return(Ok(new { message = "OK" }));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex.Message}"));
            }

            return(BadRequest());
        }
Пример #13
0
        public static void Main(string[] args)
        {
            config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                     .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: false)
                     .AddEnvironmentVariables()
                     .AddCommandLine(args)
                     .Build();

            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context     = services.GetRequiredService <ApplicationDbContext>();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <ApplicationRole> >();

                    InitializeDb initializeDb = new InitializeDb();
                    initializeDb.Initialize(context, userManager, roleManager).Wait();

                    var serviceProvider = CreateService();

                    using (var migrationScope = serviceProvider.CreateScope())
                    {
                        UpdateDatabase(migrationScope.ServiceProvider);
                    }
                }
                catch (Exception ex)
                {
                    Log.Logger.Error(ex);
                }
            }

            host.Run();
        }
Пример #14
0
 protected override void Seed(AppDbContext context)
 {
     InitializeDb.InitializeBus(context);
 }
 public HttpResponseMessage GetReset()
 {
     InitializeDb.Initialize();
     return(Request.CreateResponse(HttpStatusCode.OK, "user created"));
 }
Пример #16
0
 protected override void Seed(Tripodea.BusDataAccess.BusContext context)
 {
     InitializeDb.Initialize(context);
 }
Пример #17
0
 static void Main(string[] args)
 {
     InitializeDb.Initize();
 }
Пример #18
0
 static void Main(string[] args)
 {
     InitializeDb.Initize();
     Console.WriteLine("Hello World!");
 }