示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <ApplicationUser, IdentityRole>(opts =>
            {
                opts.User.RequireUniqueEmail         = true;
                opts.SignIn.RequireConfirmedEmail    = false;
                opts.Password.RequiredLength         = 6;
                opts.Password.RequireNonAlphanumeric = true;
                opts.Password.RequireLowercase       = true;
                opts.Password.RequireUppercase       = true;
                opts.Password.RequireDigit           = true;
            }).AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.AddTransient <IUserContactManager, UserContactManager>();
            services.AddTransient <IMailingManager, MailingManager>();

            // Add application services.
            services.AddTransient <IEmailSender, EmailSender>();

            //services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => {options.LoginPath = new Microsoft.AspNetCore.Http.PathString("/Account/Login");});

            services.AddMvc();

            // Quartz jobs

            MailingScheduler.Start();
        }
示例#2
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Debug("init main");
                var host = BuildWebHost(args);
                using (var scope = host.Services.CreateScope())
                {
                    var serviceProvider = scope.ServiceProvider;
                    try
                    {
                        var userManager     = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                        var roleManager     = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                        var operatorManager = serviceProvider.GetRequiredService <IOperatorManager>();
                        var codeManager     = serviceProvider.GetRequiredService <ICodeManager>();
                        var tariffManager   = serviceProvider.GetRequiredService <ITariffManager>();
                        var stopWordManager = serviceProvider.GetRequiredService <IStopWordManager>();
                        var unitOfWork      = serviceProvider.GetRequiredService <IUnitOfWork>();

                        IdentityDataInitializer.SeedData(userManager, roleManager, operatorManager, codeManager, tariffManager, stopWordManager, unitOfWork);

                        // Start Notification scheduler

                        NotificationScheduler.Start(scope.ServiceProvider);
                        MailingScheduler.Start(scope.ServiceProvider);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Stopped program because of exception");
                    }
                }
                host.Run();
            }
            catch (Exception ex)
            {
                //NLog: catch setup errors
                logger.Error(ex, "Stopped program because of exception");
                throw;
            }
            finally
            {
                // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
                NLog.LogManager.Shutdown();
            }
        }