public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var userManager  = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    var context      = services.GetRequiredService <AppDbContext>();
                    DBInitializer.InitializeAsync(userManager, rolesManager, context).Wait();

                    //var log4NetConfig = new XmlDocument();
                    //log4NetConfig.Load(File.OpenRead("log4net.config"));
                    //var repo = LogManager.CreateRepository(Assembly.GetEntryAssembly(),
                    //    typeof(log4net.Repository.Hierarchy.Hierarchy));
                    //XmlConfigurator.Configure(repo, log4NetConfig["log4net"]);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            host.Run();
        }
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

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

                try
                {
                    var userManager   = services.GetRequiredService <UserManager <User> >();
                    var rolesManager  = services.GetRequiredService <RoleManager <IdentityRole> >();
                    var canvasService = services.GetRequiredService <ICanvasService>();
                    var config        = services.GetRequiredService <IConfiguration>();
                    await DBInitializer.InitializeAsync(userManager, rolesManager, canvasService, config);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Startup> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
Esempio n. 3
0
        public static async Task <IServiceProvider> InitializeAsync(ApplicationArguments args)
        {
            var services = ConfigureServices();

            var loggerFactory = services.GetRequiredService <ILoggerFactory>();

            loggerFactory.AddNLog(new NLogProviderOptions {
                CaptureMessageTemplates = true, CaptureMessageProperties = true
            });
            LogManager.Configuration = SetupNLogConfig();

            var logger = services.GetService <ILogger <MonkeyClient> >();

            var client = services.GetService <DiscordSocketClient>();
            await client.LoginAsync(TokenType.Bot, (await DiscordClientConfiguration.LoadAsync().ConfigureAwait(false)).Token).ConfigureAwait(false);

            await client.StartAsync().ConfigureAwait(false);

            var manager = services.GetService <CommandManager>();
            await manager.StartAsync().ConfigureAwait(false);

            var dbContext = services.GetRequiredService <MonkeyDBContext>();
            await DBInitializer.InitializeAsync(dbContext).ConfigureAwait(false);

            var announcements = services.GetService <IAnnouncementService>();
            await announcements.InitializeAsync().ConfigureAwait(false);

            var steamGameServerService = services.GetService <SteamGameServerService>();

            steamGameServerService.Initialize();

            var minecraftGameServerService = services.GetService <MineCraftGameServerService>();

            minecraftGameServerService.Initialize();

            var gameSubscriptionService = services.GetService <IGameSubscriptionService>();

            gameSubscriptionService.Initialize();

            var roleButtonsService = services.GetService <IRoleButtonService>();

            roleButtonsService.Initialize();

            var feedService = services.GetService <IFeedService>();

            feedService.Start();

            var battlefieldNewsService = services.GetService <IBattlefieldNewsService>();

            battlefieldNewsService.Start();

            if (args != null && args.BuildDocumentation)
            {
                await manager.BuildDocumentationAsync().ConfigureAwait(false); // Write the documentation

                logger.LogInformation("Documentation built");
            }

            return(services);
        }
Esempio n. 4
0
        public static async Task <IServiceProvider> InitializeAsync(ApplicationArguments args)
        {
            IServiceProvider services = ConfigureServices(loggingBuilder =>
            {
                _ = loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
                _ = loggingBuilder.AddNLog(SetupNLogConfig());
            });

            DiscordSocketClient client = services.GetService <DiscordSocketClient>();
            string token = (await DiscordClientConfiguration.LoadAsync().ConfigureAwait(false)).Token;
            await client.LoginAsync(TokenType.Bot, token).ConfigureAwait(false);

            await client.StartAsync().ConfigureAwait(false);

            CommandManager manager = services.GetService <CommandManager>();
            await manager.StartAsync().ConfigureAwait(false);

            MonkeyDBContext dbContext = services.GetRequiredService <MonkeyDBContext>();
            await DBInitializer.InitializeAsync(dbContext).ConfigureAwait(false);

            IAnnouncementService announcements = services.GetService <IAnnouncementService>();
            await announcements.InitializeAsync().ConfigureAwait(false);

            SteamGameServerService steamGameServerService = services.GetService <SteamGameServerService>();

            steamGameServerService.Initialize();

            MineCraftGameServerService minecraftGameServerService = services.GetService <MineCraftGameServerService>();

            minecraftGameServerService.Initialize();

            IGameSubscriptionService gameSubscriptionService = services.GetService <IGameSubscriptionService>();

            gameSubscriptionService.Initialize();

            IRoleButtonService roleButtonsService = services.GetService <IRoleButtonService>();

            roleButtonsService.Initialize();

            IFeedService feedService = services.GetService <IFeedService>();

            feedService.Start();

            IBattlefieldNewsService battlefieldNewsService = services.GetService <IBattlefieldNewsService>();

            battlefieldNewsService.Start();

            if (args != null && args.BuildDocumentation)
            {
                await manager.BuildDocumentationAsync().ConfigureAwait(false); // Write the documentation

                await Console.Out.WriteLineAsync("Documentation built").ConfigureAwait(false);
            }

            return(services);
        }
Esempio n. 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              EntityContext context,
                              RoleManager <AppRole> roleManager,
                              UserManager <AppUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

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

            app.UseAuthentication();

            DBInitializer.InitializeAsync(app, context, userManager, roleManager).Wait();

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

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

            //app.UseMvc(routes =>
            //{
            //    routes.MapRoute(
            //        name: "default",
            //        template: "{controller}/{action=Index}/{id?}");
            //});
        }
Esempio n. 6
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <ApplicationDbContext>();
                    DBInitializer.InitializeAsync(context, services).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            host.Run();
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();//.Run();

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

                try
                {
                    //Static Method
                    DBInitializer.InitializeAsync(services).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured creating the DB.");
                }
            }

            host.Run();
        }//end Main method
Esempio n. 8
0
        private static async Task StartServicesAsync(IServiceProvider services)
        {
            MonkeyDBContext dbContext = services.GetRequiredService <MonkeyDBContext>();
            await DBInitializer.InitializeAsync(dbContext);

            IReminderService reminders = services.GetService <IReminderService>();
            await reminders.InitializeAsync();

            SteamGameServerService steamGameServerService = services.GetService <SteamGameServerService>();

            steamGameServerService.Initialize();

            MineCraftGameServerService minecraftGameServerService = services.GetService <MineCraftGameServerService>();

            minecraftGameServerService.Initialize();

            IRoleDropdownService roleButtonsService = services.GetService <IRoleDropdownService>();
            await roleButtonsService.InitializeAsync();

            IFeedService feedService = services.GetService <IFeedService>();

            feedService.Start();

            IBattlefieldNewsService battlefieldNewsService = services.GetService <IBattlefieldNewsService>();

            battlefieldNewsService.Start();

            IGiveAwaysService giveAwaysService = services.GetService <IGiveAwaysService>();

            giveAwaysService.Start();

            IPollService pollService = services.GetService <IPollService>();
            await pollService.InitializeAsync();

            return;
        }
Esempio n. 9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              BrainStormDbContext context,
                              RoleManager <BrainStormRole> roleManager,
                              UserManager <BrainStormUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseHealthChecks("/health");

                // When the app runs in the Development environment:
                //   Use the Developer Exception Page to report app runtime errors.
                //   Use the Database Error Page to report database runtime errors.
                app.UseDeveloperExceptionPage();
                // app.UseDatabaseErrorPage();
            }
            else
            {
                // When the app doesn't run in the Development environment:
                //   Enable the Exception Handler Middleware to catch exceptions
                //     thrown in the following middlewares.
                //   Use the HTTP Strict Transport Security Protocol (HSTS)
                //     Middleware.
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            // Use HTTPS Redirection Middleware to redirect HTTP requests to HTTPS.
            app.UseHttpsRedirection();
            // Return static files and end the pipeline.
            app.UseStaticFiles();
            // Use Cookie Policy Middleware to conform to EU General Data
            // Protection Regulation (GDPR) regulations.
            app.UseCookiePolicy();

            app.UseRouting();
            // Authenticate before the user accesses secure resources.
            app.UseAuthentication();
            app.UseAuthorization();


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub <ChatHub>("/chat");

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });

            app.UseSpaStaticFiles();

            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

            // Add MVC to the request pipeline.

            DBInitializer.InitializeAsync(app, context, userManager, roleManager).Wait();

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }