Esempio n. 1
0
        private static void CreateManagmentJob()
        {
            DashboardRoutes.Routes.AddRazorPage(JobExtensionPage.PageRoute, x => new JobExtensionPage());
            DashboardRoutes.Routes.AddRazorPage(JobsStoppedPage.PageRoute, x => new JobsStoppedPage());

            DashboardRoutes.Routes.Add("/jobs/GetJobsStopped", new GetJobsStoppedDispatcher());
            DashboardRoutes.Routes.Add("/JobConfiguration/GetJobs", new GetJobDispatcher());
            DashboardRoutes.Routes.Add("/JobConfiguration/UpdateJobs", new ChangeJobDispatcher());
            DashboardRoutes.Routes.Add("/JobConfiguration/GetJob", new GetJobForEdit());
            DashboardRoutes.Routes.Add("/JobConfiguration/JobAgent", new JobAgentDispatcher());
            DashboardRoutes.Routes.Add("/DataConfiguration/GetTimeZones", new GetTimeZonesDispatcher());

            DashboardMetrics.AddMetric(TagDashboardMetrics.JobsStoppedCount);
            JobsSidebarMenu.Items.Add(page => new MenuItem("Jobs Stopped", page.Url.To("/jobs/stopped"))
            {
                Active = page.RequestPath.StartsWith("/jobs/stopped"),
                Metric = TagDashboardMetrics.JobsStoppedCount,
            });

            NavigationMenu.Items.Add(page => new MenuItem(JobExtensionPage.Title, page.Url.To("/JobConfiguration"))
            {
                Active = page.RequestPath.StartsWith(JobExtensionPage.PageRoute),
                Metric = DashboardMetrics.RecurringJobCount
            });

            AddDashboardRouteToEmbeddedResource("/JobConfiguration/js/page", "application/js", "Hangfire.RecurringJobAdmin.Dashboard.Content.js.jobextension.js");
            AddDashboardRouteToEmbeddedResource("/JobConfiguration/js/vue", "application/js", "Hangfire.RecurringJobAdmin.Dashboard.Content.js.vue.js");
            AddDashboardRouteToEmbeddedResource("/JobConfiguration/js/axio", "application/js", "Hangfire.RecurringJobAdmin.Dashboard.Content.js.axios.min.js");
            AddDashboardRouteToEmbeddedResource("/JobConfiguration/js/daysjs", "application/js", "Hangfire.RecurringJobAdmin.Dashboard.Content.js.daysjs.min.js");
            AddDashboardRouteToEmbeddedResource("/JobConfiguration/js/relativeTime", "application/js", "Hangfire.RecurringJobAdmin.Dashboard.Content.js.relativeTime.min.js");
            AddDashboardRouteToEmbeddedResource("/JobConfiguration/js/vuejsPaginate", "application/js", "Hangfire.RecurringJobAdmin.Dashboard.Content.js.vuejs-paginate.js");
            AddDashboardRouteToEmbeddedResource("/JobConfiguration/js/sweetalert", "application/js", "Hangfire.RecurringJobAdmin.Dashboard.Content.js.sweetalert.js");
            AddDashboardRouteToEmbeddedResource("/JobConfiguration/css/jobExtension", "text/css", "Hangfire.RecurringJobAdmin.Dashboard.Content.css.JobExtension.css");
        }
Esempio n. 2
0
        /// <summary>
        /// Configures Hangfire to use Tags.
        /// </summary>
        /// <param name="configuration">Global configuration</param>
        /// <param name="options">Options for tags</param>
        /// <param name="jobStorage">Job storage</param>
        /// <returns></returns>
        public static IGlobalConfiguration UseTags(this IGlobalConfiguration configuration, TagsOptions options = null, JobStorage jobStorage = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            TagsOptions.Options = options ?? new TagsOptions {
                Storage = JobStorage.Current as ITagsServiceStorage
            };

            if (options != null && jobStorage != null)
            {
                TagsOptions.OptionsDictionary.Add(jobStorage.ToString(), options);
            }

            if (TagsOptions.Options.Storage == null)
            {
                throw new ApplicationException("The specified storage is not suitable for use with tags");
            }

            if (DashboardRoutes.Routes.FindDispatcher("/tags/(.*)") != null)
            {
                throw new InvalidOperationException("Tags are already initialized");
            }

            // Register server filter for jobs, to clean up after ourselves
            GlobalJobFilters.Filters.Add(new TagsCleanupStateFilter(), int.MaxValue);
            GlobalJobFilters.Filters.Add(new CreateJobFilter(), int.MaxValue);

            DashboardRoutes.Routes.AddRazorPage("/tags/search", x => new TagsSearchPage());
            DashboardRoutes.Routes.AddRazorPage("/tags/search/.+", x => new TagsJobsPage());
            DashboardRoutes.Routes.Add("/tags/all", new TagsDispatcher(TagsOptions.Options));
            DashboardRoutes.Routes.Add("/tags/([0-9a-z\\-]+)", new JobTagsDispatcher(TagsOptions.Options));

            DashboardMetrics.AddMetric(TagDashboardMetrics.TagsCount);

            if (!JobsSidebarMenu.Items.Contains(TagsMenuItemInitializer))
            {
                JobsSidebarMenu.Items.Add(TagsMenuItemInitializer);
            }

            var assembly = typeof(GlobalConfigurationExtensions).Assembly;

            var jsPath = DashboardRoutes.Routes.Contains("/js[0-9]+") ? "/js[0-9]+" : "/js[0-9]{3}";

            DashboardRoutes.Routes.Append(jsPath, new EmbeddedResourceDispatcher(assembly, "Hangfire.Tags.Resources.jquery.tagcloud.js"));
            DashboardRoutes.Routes.Append(jsPath, new EmbeddedResourceDispatcher(assembly, "Hangfire.Tags.Resources.script.js"));

            var cssPath = DashboardRoutes.Routes.Contains("/css[0-9]+") ? "/css[0-9]+" : "/css[0-9]{3}";

            DashboardRoutes.Routes.Append(cssPath, new EmbeddedResourceDispatcher(assembly, "Hangfire.Tags.Resources.style.css"));
            DashboardRoutes.Routes.Append(cssPath, new DynamicCssDispatcher(TagsOptions.Options));
            return(configuration);
        }
Esempio n. 3
0
        public static IGlobalConfiguration UseDashboardMetric(
            [NotNull] this IGlobalConfiguration configuration,
            [NotNull] DashboardMetric metric)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            if (metric == null)
            {
                throw new ArgumentNullException("metric");
            }

            DashboardMetrics.AddMetric(metric);
            HomePage.Metrics.Add(metric);

            return(configuration);
        }