Beispiel #1
0
        /// <summary>
        /// 安装数据库
        /// </summary>
        private void InstallDatabase()
        {
            try
            {
                var app_data = Server.AppDataPath();
                new DirectoryInfo(app_data).CreateIfNotExist();
                var lock_file = Path.Combine(app_data, "database_installed.json");

                if (!File.Exists(lock_file))
                {
                    //尝试创建数据表
                    EFManager.TryInstallDatabase <EntityDB>();
                    //写文件
                    var data = new
                    {
                        msg  = "数据库已经安装,要重新安装请删除这个文件并重启系统",
                        time = DateTime.Now
                    }.ToJson();
                    File.WriteAllText(lock_file, data, settting.SystemEncoding);
                }
            }
            catch (Exception e)
            {
                throw new Exception("尝试安装数据库失败", e);
            }
        }
Beispiel #2
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;
            }
        }