forked from tracstarr/Hangfire.Core.Dashboard.Management
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGlobalConfigurationExtension.cs
49 lines (41 loc) · 2.11 KB
/
GlobalConfigurationExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Hangfire.Core.Dashboard.Management.Pages;
using Hangfire.Core.Dashboard.Management.Support;
using Hangfire.Dashboard;
namespace Hangfire.Core.Dashboard.Management
{
public static class GlobalConfigurationExtension
{
public static void UseManagementPages(this IGlobalConfiguration config, Assembly assembly)
{
JobsHelper.GetAllJobs(assembly);
CreateManagement();
}
private static void CreateManagement()
{
foreach (var pageInfo in JobsHelper.Pages)
{
ManagementBasePage.AddCommands(pageInfo.Queue);
ManagementSidebarMenu.Items.Add(p => new MenuItem(pageInfo.MenuName, p.Url.To($"{ManagementPage.UrlRoute}/{pageInfo.Queue}"))
{
Active = p.RequestPath.StartsWith($"{ManagementPage.UrlRoute}/{pageInfo.Queue}")
});
DashboardRoutes.Routes.AddRazorPage($"{ManagementPage.UrlRoute}/{pageInfo.Queue}", x => new ManagementBasePage(pageInfo.Title, pageInfo.Title, pageInfo.Queue));
}
//note: have to use new here as the pages are dispatched and created each time. If we use an instance, the page gets duplicated on each call
DashboardRoutes.Routes.AddRazorPage(ManagementPage.UrlRoute, x => new ManagementPage());
// can't use the method of Hangfire.Console as it's usage overrides any similar usage here. Thus
// we have to add our own endpoint to load it and call it from our code. Actually is a lot less work
DashboardRoutes.Routes.Add("/jsm", new EmbeddedResourceDispatcher(Assembly.GetExecutingAssembly(), "Hangfire.Core.Dashboard.Management.Content.management.js"));
NavigationMenu.Items.Add(page => new MenuItem(ManagementPage.Title, page.Url.To(ManagementPage.UrlRoute))
{
Active = page.RequestPath.StartsWith(ManagementPage.UrlRoute)
});
}
}
}