Exemplo n.º 1
0
 public static IEndpointConventionBuilder MapHangfireDashboard(
     [NotNull] this IEndpointRouteBuilder endpoints,
     [CanBeNull] DashboardOptions options = null,
     [CanBeNull] JobStorage storage       = null)
 {
     return(MapHangfireDashboard(endpoints, "/hangfire", options, storage));
 }
Exemplo n.º 2
0
        public static IEndpointConventionBuilder MapHangfireDashboard(
            [NotNull] this IEndpointRouteBuilder endpoints,
            [NotNull] string pattern,
            [CanBeNull] DashboardOptions options = null,
            [CanBeNull] JobStorage storage       = null)
        {
            if (endpoints == null)
            {
                throw new ArgumentNullException(nameof(endpoints));
            }
            if (pattern == null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            var app = endpoints.CreateApplicationBuilder();

            HangfireServiceCollectionExtensions.ThrowIfNotConfigured(app.ApplicationServices);

            var services = app.ApplicationServices;

            storage = storage ?? services.GetRequiredService <JobStorage>();
            options = options ?? services.GetService <DashboardOptions>() ?? new DashboardOptions();
            options.TimeZoneResolver = options.TimeZoneResolver ?? services.GetService <ITimeZoneResolver>();

            var routes = app.ApplicationServices.GetRequiredService <Dashboard.RouteCollection>();

            var pipeline = app
                           .UsePathBase(pattern)
                           .UseMiddleware <AspNetCoreDashboardMiddleware>(storage, options, routes)
                           .Build();

            return(endpoints.Map(pattern + "/{**path}", pipeline));
        }
        public static IEndpointConventionBuilder MapHangfireDashboardWithAuthorizationPolicy(
            [NotNull] this IEndpointRouteBuilder endpoints,
            [NotNull] string authorizationPolicyName,
            [NotNull] string pattern             = "/hangfire",
            [CanBeNull] DashboardOptions options = null,
            [CanBeNull] JobStorage storage       = null)
        {
            if (endpoints == null)
            {
                throw new ArgumentNullException(nameof(endpoints));
            }
            if (authorizationPolicyName == null)
            {
                throw new ArgumentNullException(nameof(authorizationPolicyName));
            }

            options = options ?? new DashboardOptions();

            // We don't require the default LocalRequestsOnlyAuthorizationFilter since we provide our own policy
            options.Authorization      = Enumerable.Empty <IDashboardAuthorizationFilter>();
            options.AsyncAuthorization = Enumerable.Empty <IDashboardAsyncAuthorizationFilter>();

            return(endpoints
                   .MapHangfireDashboard(pattern, options, storage)
                   .RequireAuthorization(authorizationPolicyName));
        }
Exemplo n.º 4
0
        public void Configuration(IAppBuilder app)
        {

            var authorizationFilter = new BasicAuthAuthorizationFilter(
                                new BasicAuthAuthorizationFilterOptions
                                {
                                    // Require secure connection for dashboard
                                    RequireSsl = true,
                                    // Case sensitive login checking
                                    LoginCaseSensitive = true,
                                    // Users
                                    Users = new[]
                                    {
                                        new BasicAuthAuthorizationUser
                                        {
                                            Login = "******",
                                            PasswordClear = "passW0rd!"
                                        }
                                    }
                                });

            var options = new DashboardOptions
            {
                AuthorizationFilters = new IAuthorizationFilter[]
                {
                    authorizationFilter
                }
            };
            GlobalConfiguration.Configuration.UseSqlServerStorage("DefaultConnection");

            app.UseHangfireDashboard("/hangfire", options);
            app.UseHangfireServer();

            ConfigureAuth(app);
        }
Exemplo n.º 5
0
        public void ConfigureOwin(IAppBuilder app, IUnityContainer container)
        {
            JobStorage.Current = CreateJobStorage(Stage.ConfigureOwin);

            // Configure Hangfire dashboard

            var securityService = container.Resolve<ISecurityService>();
            var moduleInitializerOptions = container.Resolve<IModuleInitializerOptions>();

            var appPath = "/" + moduleInitializerOptions.RoutePrefix;

            var authorizationFilters = new[]
            {
                    new PermissionBasedAuthorizationFilter(securityService)
                    {
                        Permission = PredefinedPermissions.BackgroundJobsManage
                    }
                };

            var dashboardOptions = new DashboardOptions
            {
                AppPath = appPath,
                AuthorizationFilters = authorizationFilters
            };

            app.UseHangfireDashboard(appPath + "hangfire", dashboardOptions);

            // Configure Hangfire server
            if (_options.StartServer)
            {
                app.UseHangfireServer(new BackgroundJobServerOptions { Activator = new UnityJobActivator(container) });
            }
        }
Exemplo n.º 6
0
      public void ConfigureHangFire(IAppBuilder app)
      {
         var storageOptions = new SqlServerStorageOptions
         {
            InvisibilityTimeout = TimeSpan.FromHours(2),
            QueuePollInterval = TimeSpan.FromMinutes(15.0)
         };
         GlobalConfiguration.Configuration
            .UseSqlServerStorage("TrainingManagerDb", storageOptions);

         // case msmq installed
         /*GlobalConfiguration.Configuration
            .UseSqlServerStorage("TrainingManagerDb")
            .UseMsmqQueues(@".\hangfire-{0}");*/



         var dashboardOptions = new DashboardOptions
         {
            AuthorizationFilters = new[] { new AuthorizationFilter { Roles = AppConstants.UserRole.Administrator } }
         };
         app.UseHangfireDashboard("/hangfire", dashboardOptions);


         var jobServerOptions = new BackgroundJobServerOptions
         {
            WorkerCount = 1
         };
         app.UseHangfireServer(jobServerOptions);

         RecurringJob.AddOrUpdate(() => UpdateDaemon.ScheduledCatalogsUpdate(), Cron.Hourly);
      }
Exemplo n.º 7
0
        public void Configuration(IAppBuilder app)
        {
            HangfireConfiguration.Register();

            var options = new DashboardOptions
            {
                AuthorizationFilters = new []
                {
                    new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
                    {
                        RequireSsl = true,
                        LoginCaseSensitive = true,
                        Users = new []
                        {
                            new BasicAuthAuthorizationUser
                            {
                                Login = "******",
                                PasswordClear = "D3v3L0pM3nT"
                            }
                        }
                    }),
                }
            };

            app.UseHangfireDashboard("/hangfire", options);
            app.UseHangfireServer();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Adds Dashboard UI middleware to the OWIN request processing pipeline under
 /// the specified path and the given options, for the <see cref="JobStorage.Current"/>
 /// storage.
 /// </summary>
 /// <param name="builder">OWIN application builder.</param>
 /// <param name="pathMatch">Path prefix for middleware to use, e.g. "/hangfire".</param>
 /// <param name="options">Options for Dashboard UI.</param>
 ///
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="pathMatch"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="options"/> is null.</exception>
 ///
 /// <remarks>
 /// Please see <see cref="AppBuilderExtensions"/> for details and examples.
 /// </remarks>
 public static IAppBuilder UseHangfireDashboard(
     [NotNull] this IAppBuilder builder,
     [NotNull] string pathMatch,
     [NotNull] DashboardOptions options)
 {
     return(builder.UseHangfireDashboard(pathMatch, options, JobStorage.Current));
 }
        public static IApplicationBuilder UseHangfireDashboard(
            [NotNull] this IApplicationBuilder app,
            [NotNull] string pathMatch           = "/hangfire",
            [CanBeNull] DashboardOptions options = null,
            [CanBeNull] JobStorage storage       = null)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (pathMatch == null)
            {
                throw new ArgumentNullException(nameof(pathMatch));
            }

            HangfireServiceCollectionExtensions.ThrowIfNotConfigured(app.ApplicationServices);

            var services = app.ApplicationServices;

            storage = storage ?? services.GetRequiredService <JobStorage>();
            options = options ?? services.GetService <DashboardOptions>() ?? new DashboardOptions();
            options.TimeZoneResolver = options.TimeZoneResolver ?? services.GetService <ITimeZoneResolver>();

            var routes = app.ApplicationServices.GetRequiredService <RouteCollection>();

            app.Map(new PathString(pathMatch), x => x.UseMiddleware <AspNetCoreDashboardMiddleware>(storage, options, routes));

            return(app);
        }
Exemplo n.º 10
0
        public static IAppBuilder UseHangfireDashboard(
            [NotNull] this IAppBuilder builder,
            [NotNull] string pathMatch,
            [NotNull] DashboardOptions options,
            [NotNull] JobStorage storage)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }
            if (pathMatch == null)
            {
                throw new ArgumentNullException("pathMatch");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            SignatureConversions.AddConversions(builder);

            builder.Map(pathMatch, subApp => subApp
                        .UseOwin()
                        .UseHangfireDashboard(options, storage, DashboardRoutes.Routes));

            return(builder);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Adds Dashboard UI middleware to the OWIN request processing pipeline with the
        /// specified parameters and antiforgery service.
        /// </summary>
        /// <param name="builder">OWIN application builder.</param>
        /// <param name="pathMatch">Path prefix for middleware to use, e.g. "/hangfire".</param>
        /// <param name="options">Options for Dashboard UI.</param>
        /// <param name="storage">Job storage to use by Dashboard IO.</param>
        /// <param name="antiforgery">Antiforgery service.</param>
        ///
        /// <exception cref="ArgumentNullException"><paramref name="builder"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="pathMatch"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="storage"/> is null.</exception>
        ///
        /// <remarks>
        /// Please see <see cref="AppBuilderExtensions"/> for details and examples.
        /// </remarks>
        public static IAppBuilder UseHangfireDashboard(
            [NotNull] this IAppBuilder builder,
            [NotNull] string pathMatch,
            [NotNull] DashboardOptions options,
            [NotNull] JobStorage storage,
            [CanBeNull] IOwinDashboardAntiforgery antiforgery)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (pathMatch == null)
            {
                throw new ArgumentNullException(nameof(pathMatch));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }

            SignatureConversions.AddConversions(builder);

            builder.Map(pathMatch, subApp => subApp
                        .UseOwin()
                        .UseHangfireDashboard(options, storage, DashboardRoutes.Routes, antiforgery));

            return(builder);
        }
Exemplo n.º 12
0
 public static IEndpointConventionBuilder MapHangfireDashboardWithAuthorizationPolicy(
     [NotNull] this IEndpointRouteBuilder endpoints,
     [NotNull] string authorizationPolicyName,
     [CanBeNull] DashboardOptions options = null,
     [CanBeNull] JobStorage storage       = null)
 {
     return(MapHangfireDashboardWithAuthorizationPolicy(endpoints, authorizationPolicyName, "/hangfire", options, storage));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Adds Dashboard UI middleware to the OWIN request processing pipeline with the
 /// specified parameters.
 /// </summary>
 /// <param name="builder">OWIN application builder.</param>
 /// <param name="pathMatch">Path prefix for middleware to use, e.g. "/hangfire".</param>
 /// <param name="options">Options for Dashboard UI.</param>
 /// <param name="storage">Job storage to use by Dashboard IO.</param>
 ///
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="pathMatch"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="options"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="storage"/> is null.</exception>
 ///
 /// <remarks>
 /// Please see <see cref="AppBuilderExtensions"/> for details and examples.
 /// </remarks>
 public static IAppBuilder UseHangfireDashboard(
     [NotNull] this IAppBuilder builder,
     [NotNull] string pathMatch,
     [NotNull] DashboardOptions options,
     [NotNull] JobStorage storage)
 {
     return(builder.UseHangfireDashboard(pathMatch, options, storage, null));
 }
Exemplo n.º 14
0
            // Install the Hangfire.Dashboard.Authorization NuGet package first.

            public void Configuration(IAppBuilder app)
            {
                // GlobalConfiguration usage was removed for clarity.
                var options = new DashboardOptions
                {
                    AuthorizationFilters = new [] 
                    {
                        new AuthorizationFilter { Roles = "admin" },
                    }
                };

                app.UseHangfireDashboard("/hangfire", options);
            }
        public static IApplicationBuilder UseHangfireDashboard(this IApplicationBuilder builder, IServiceInfo serviceInfo)
        {
            var options = new DashboardOptions
            {
                AppPath        = $"/{serviceInfo.ShortName}/hangfire",
                DashboardTitle = $"{serviceInfo.Description}任务控制台",
                DisplayStorageConnectionString = false
            };

            builder.UseHangfireDashboard($"/{serviceInfo.ShortName}/hangfire", options);

            return(builder);
        }
Exemplo n.º 16
0
        public static IApplicationBuilder UseHangfireDashboard(
            [NotNull] this IApplicationBuilder app,
            [CanBeNull] string pathMatch = "/hangfire",
            [CanBeNull] Action <DashboardOptions> setup = null,
            [CanBeNull] JobStorage storage = null)
        {
            Check.NotNull(app, nameof(app));

            var options = new DashboardOptions();

            setup?.Invoke(options);

            return(app.UseHangfireDashboard(pathMatch: pathMatch, options: options, storage: storage));
        }
        public static DashboardOptions UseAuthorizations(
            [NotNull] this DashboardOptions options,
            [NotNull] IEnumerable <IDashboardAuthorizationFilter> authorizationFilters)
        {
            Check.NotNull(options, nameof(options));
            Check.NotNull(authorizationFilters, nameof(authorizationFilters));

            List <IDashboardAuthorizationFilter> filters = new List <IDashboardAuthorizationFilter>();

            filters.AddRange(authorizationFilters);

            options.Authorization = filters;

            return(options);
        }
        public static DashboardOptions AddAuthorization(
            [NotNull] this DashboardOptions options,
            [NotNull] IDashboardAuthorizationFilter authorizationFilter)
        {
            Check.NotNull(options, nameof(options));
            Check.NotNull(authorizationFilter, nameof(authorizationFilter));

            List <IDashboardAuthorizationFilter> filters = new List <IDashboardAuthorizationFilter>();

            filters.AddRange(options.Authorization);
            filters.AddIfNotContains(authorizationFilter);

            options.Authorization = filters;

            return(options);
        }
        public static DashboardOptions UseAuthorization(
            [NotNull] this DashboardOptions options,
            [NotNull] IDashboardAuthorizationFilter authorizationFilter)
        {
            Check.NotNull(options, nameof(options));
            Check.NotNull(authorizationFilter, nameof(authorizationFilter));

            List <IDashboardAuthorizationFilter> filters = new List <IDashboardAuthorizationFilter>
            {
                authorizationFilter
            };

            options.Authorization = filters;

            return(options);
        }
Exemplo n.º 20
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
            GlobalConfiguration.Configuration.UseSqlServerStorage("HangFireDB");

            var options = new DashboardOptions
            {
                AuthorizationFilters = new []
                {
                    new ClaimsBasedAuthorizationFilter(ClaimTypes.Role, "Admin")
                }
            };
            app.UseHangfireDashboard("/hangfire", options);
            app.UseHangfireServer();

            RecurringJob.AddOrUpdate(() => SessionCounter.CreateTables(), Cron.Daily);
            RecurringJob.AddOrUpdate(() => SessionCounter.RegisterUserSessions(), Cron.Minutely);
        }
Exemplo n.º 21
0
        public static IEndpointConventionBuilder MapHangfireDashboardWithAuthorizationPolicy(
            [NotNull] this IEndpointRouteBuilder endpoints,
            [NotNull] string authorizationPolicyName,
            [NotNull] string pattern,
            [CanBeNull] DashboardOptions options = null,
            [CanBeNull] JobStorage storage       = null)
        {
            if (options == null)
            {
                options = new DashboardOptions()
                {
                    Authorization = new List <IDashboardAuthorizationFilter>() // We don't require the default LocalHost only filter since we provide our own policy
                };
            }

            return(endpoints
                   .MapHangfireDashboard(pattern, options, storage)
                   .RequireAuthorization(authorizationPolicyName));
        }
Exemplo n.º 22
0
        public void Configuration(IAppBuilder app)
        {
            var options = new DashboardOptions
            {
                AuthorizationFilters = new[]
            {
                new LocalRequestsOnlyAuthorizationFilter()
            }
            };

            app.UseHangfireDashboard("/hangfire", options);

            /*
            app.UseHangfire(config =>
            {
                config.UseSqlServerStorage("DbConnection");
                config.UseServer();
            });

            app.UseHangfireServer();*/
        }
Exemplo n.º 23
0
        public void Configuration(IAppBuilder app)
        {
            var options = new DashboardOptions
            {
                AppPath = VirtualPathUtility.ToAbsolute("~"),
                AuthorizationFilters = new[]
            {

                new HangFireAuthorizationFilter()
            }
            };

            app.UseHangfireDashboard("/private/hangfire", options);
            app.UseHangfireServer();

            //InfoPageConfigurator.Configure(app,
            //        x =>
            //        {
            //            x.BaseUrl = "custom-info";
            //            x.ApplicationName = "WLOG";
            //        });
        }
        public static IApplicationBuilder UseHangfireDashboard(this IApplicationBuilder builder, IServiceInfo serviceInfo, params Authorize[] authorize)
        {
            var options = new DashboardOptions
            {
                AppPath        = $"/{serviceInfo.ShortName}/hangfire",
                DashboardTitle = $"{serviceInfo.Description}任务控制台",
                DisplayStorageConnectionString = false
            };

            if (authorize.Any())
            {
                options.Authorization = authorize.Select(s =>
                                                         new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
                {
                    Users = new[] { new BasicAuthAuthorizationUser {
                                        Login = s.Login, PasswordClear = s.Password
                                    } }
                })).ToArray();
            }
            builder.UseHangfireDashboard($"/{serviceInfo.ShortName}/hangfire", options);

            return(builder);
        }
Exemplo n.º 25
0
 public void Configuration(IAppBuilder app)
 {
     // GlobalConfiguration usage was removed for clarity.
     var options = new DashboardOptions { AppPath = "/app" };
     app.UseHangfireDashboard("/hangfire", options);
 }