diff --git a/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Services/ScheduledArchivingBackgroundTask.cs b/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Services/ScheduledArchivingBackgroundTask.cs index 46b86ee1bd7..8fed89fac5c 100644 --- a/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Services/ScheduledArchivingBackgroundTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Services/ScheduledArchivingBackgroundTask.cs @@ -14,7 +14,10 @@ namespace OrchardCore.ArchiveLater.Services; -[BackgroundTask(Schedule = "* * * * *", Description = "Archives content items when their scheduled archive date time arrives.")] +[BackgroundTask( + Title = "Content Items Archiver", + Schedule = "* * * * *", + Description = "Archives content items when their scheduled archive date time arrives.")] public class ScheduledArchivingBackgroundTask : IBackgroundTask { private readonly ILogger _logger; diff --git a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs index dca7360b570..41eb2e3f8a4 100644 --- a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs @@ -11,8 +11,10 @@ namespace OrchardCore.AuditTrail.Services { - [BackgroundTask(Schedule = "0 0 * * *", - Description = "A background task that regularly deletes old Audit Trail Events.", + [BackgroundTask( + Title = "Audit Trail Events Purger", + Schedule = "0 0 * * *", + Description = "Regularly purges old Audit Trail events.", LockTimeout = 3_000, LockExpiration = 30_000)] public class AuditTrailBackgroundTask : IBackgroundTask diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Controllers/BackgroundTaskController.cs b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Controllers/BackgroundTaskController.cs index 230a759da98..51b52b51fad 100644 --- a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Controllers/BackgroundTaskController.cs +++ b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Controllers/BackgroundTaskController.cs @@ -4,144 +4,117 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Localization; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Routing; +using Microsoft.CodeAnalysis; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; using OrchardCore.Admin; +using OrchardCore.BackgroundTasks.Models; using OrchardCore.BackgroundTasks.Services; using OrchardCore.BackgroundTasks.ViewModels; using OrchardCore.DisplayManagement; -using OrchardCore.Environment.Shell; +using OrchardCore.DisplayManagement.Notify; using OrchardCore.Navigation; +using OrchardCore.Routing; namespace OrchardCore.BackgroundTasks.Controllers { [Admin] public class BackgroundTaskController : Controller { - private readonly string _tenant; private readonly IAuthorizationService _authorizationService; private readonly IEnumerable _backgroundTasks; private readonly BackgroundTaskManager _backgroundTaskManager; private readonly PagerOptions _pagerOptions; - private readonly IStringLocalizer S; + private readonly INotifier _notifier; private readonly dynamic New; + private readonly IStringLocalizer S; + private readonly IHtmlLocalizer H; public BackgroundTaskController( - ShellSettings shellSettings, IAuthorizationService authorizationService, IEnumerable backgroundTasks, BackgroundTaskManager backgroundTaskManager, - IShapeFactory shapeFactory, IOptions pagerOptions, - IStringLocalizer stringLocalizer) + IShapeFactory shapeFactory, + IHtmlLocalizer htmlLocalizer, + IStringLocalizer stringLocalizer, + INotifier notifier) { - _tenant = shellSettings.Name; _authorizationService = authorizationService; _backgroundTasks = backgroundTasks; _backgroundTaskManager = backgroundTaskManager; _pagerOptions = pagerOptions.Value; + _notifier = notifier; New = shapeFactory; S = stringLocalizer; + H = htmlLocalizer; } - public async Task Index(PagerParameters pagerParameters) + public async Task Index(AdminIndexOptions options, PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageBackgroundTasks)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); var document = await _backgroundTaskManager.GetDocumentAsync(); - var taskEntries = _backgroundTasks.Select(t => - { - if (!document.Settings.TryGetValue(t.GetTaskName(), out var settings)) - { - settings = t.GetDefaultSettings(); - } - - return new BackgroundTaskEntry() { Settings = settings }; - }) - .OrderBy(entry => entry.Settings.Name) - .Skip(pager.GetStartIndex()) - .Take(pager.PageSize) - .ToList(); - - var pagerShape = (await New.Pager(pager)).TotalItemCount(_backgroundTasks.Count()); - - var model = new BackgroundTaskIndexViewModel - { - Tasks = taskEntries, - Pager = pagerShape - }; - - return View(model); - } + var items = _backgroundTasks.Select(task => new BackgroundTaskEntry() { Settings = GetSettings(task, document) }); - public async Task Create(string name) - { - if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageBackgroundTasks)) + if (!String.IsNullOrWhiteSpace(options.Search)) { - return Forbid(); + items = items.Where(x => x.Settings.Title.Contains(options.Search, StringComparison.OrdinalIgnoreCase) + || (x.Settings.Description != null && x.Settings.Description.Contains(options.Search, StringComparison.OrdinalIgnoreCase)) + ); } - var model = new BackgroundTaskViewModel() { Name = name }; - - var task = _backgroundTasks.GetTaskByName(name); - - if (task != null) + if (String.Equals(options.Status, "enabled", StringComparison.OrdinalIgnoreCase)) { - var settings = task.GetDefaultSettings(); - - model.Enable = settings.Enable; - model.Schedule = settings.Schedule; - model.DefaultSchedule = settings.Schedule; - model.Description = settings.Description; - model.LockTimeout = settings.LockTimeout; - model.LockExpiration = settings.LockExpiration; + items = items.Where(x => x.Settings.Enable); } - - return View(model); - } - - [HttpPost, ActionName("Create")] - public async Task CreatePost(BackgroundTaskViewModel model) - { - if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageBackgroundTasks)) + else if (String.Equals(options.Status, "disabled", StringComparison.OrdinalIgnoreCase)) { - return Forbid(); + items = items.Where(x => !x.Settings.Enable); } - if (ModelState.IsValid) + options.Statuses = new List() { - if (String.IsNullOrWhiteSpace(model.Name)) - { - ModelState.AddModelError(nameof(BackgroundTaskViewModel.Name), S["The name is mandatory."]); - } - } + new SelectListItem() { Text = S["Enabled"], Value = "enabled" }, + new SelectListItem() { Text = S["Disabled"], Value = "disabled" } + }; - if (ModelState.IsValid) - { - var settings = new BackgroundTaskSettings - { - Name = model.Name, - Enable = model.Enable, - Schedule = model.Schedule?.Trim(), - Description = model.Description, - LockTimeout = model.LockTimeout, - LockExpiration = model.LockExpiration - }; + var taskItems = items.ToList(); + var routeData = new RouteData(); + routeData.Values.Add($"{nameof(BackgroundTaskIndexViewModel.Options)}.{nameof(options.Search)}", options.Search); + routeData.Values.Add($"{nameof(BackgroundTaskIndexViewModel.Options)}.{nameof(options.Status)}", options.Status); - await _backgroundTaskManager.UpdateAsync(model.Name, settings); + var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pagerShape = (await New.Pager(pager)).TotalItemCount(taskItems.Count).RouteData(routeData); - return RedirectToAction(nameof(Index)); - } + var model = new BackgroundTaskIndexViewModel + { + Tasks = taskItems.OrderBy(entry => entry.Settings.Title).Skip(pager.GetStartIndex()).Take(pager.PageSize).ToList(), + Pager = pagerShape, + Options = options, + }; return View(model); } + [HttpPost, ActionName(nameof(Index))] + [FormValueRequired("submit.Filter")] + public ActionResult IndexFilterPOST(BackgroundTaskIndexViewModel model) + { + return RedirectToAction(nameof(Index), new RouteValueDictionary { + { $"{nameof(model.Options)}.{nameof(AdminIndexOptions.Search)}", model.Options.Search }, + { $"{nameof(model.Options)}.{nameof(AdminIndexOptions.Status)}", model.Options.Status }, + }); + } + public async Task Edit(string name) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageBackgroundTasks)) @@ -149,20 +122,21 @@ public async Task Edit(string name) return Forbid(); } - var document = await _backgroundTaskManager.GetDocumentAsync(); + var task = _backgroundTasks.GetTaskByName(name); - if (!document.Settings.ContainsKey(name)) + if (task == null) { - return RedirectToAction(nameof(Create), new { name }); + return NotFound(); } - var task = _backgroundTasks.GetTaskByName(name); + var document = await _backgroundTaskManager.GetDocumentAsync(); - var settings = document.Settings[name]; + var settings = GetSettings(task, document); var model = new BackgroundTaskViewModel { Name = name, + Title = settings.Title, Enable = settings.Enable, Schedule = settings.Schedule, DefaultSchedule = task?.GetDefaultSettings().Schedule, @@ -182,32 +156,30 @@ public async Task Edit(BackgroundTaskViewModel model) return Forbid(); } - if (ModelState.IsValid) + var task = _backgroundTasks.GetTaskByName(model.Name); + + if (task == null) { - if (String.IsNullOrWhiteSpace(model.Name)) - { - ModelState.AddModelError(nameof(BackgroundTaskViewModel.Name), S["The name is mandatory."]); - } + return NotFound(); } if (ModelState.IsValid) { - var settings = new BackgroundTaskSettings - { - Name = model.Name, - Enable = model.Enable, - Schedule = model.Schedule?.Trim(), - Description = model.Description, - LockTimeout = model.LockTimeout, - LockExpiration = model.LockExpiration - }; + var document = await _backgroundTaskManager.LoadDocumentAsync(); + + var settings = GetSettings(task, document); + + settings.Schedule = model.Schedule?.Trim(); + settings.LockTimeout = model.LockTimeout; + settings.LockExpiration = model.LockExpiration; await _backgroundTaskManager.UpdateAsync(model.Name, settings); + await _notifier.SuccessAsync(H["The task has been updated."]); + return RedirectToAction(nameof(Index)); } - // If we got this far, something failed, redisplay form return View(model); } @@ -219,6 +191,11 @@ public async Task Delete(string name) return Forbid(); } + if (String.IsNullOrWhiteSpace(name)) + { + return NotFound(); + } + var document = await _backgroundTaskManager.LoadDocumentAsync(); if (!document.Settings.ContainsKey(name)) @@ -228,6 +205,8 @@ public async Task Delete(string name) await _backgroundTaskManager.RemoveAsync(name); + await _notifier.SuccessAsync(H["The task has been deleted."]); + return RedirectToAction(nameof(Index)); } @@ -239,18 +218,22 @@ public async Task Enable(string name) return Forbid(); } - var document = await _backgroundTaskManager.LoadDocumentAsync(); + var task = _backgroundTasks.GetTaskByName(name); - if (!document.Settings.TryGetValue(name, out var settings)) + if (task == null) { - settings = _backgroundTasks.GetTaskByName(name)?.GetDefaultSettings(); + return NotFound(); } - if (settings != null) - { - settings.Enable = true; - await _backgroundTaskManager.UpdateAsync(name, settings); - } + var document = await _backgroundTaskManager.LoadDocumentAsync(); + + var settings = GetSettings(task, document); + + settings.Enable = true; + + await _backgroundTaskManager.UpdateAsync(name, settings); + + await _notifier.SuccessAsync(H["The task has been enabled."]); return RedirectToAction(nameof(Index)); } @@ -263,20 +246,36 @@ public async Task Disable(string name) return Forbid(); } - var document = await _backgroundTaskManager.LoadDocumentAsync(); + var task = _backgroundTasks.GetTaskByName(name); - if (!document.Settings.TryGetValue(name, out var settings)) + if (task == null) { - settings = _backgroundTasks.GetTaskByName(name)?.GetDefaultSettings(); + return NotFound(); } - if (settings != null) + var document = await _backgroundTaskManager.LoadDocumentAsync(); + + var settings = GetSettings(task, document); + + settings.Enable = false; + + await _backgroundTaskManager.UpdateAsync(name, settings); + + await _notifier.SuccessAsync(H["The task has been disabled."]); + + return RedirectToAction(nameof(Index)); + } + + private static BackgroundTaskSettings GetSettings(IBackgroundTask task, BackgroundTaskDocument document) + { + var name = task.GetTaskName(); + + if (document.Settings.ContainsKey(name)) { - settings.Enable = false; - await _backgroundTaskManager.UpdateAsync(name, settings); + return document.Settings[name]; } - return RedirectToAction(nameof(Index)); + return task.GetDefaultSettings(); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Models/BackgroundTaskDocument.cs b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Models/BackgroundTaskDocument.cs index b1c73a4eb5e..cef98c7754c 100644 --- a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Models/BackgroundTaskDocument.cs +++ b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Models/BackgroundTaskDocument.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using OrchardCore.Data.Documents; @@ -5,6 +6,6 @@ namespace OrchardCore.BackgroundTasks.Models { public class BackgroundTaskDocument : Document { - public Dictionary Settings { get; } = new Dictionary(); + public Dictionary Settings { get; } = new(StringComparer.OrdinalIgnoreCase); } } diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Startup.cs b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Startup.cs index f2429460ff4..0ddd1b21481 100644 --- a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Startup.cs @@ -41,24 +41,21 @@ public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilde pattern: _adminOptions.AdminUrlPrefix + "/BackgroundTasks", defaults: new { controller = backgroundTaskControllerName, action = nameof(BackgroundTaskController.Index) } ); - routes.MapAreaControllerRoute( - name: "BackgroundTasksCreate", - areaName: "OrchardCore.BackgroundTasks", - pattern: _adminOptions.AdminUrlPrefix + "/BackgroundTasks/Create/{name}", - defaults: new { controller = backgroundTaskControllerName, action = nameof(BackgroundTaskController.Create) } - ); + routes.MapAreaControllerRoute( name: "BackgroundTasksEdit", areaName: "OrchardCore.BackgroundTasks", pattern: _adminOptions.AdminUrlPrefix + "/BackgroundTasks/Edit/{name}", defaults: new { controller = backgroundTaskControllerName, action = nameof(BackgroundTaskController.Edit) } ); + routes.MapAreaControllerRoute( name: "BackgroundTasksEnable", areaName: "OrchardCore.BackgroundTasks", pattern: _adminOptions.AdminUrlPrefix + "/BackgroundTasks/Enable/{name}", defaults: new { controller = backgroundTaskControllerName, action = nameof(BackgroundTaskController.Enable) } ); + routes.MapAreaControllerRoute( name: "BackgroundTasksDisable", areaName: "OrchardCore.BackgroundTasks", diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/ViewModels/AdminIndexOptions.cs b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/ViewModels/AdminIndexOptions.cs new file mode 100644 index 00000000000..130825caf26 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/ViewModels/AdminIndexOptions.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc.Rendering; + +namespace OrchardCore.BackgroundTasks.ViewModels; + +public class AdminIndexOptions +{ + public string Search { get; set; } + + public string Status { get; set; } + public List Statuses { get; internal set; } +} diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/ViewModels/BackgroundTaskIndexViewModel.cs b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/ViewModels/BackgroundTaskIndexViewModel.cs index d11d640b544..0eec0564a9c 100644 --- a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/ViewModels/BackgroundTaskIndexViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/ViewModels/BackgroundTaskIndexViewModel.cs @@ -1,10 +1,16 @@ using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc.ModelBinding; namespace OrchardCore.BackgroundTasks.ViewModels { public class BackgroundTaskIndexViewModel { + public AdminIndexOptions Options { get; set; } + + [BindNever] public IList Tasks { get; set; } + + [BindNever] public dynamic Pager { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Create.cshtml b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Create.cshtml deleted file mode 100644 index 3fb29098618..00000000000 --- a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Create.cshtml +++ /dev/null @@ -1,73 +0,0 @@ -@model BackgroundTaskViewModel - -

@RenderTitleSegments(T["Edit Task Settings"])

- -
-
- - - -
-
-
- - - @T["The task on which this settings will apply."] -
- -
- - - @T["The task schedule as a cron expression."] -
- -
- - - -
- -
@T["Invalid lock timeout value in the advanced tab"]
-
@T["Invalid lock expiration value in the advanced tab"]
-
- -
-
- - - @T["The timeout in milliseconds to acquire a lock before executing the task atomically. Leave it to zero to not use any locking."] - @T["Ignored if there is no distributed lock feature enabled."] -
- -
- - - @T["The expiration in milliseconds of the lock acquired before executing the task atomically. Leave it to zero to not use any locking."] - @T["Ignored if there is no distributed lock feature enabled."] -
-
-
- -
- - - @T["Cancel"] -
-
- - diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Edit.cshtml index 114c4aba9dd..9bb82029049 100644 --- a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Edit.cshtml @@ -16,10 +16,11 @@
-
- - - @T["The task on which this settings will apply."] + +
+ + +
@@ -28,12 +29,6 @@ @T["The task schedule as a cron expression."]
-
- - - -
-
@T["Invalid lock timeout value in the advanced tab"]
@T["Invalid lock expiration value in the advanced tab"]
@@ -63,11 +58,10 @@ diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Index.cshtml b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Index.cshtml index 2067e45f89c..7c9e4f3e7d2 100644 --- a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Index.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Views/BackgroundTask/Index.cshtml @@ -1,43 +1,99 @@ @model BackgroundTaskIndexViewModel -@inject OrchardCore.Modules.ILocalClock LocalClock

@RenderTitleSegments(T["Background Tasks"])

-
@* the form is necessary to generate an antiforgery token for the delete action *@ + + - @if (Model.Tasks.Any()) - { -
    - @foreach (var settings in Model.Tasks.Select(t => t.Settings)) +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
      +
    • +
      +
      +
      +
      +
      + +
      +
      +
      +
    • + @if (Model.Tasks.Count > 0) + { + foreach (var settings in Model.Tasks.Select(t => t.Settings)) {
    • -
      -
      - @if (@settings.Enable) - { - @T["Disable"] - } - else - { - @T["Enable"] - } - +
      + +
      @T["Edit"] + + @if (settings.Enable) + { + @T["Disable"] + } + else + { + @T["Enable"] + }
      - - @settings.Name - @settings.Description
      + + @if (!String.IsNullOrWhiteSpace(settings.Description)) + { +
      +
      +

      @settings.Description

      +
      +
      + }
    • } -
    - } - else - { - - } + } + else + { +
  • +
    + @T["Nothing here! Your search returned no results."] +
    +
  • + } +
+
@await DisplayAsync(Model.Pager) + + + + diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Tasks/OpenIdBackgroundTask.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Tasks/OpenIdBackgroundTask.cs index 9e39de3fa57..1d6ac0b848f 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Tasks/OpenIdBackgroundTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Tasks/OpenIdBackgroundTask.cs @@ -10,7 +10,10 @@ namespace OrchardCore.OpenId.Tasks { - [BackgroundTask(Schedule = "*/30 * * * *", Description = "Performs various cleanup operations for OpenID-related features.")] + [BackgroundTask( + Title = "OpenID Cleaner", + Schedule = "*/30 * * * *", + Description = "Performs various cleanup operations for OpenID features.")] public class OpenIdBackgroundTask : IBackgroundTask { private readonly ILogger _logger; diff --git a/src/OrchardCore.Modules/OrchardCore.PublishLater/Services/ScheduledPublishingBackgroundTask.cs b/src/OrchardCore.Modules/OrchardCore.PublishLater/Services/ScheduledPublishingBackgroundTask.cs index 174bb887f12..06502c183b9 100644 --- a/src/OrchardCore.Modules/OrchardCore.PublishLater/Services/ScheduledPublishingBackgroundTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.PublishLater/Services/ScheduledPublishingBackgroundTask.cs @@ -13,7 +13,10 @@ namespace OrchardCore.PublishLater.Services; -[BackgroundTask(Schedule = "* * * * *", Description = "Publishes content items when their scheduled publish date time arrives.")] +[BackgroundTask( + Title = "Scheduled Content Items Publisher", + Schedule = "* * * * *", + Description = "Publishes content items when their scheduled publish date time arrives.")] public class ScheduledPublishingBackgroundTask : IBackgroundTask { private readonly ILogger _logger; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/IndexingBackgroundTask.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/IndexingBackgroundTask.cs index 629148bf77f..a0c0616adc0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/IndexingBackgroundTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/IndexingBackgroundTask.cs @@ -12,7 +12,10 @@ namespace OrchardCore.Search.Lucene /// /// This services is only registered from OrchardCore.Search.Lucene.Worker feature. /// - [BackgroundTask(Schedule = "* * * * *", Description = "Update lucene indexes.")] + [BackgroundTask( + Title = "Lucene Indexes Updater", + Schedule = "* * * * *", + Description = "Updates lucene indexes.")] public class IndexingBackgroundTask : IBackgroundTask { public Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken) diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Cache/SitemapCacheBackgroundTask.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Cache/SitemapCacheBackgroundTask.cs index 712049b402f..2c9b8498415 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Cache/SitemapCacheBackgroundTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Cache/SitemapCacheBackgroundTask.cs @@ -8,7 +8,10 @@ namespace OrchardCore.Sitemaps.Cache { - [BackgroundTask(Schedule = "*/5 * * * *", Description = "Cleanup sitemap cache files.")] + [BackgroundTask( + Title = "Sitemap Cache Cleaner", + Schedule = "*/5 * * * *", + Description = "Cleans up sitemap cache files.")] public class SitemapCacheBackgroundTask : IBackgroundTask { public async Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken) diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Timers/TimerBackgroundTask.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Timers/TimerBackgroundTask.cs index 645ee42efd8..22c0c1e0cab 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Timers/TimerBackgroundTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Timers/TimerBackgroundTask.cs @@ -7,7 +7,10 @@ namespace OrchardCore.Workflows.Timers { - [BackgroundTask(Schedule = "* * * * *", Description = "Trigger workflow timer events.")] + [BackgroundTask( + Title = "Timed Workflow Starter", + Schedule = "* * * * *", + Description = "Triggers timed workflow events.")] public class TimerBackgroundTask : IBackgroundTask { public Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken) diff --git a/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskAttribute.cs b/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskAttribute.cs index 08f7cbf6bd1..0e471b0a41c 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskAttribute.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskAttribute.cs @@ -5,6 +5,7 @@ namespace OrchardCore.BackgroundTasks [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] public class BackgroundTaskAttribute : Attribute { + public string Title { get; set; } public bool Enable { get; set; } = true; public string Schedule { get; set; } = "*/5 * * * *"; public string Description { get; set; } = String.Empty; diff --git a/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskExtensions.cs b/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskExtensions.cs index 9db626a60ff..39768477bd6 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskExtensions.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskExtensions.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -8,15 +9,16 @@ public static class BackgroundTaskExtensions { public static BackgroundTaskSettings GetDefaultSettings(this IBackgroundTask task) { - var type = task.GetType(); + var technicalName = task.GetTaskName(); - var attribute = type.GetCustomAttribute(); + var attribute = task.GetType().GetCustomAttribute(); if (attribute != null) { return new BackgroundTaskSettings { - Name = type.FullName, + Title = !String.IsNullOrWhiteSpace(attribute.Title) ? attribute.Title : technicalName, + Name = technicalName, Enable = attribute.Enable, Schedule = attribute.Schedule, Description = attribute.Description, @@ -25,12 +27,21 @@ public static BackgroundTaskSettings GetDefaultSettings(this IBackgroundTask tas }; } - return new BackgroundTaskSettings() { Name = type.FullName }; + return new BackgroundTaskSettings() + { + Name = technicalName, + Title = technicalName + }; } public static IBackgroundTask GetTaskByName(this IEnumerable tasks, string name) { - return tasks.LastOrDefault(t => t.GetTaskName() == name); + if (String.IsNullOrEmpty(name)) + { + return null; + } + + return tasks.LastOrDefault(task => String.Equals(task.GetTaskName(), name, StringComparison.OrdinalIgnoreCase)); } public static string GetTaskName(this IBackgroundTask task) diff --git a/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskSettings.cs b/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskSettings.cs index 7139b1f079e..2bd227bc469 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskSettings.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/BackgroundTaskSettings.cs @@ -4,6 +4,7 @@ namespace OrchardCore.BackgroundTasks { public class BackgroundTaskSettings { + public string Title { get; set; } public string Name { get; set; } = String.Empty; public bool Enable { get; set; } = true; public string Schedule { get; set; } = "* * * * *"; diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/IndexingBackgroundTask.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/IndexingBackgroundTask.cs index 3338409942b..1cb0d6abfc1 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/IndexingBackgroundTask.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/IndexingBackgroundTask.cs @@ -12,7 +12,12 @@ namespace OrchardCore.Search.Elasticsearch.Core.Services /// /// This services is only registered from OrchardCore.Search.Elasticsearch.Worker feature. /// - [BackgroundTask(Schedule = "* * * * *", Description = "Update Elasticsearch indexes.", LockTimeout = 1000, LockExpiration = 300000)] + [BackgroundTask( + Title = "Elasticsearch Indexes Updater", + Schedule = "* * * * *", + Description = "Updates Elasticsearch indexes.", + LockTimeout = 1000, + LockExpiration = 300000)] public class IndexingBackgroundTask : IBackgroundTask { public Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken)