private static void CreateAndInitializeDatabaseIfNotExists(string schema)
        {
            var recreateDatabaseSql = String.Format(
                @"if db_id('{0}') is null create database [{0}] COLLATE SQL_Latin1_General_CP1_CS_AS",
                ConnectionUtils.GetDatabaseName());

            using (var conn = ConnectionUtils.GetMasterConnection())
            {
                conn.Execute(recreateDatabaseSql);
            }

            using (var conn = ConnectionUtils.GetDatabaseConnection())
            {
                SqlServerObjectsInstaller.Install(conn, schema);
            }
        }
Exemple #2
0
        private static void RecreateDatabaseAndInstallObjects()
        {
            var recreateDatabaseSql = String.Format(
                @"if db_id('{0}') is null create database [{0}]",
                ConnectionUtils.GetDatabaseName());

            using (var connection = new SqlConnection(
                       ConnectionUtils.GetMasterConnectionString()))
            {
                connection.Execute(recreateDatabaseSql);
            }

            using (var connection = new SqlConnection(
                       ConnectionUtils.GetConnectionString()))
            {
                SqlServerObjectsInstaller.Install(connection);
            }
        }
Exemple #3
0
        public override void UseModule(IApplicationBuilder app)
        {
            if (!_enabled)
            {
                return;
            }

            IServiceProvider provider = app.ApplicationServices;

            var quartzOptions = provider.GetRequiredService <QuartzOptions>();

            if (quartzOptions.StorageType.Equals(QuartzStorageType.InMemory))
            {
                // 初始化数据库
                MySqlObjectsInstaller.Initialize(quartzOptions.ConnectionStringOrCacheName, quartzOptions.TablePrefix);
            }
            if (quartzOptions.StorageType.Equals(QuartzStorageType.SqlServer))
            {
                // 初始化SqlServer数据库
                SqlServerObjectsInstaller.Initialize(quartzOptions.ConnectionStringOrCacheName, quartzOptions.TablePrefix);
            }

            var scheduler = provider.GetService <IScheduler>();

            //:jobFactory quartz.net Execute 使用依赖注入
            //scheduler.JobFactory = jobFactory ?? throw new InvalidOperationException(
            //        "You must be config used message queue provider at AddQuartz() options!   eg: services.AddQuartz(options=>{ options.UseInMemory(...) })");

            scheduler.JobFactory = new JobFactory(provider);

            //LogProvider.SetCurrentLogProvider(loggingProvider);

            var liveLogPlugin = new LiveLogPlugin(provider);

            scheduler.ListenerManager.AddJobListener(liveLogPlugin);
            scheduler.ListenerManager.AddTriggerListener(liveLogPlugin);
            scheduler.ListenerManager.AddSchedulerListener(liveLogPlugin);

            scheduler.Start().Wait();

            //var lifetime = provider.GetService<IApplicationLifetime>();
            //lifetime.ApplicationStarted.Register(() =>
            //{
            //    scheduler.Start().Wait(); //网站启动完成执行
            //});

            //lifetime.ApplicationStopped.Register(() =>
            //{
            //    scheduler.Shutdown().Wait(); //网站停止完成执行
            //});

            //var dashboardQuartzOptions = provider.GetService<DashboardQuartzOptions>();

            //if (dashboardQuartzOptions == null) return;

            //app.UseDashboard(dashboardQuartzOptions);

            var Configuration = provider.GetService <IHybridStartupConfiguration>();

            Configuration.Localization.Sources.Add(
                new DictionaryBasedLocalizationSource(
                    LocalizationConsts.QuartzSourceName,
                    new JsonEmbeddedFileLocalizationDictionaryProvider(
                        typeof(QuartzModuleBase).GetAssembly(), "Hybrid.Quartz.Dashboard.Localization.Sources.JsonSource"
                        )));

            app.UseSignalR(routes =>
            {
                //这里要说下,为啥地址要写 /api/xxx
                //如果你不用/api/xxx的这个规则的话,会出现跨域问题,毕竟这个不是我的MVC的路由,而且自己定义的路由
                routes.MapHub <LiveLogHub>("/api/liveLogHub");
            });

            base.UseModule(app);
        }