예제 #1
0
        protected void Application_Start()
        {
            try
            {
                var start = DateTime.Now;

                //添加依赖注入
                AppContext.AddExtraRegistrar(new FullDependencyRegistrar());

                //disable "X-AspNetMvc-Version" header name
                MvcHandler.DisableMvcResponseHeader = true;
                AreaRegistration.RegisterAllAreas();
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                //用AutoFac接管控制器生成,从而实现依赖注入
                //ControllerBuilder.Current.SetControllerFactory(typeof(AutoFacControllerFactory));
                //使用autofac生成控制器
                DependencyResolver.SetResolver(new AutofacDependencyResolver(AppContext.Container));
                //加速首次启动EF
                //EFManager.SelectDB(null).FastStart();
                EFManager.FastStart <EntityDB>();

                start_up_task = Task.Run(() =>
                {
                    //启动后台服务
                    TaskManager.InitTasks();
                    //do something else
                });

                //记录程序开始
                $"Application_Start|耗时:{(DateTime.Now - start).TotalSeconds}秒".SaveInfoLog(this.GetType());
                //"记录数据库的日志".AddBusinessInfoLog();
            }
            catch (Exception e)
            {
                e.SaveLog("网站启动异常");
                throw e;
            }
        }
예제 #2
0
        protected void Application_Start()
        {
            try
            {
                Action <long, string> logger = (ms, name) =>
                {
                    $"{nameof(Application_Start)}|耗时:{ms}毫秒".AddBusinessInfoLog();
                };
                using (var timer = new CpuTimeLogger(logger))
                {
                    /*
                     * if (!("config_1.json", "config_2.json").SameJsonStructure())
                     * {
                     *  throw new Exception("正式机和测试机配置文件结构不相同");
                     * }*/

                    //添加依赖注入
                    IocContext.Instance.AddExtraRegistrar(new CommonDependencyRegister());
                    IocContext.Instance.AddExtraRegistrar(new FullDependencyRegistrar());
                    IocContext.Instance.OnContainerBuilding += (ref ContainerBuilder builder) =>
                    {
                        builder.UseAccountSystem <UserLoginService>();
                        //builder.AuthUseAuthServerValidation(() => new AuthServerConfig() { });
                        builder.AuthUseLoginStatus(() => new LoginStatus($"auth_user_uid", $"auth_user_token", $"auth_user_session"));
                        builder.AuthUseValidationDataProvider <AppOrWebAuthDataProvider>();
                        builder.AuthClientUseCustomValidation <AuthBasicValidationProvider>();
                        //auth 功能逻辑
                        builder.AuthUseServerApiAccessService <AuthApiServiceFromDB_>();
                    };

                    //disable "X-AspNetMvc-Version" header name
                    MvcHandler.DisableMvcResponseHeader = true;
                    AreaRegistration.RegisterAllAreas();
                    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                    RouteConfig.RegisterRoutes(RouteTable.Routes);
                    //用AutoFac接管控制器生成,从而实现依赖注入
                    //ControllerBuilder.Current.SetControllerFactory(typeof(AutoFacControllerFactory));
                    //使用autofac生成控制器
                    DependencyResolver.SetResolver(IocContext.Instance.Container.AutofacDependencyResolver_());

                    try
                    {
                        //断网的情况下这里不会抛异常,会长时间等待
                        Policy.Timeout(TimeSpan.FromSeconds(6), TimeoutStrategy.Pessimistic).Execute(() =>
                        {
                            //加速首次启动EF
                            //EFManager.SelectDB(null).FastStart();
                            EFManager.FastStart <EntityDB>();
                            //SSO数据库
                            //EFManager.FastStart<SSODB>();
                        });
                    }
                    catch (Exception err)
                    {
                        throw new Exception("设置EF快速启动失败", err);
                    }

#if DEBUG
                    //安装数据库
                    this.InstallDatabase();
#endif

                    //启动后台服务
                    TaskManager.Start();
                }
            }
            catch (Exception e)
            {
                e.AddErrorLog("网站启动异常");
                throw e;
            }
        }
예제 #3
0
        protected void Application_Start()
        {
            try
            {
                Action <long, string> logger = (ms, name) =>
                {
                    $"{nameof(Application_Start)}|耗时:{ms}毫秒".AddBusinessInfoLog();
                };
                using (var timer = new CpuTimeLogger(logger))
                {
                    /*
                     * if (!("config_1.json", "config_2.json").SameJsonStructure())
                     * {
                     *  throw new Exception("正式机和测试机配置文件结构不相同");
                     * }*/

                    //添加依赖注入
                    IocContext.Instance.AddExtraRegistrar(new CommonDependencyRegister());
                    IocContext.Instance.AddExtraRegistrar(new FullDependencyRegistrar());
                    IocContext.Instance.OnContainerBuilding += (ref ContainerBuilder builder) =>
                    {
                        Func <LoginStatus> CookieProvider = () => new LoginStatus($"auth_user_uid", $"auth_user_token", $"auth_user_session");

                        var server_host = string.Empty;
                        if (ValidateHelper.IsPlumpString(server_host))
                        {
                            builder.AuthBasicServerConfig <AuthLoginProvider>(() => new AuthServerConfig(server_host), CookieProvider);
                        }
                        else
                        {
                            builder.AuthBasicConfig <AuthLoginProvider, AuthApiService>(CookieProvider);
                        }
                    };

                    //disable "X-AspNetMvc-Version" header name
                    MvcHandler.DisableMvcResponseHeader = true;
                    AreaRegistration.RegisterAllAreas();
                    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                    RouteConfig.RegisterRoutes(RouteTable.Routes);
                    //用AutoFac接管控制器生成,从而实现依赖注入
                    //ControllerBuilder.Current.SetControllerFactory(typeof(AutoFacControllerFactory));
                    //使用autofac生成控制器
                    DependencyResolver.SetResolver(IocContext.Instance.Container.AutofacDependencyResolver_());

                    try
                    {
                        //断网的情况下这里不会抛异常,会长时间等待
                        Policy.Timeout(TimeSpan.FromSeconds(10), TimeoutStrategy.Pessimistic).Execute(() =>
                        {
                            //加速首次启动EF
                            EFManager.FastStart <EntityDB>();
                            EFManager.FastStart <EpcEntityDB>();
                        });
                    }
                    catch (Exception err)
                    {
                        throw new Exception("设置EF快速启动失败", err);
                    }

#if DEBUG
                    //安装数据库
                    this.InstallDatabase();
#endif

                    //启动后台服务
                    TaskManager.Start();
                }
            }
            catch (Exception e)
            {
                e.AddErrorLog("网站启动异常");
                throw e;
            }
        }
예제 #4
0
        protected void Application_Start()
        {
            try
            {
                Action <long, string> logger = (ms, name) =>
                {
                    $"Application_Start|耗时:{ms}毫秒".AddInfoLog(this.GetType());
                };
                using (var timer = new CpuTimeLogger(logger))
                {
                    /*
                     * if (!("config_1.json", "config_2.json").SameJsonStructure())
                     * {
                     *  throw new Exception("正式机和测试机配置文件结构不相同");
                     * }*/

                    //添加依赖注入
                    AppContext.AddExtraRegistrar(new CommonDependencyRegister());
                    AppContext.AddExtraRegistrar(new FullDependencyRegistrar());
                    AppContext.OnContainerBuilding = (ref ContainerBuilder builder) =>
                    {
                        builder.RegisterType <QipeilongLoginService>().AsSelf().AsImplementedInterfaces().SingleInstance();
                        //builder.AuthUseAuthServerValidation(() => new AuthServerConfig() { });
                        //new LoginStatus("hiwjcn_uid", "hiwjcn_token", "hiwjcn_login_session", "")
                        //builder.AuthClientUseCookieValidation(() => new LoginStatus("hiwjcn_uid", "hiwjcn_token", "hiwjcn_login_session", ""));

                        builder.AuthUseLoginStatus(() => new LoginStatus("hiwjcn_uid", "hiwjcn_token", "hiwjcn_session", ""));
                        builder.AuthUseValidationDataProvider <WebValidationDataProvider>();
                        builder.AuthClientUseCustomValidation <AuthLocalValidationProvider>();
                    };

                    //disable "X-AspNetMvc-Version" header name
                    MvcHandler.DisableMvcResponseHeader = true;
                    AreaRegistration.RegisterAllAreas();
                    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                    RouteConfig.RegisterRoutes(RouteTable.Routes);
                    //用AutoFac接管控制器生成,从而实现依赖注入
                    //ControllerBuilder.Current.SetControllerFactory(typeof(AutoFacControllerFactory));
                    //使用autofac生成控制器
                    DependencyResolver.SetResolver(AppContext.Container.AutofacDependencyResolver());

                    //加速首次启动EF
                    //EFManager.SelectDB(null).FastStart();
                    EFManager.FastStart <EntityDB>();
                    //汽配龙数据库
                    EFManager.FastStart <Core.Data.QipeilongDbContext>();
                    //尝试创建数据表
                    EFManager.TryInstallDatabase <EntityDB>();

                    start_up_task = Task.Run(() =>
                    {
                        //启动后台服务
                        TaskManager.StartAllTasks(new Assembly[] { typeof(CleanDatabaseTask).Assembly });
                        //do something else
                    });
                }
            }
            catch (Exception e)
            {
                e.AddLog("网站启动异常");
                throw e;
            }
        }
예제 #5
0
        protected void Application_Start()
        {
            try
            {
                Action <long, string> logger = (ms, name) =>
                {
                    $"{nameof(Application_Start)}|耗时:{ms}毫秒".AddBusinessInfoLog();
                };
                using (var timer = new CpuTimeLogger(logger))
                {
                    /*
                     * if (!("config_1.json", "config_2.json").SameJsonStructure())
                     * {
                     *  throw new Exception("正式机和测试机配置文件结构不相同");
                     * }*/

                    //添加依赖注入
                    AppContext.AddExtraRegistrar(new CommonDependencyRegister());
                    AppContext.AddExtraRegistrar(new FullDependencyRegistrar());
                    AppContext.OnContainerBuilding = (ref ContainerBuilder builder) =>
                    {
                        //sso
                        //builder.Register(_ => new LoginStatus("auth_sso_uid", "auth_sso_token", "auth_sso_session", "")).Named<LoginStatus>("sso").SingleInstance();
                        //builder.RegisterType<SSOValidationProvider>().Named<TokenValidationProviderBase>("sso").SingleInstance();
                        var account_system = string.Empty;
                        account_system = ConfigurationManager.AppSettings[nameof(account_system)] ?? "未知账号体系";

                        if (account_system == nameof(AccountSystemEnum.UserInfo))
                        {
                            builder.UseAccountSystem <QPLUserLoginService>();
                        }
                        else if (account_system == nameof(AccountSystemEnum.SalesInfo))
                        {
                            builder.UseAccountSystem <QPLSalesLoginService>();
                        }
                        else
                        {
                            throw new Exception($"不支持的账号体系:{account_system}");
                        }
                        //builder.AuthUseAuthServerValidation(() => new AuthServerConfig() { });
                        //new LoginStatus("hiwjcn_uid", "hiwjcn_token", "hiwjcn_login_session", "")
                        //builder.AuthClientUseCookieValidation(() => new LoginStatus("hiwjcn_uid", "hiwjcn_token", "hiwjcn_login_session", ""));

                        builder.AuthUseLoginStatus(() => new LoginStatus($"auth_{account_system}_uid", $"auth_{account_system}_token", $"auth_{account_system}_session"));
                        builder.AuthUseValidationDataProvider <AppOrWebTokenProvider>();
                        builder.AuthClientUseCustomValidation <AuthBasicValidationProvider>();
                        //auth 功能逻辑
                        builder.AuthUseServerApiAccessService <AuthApiServiceFromDB>();
                    };

                    //disable "X-AspNetMvc-Version" header name
                    MvcHandler.DisableMvcResponseHeader = true;
                    AreaRegistration.RegisterAllAreas();
                    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                    RouteConfig.RegisterRoutes(RouteTable.Routes);
                    //用AutoFac接管控制器生成,从而实现依赖注入
                    //ControllerBuilder.Current.SetControllerFactory(typeof(AutoFacControllerFactory));
                    //使用autofac生成控制器
                    DependencyResolver.SetResolver(AppContext.Container.AutofacDependencyResolver_());

                    try
                    {
                        //断网的情况下这里不会抛异常,会长时间等待
                        Policy.Timeout(TimeSpan.FromSeconds(6), TimeoutStrategy.Pessimistic).Execute(() =>
                        {
                            //加速首次启动EF
                            //EFManager.SelectDB(null).FastStart();
                            EFManager.FastStart <EntityDB>();
                            //汽配龙数据库
                            EFManager.FastStart <QPLEntityDB>();
                            //SSO数据库
                            EFManager.FastStart <SSODB>();
                        });
                    }
                    catch (Exception err)
                    {
                        throw new Exception("设置EF快速启动失败", err);
                    }

#if DEBUG
                    //安装数据库
                    this.InstallDatabase();
#endif

                    //启动后台服务
                    TaskManager.StartAllTasks(new Assembly[] { typeof(CleanDatabaseTask).Assembly });
                }
            }
            catch (Exception e)
            {
                e.AddErrorLog("网站启动异常");
                throw e;
            }
        }