Esempio n. 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);
            }
        }
Esempio n. 2
0
        public void OnChange()
        {
            var cfg_name = this.Name + "_EF_Edmx";
            var cfg      = System.Configuration.ConfigurationManager.AppSettings[cfg_name];

            if (cfg == null)
            {
                DBGlobalService.EFConceptualModels = null;
                DBGlobalService.EFStorageModels    = null;
                return;
            }

            if (!System.IO.File.Exists(cfg))
            {
                DBGlobalService.EFConceptualModels = null;
                DBGlobalService.EFStorageModels    = null;
                return;
            }

            EF.StorageModels.Schema    ef_storage = new EF.StorageModels.Schema();
            EF.ConceptualModels.Schema ef_concept = new EF.ConceptualModels.Schema();
            EF.Mappings.Mapping        mapping    = new EF.Mappings.Mapping();
            try
            {
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.Load(cfg);
                var schema_storage = doc.ChildNodes[1].ChildNodes[1].ChildNodes[1].ChildNodes[0];
                ef_storage.Parse(schema_storage);

                var schema_concept = doc.ChildNodes[1].ChildNodes[1].ChildNodes[3].ChildNodes[0];
                ef_concept.Parse(schema_concept);

                var mappingNode = doc.ChildNodes[1].ChildNodes[1].ChildNodes[5].ChildNodes[0];
                mapping.Parse(mappingNode);

                DBGlobalService.EFStorageModels    = ef_storage;
                DBGlobalService.EFConceptualModels = ef_concept;
                DBGlobalService.EFMappings         = mapping;

                EFManager.Instance().Reset();
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message);
                return;
            }
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
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;
            }
        }
Esempio n. 7
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;
            }
        }