Ejemplo n.º 1
0
        public static IApplicationBuilder UseJobAgentConsoleToSqlServer(this IApplicationBuilder app, Action <MssqlConsoleOptionsConfigurer> configureOptions = null)
        {
            var evt           = new EventId(1, "Hangfire.HttpJob.Agent.MssqlConsole");
            var options       = app.ApplicationServices.GetService <IOptions <MssqlStorageOptions> >();
            var configurer    = new MssqlConsoleOptionsConfigurer(options.Value);
            var loggerFactory = app.ApplicationServices.GetService <ILoggerFactory>();
            var logger        = loggerFactory.CreateLogger <MssqlConsoleOptionsConfigurer>();

            try
            {
                configureOptions?.Invoke(configurer);
            }
            catch (Exception exception)
            {
                logger.LogCritical(evt, exception, "【Hangfire.HttpJob.Agent.MssqlConsole】 - Failed to configure Hangfire.HttpJob.Agent.MssqlConsole middleware");
            }

            JobStorageConfig.LocalJobStorageConfig = new JobStorageConfig
            {
                Type         = "sqlserver",
                HangfireDb   = options.Value?.HangfireDb,
                ExpireAtDays = options.Value?.ExpireAtDays
            };

            logger.LogInformation(evt, "【Hangfire.HttpJob.Agent.MssqlConsole】 - Registered MssqlConsole middleware Success!");

            return(app);
        }
Ejemplo n.º 2
0
        public static IApplicationBuilder UseJobAgentConsoleToSqlServer(this IApplicationBuilder app, Action <MssqlConsoleOptionsConfigurer> configureOptions = null)
        {
            var evt           = new EventId(1, "Hangfire.HttpJob.Agent.MssqlConsole");
            var options       = app.ApplicationServices.GetService <IOptions <MssqlStorageOptions> >();
            var configurer    = new MssqlConsoleOptionsConfigurer(options.Value);
            var loggerFactory = app.ApplicationServices.GetService <ILoggerFactory>();
            var logger        = loggerFactory.CreateLogger <MssqlConsoleOptionsConfigurer>();

            try
            {
                configureOptions?.Invoke(configurer);
            }
            catch (Exception exception)
            {
                logger.LogCritical(evt, exception, "【Hangfire.HttpJob.Agent.MssqlConsole】 - Failed to configure Hangfire.HttpJob.Agent.MssqlConsole middleware");
            }

            if (options.Value == null)
            {
                logger.LogCritical(evt, "【Hangfire.HttpJob.Agent.MssqlConsole】 - MssqlStorageOptions can not be null");
                return(app);
            }

            if (string.IsNullOrEmpty(options.Value.HangfireDb))
            {
                throw new ArgumentException(nameof(MssqlStorageOptions.HangfireDb));
            }

            logger.LogInformation(evt, "【Hangfire.HttpJob.Agent.MssqlConsole】 - Registered MssqlConsole middleware Success!");

            return(app);
        }
Ejemplo n.º 3
0
        public static IAppBuilder UseJobAgentConsoleToSqlServer(this IAppBuilder app, IServiceCollection services, Action <MssqlConsoleOptionsConfigurer> configureOptions = null)
#endif

        {
#if NETCORE
            var sp = app.ApplicationServices;
#else
            var sp         = services.BuildServiceProvider();//OWIN
            var configRoot = sp.GetRequiredService <IConfiguration>();
            services.Configure <MssqlStorageOptions>(configRoot.GetSection("JobAgent:HangfireConsole"));
            sp = services.BuildServiceProvider();//OWIN
#endif
            var evt           = new EventId(1, "Hangfire.HttpJob.Agent.MssqlConsole");
            var options       = sp.GetService <IOptions <MssqlStorageOptions> >();
            var configurer    = new MssqlConsoleOptionsConfigurer(options.Value);
            var loggerFactory = sp.GetService <ILoggerFactory>();
            var logger        = loggerFactory.CreateLogger <MssqlConsoleOptionsConfigurer>();
            try
            {
                configureOptions?.Invoke(configurer);
            }
            catch (Exception exception)
            {
                logger.LogCritical(evt, exception, "【Hangfire.HttpJob.Agent.MssqlConsole】 - Failed to configure Hangfire.HttpJob.Agent.MssqlConsole middleware");
            }

            JobStorageConfig.LocalJobStorageConfig = new JobStorageConfig
            {
                Type         = "sqlserver",
                HangfireDb   = options.Value?.HangfireDb,
                ExpireAtDays = options.Value?.ExpireAtDays
            };

            logger.LogInformation(evt, "【Hangfire.HttpJob.Agent.MssqlConsole】 - Registered MssqlConsole middleware Success!");

            return(app);
        }