-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTaskDashboard.razor.cs
More file actions
122 lines (101 loc) · 4.14 KB
/
TaskDashboard.razor.cs
File metadata and controls
122 lines (101 loc) · 4.14 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace BootstrapBlazor.Components.Tasks;
/// <summary>
/// Task Dashboard Component
/// </summary>
public partial class TaskDashboard
{
[Inject, NotNull]
private IStringLocalizer<TaskDashboard>? Localizer { get; set; }
[Inject, NotNull]
private DialogService? DialogService { get; set; }
private string? ClassString => CssBuilder.Default("bb-tasks-dashboard")
.AddClassFromAttributes(AdditionalAttributes)
.Build();
private IEnumerable<IScheduler> _schedulers = [];
/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnParametersSet()
{
base.OnParametersSet();
_schedulers = TaskServicesManager.ToList();
}
private static Color GetStatusColor(SchedulerStatus status) => status switch
{
SchedulerStatus.Running => Color.Success,
SchedulerStatus.Ready => Color.Primary,
_ => Color.Danger
};
private string FormatStatus(SchedulerStatus status) => status switch
{
SchedulerStatus.Running => Localizer["SchedulerStatus.Running"],
SchedulerStatus.Ready => Localizer["SchedulerStatus.Ready"],
_ => Localizer["SchedulerStatus.Disabled"]
};
private static string GetStatusIcon(SchedulerStatus status) => status switch
{
SchedulerStatus.Running => "fa-solid fa-play-circle",
SchedulerStatus.Ready => "fa-solid fa-stop-circle",
_ => "fa-solid fa-times-circle"
};
private static Color GetResultColor(TriggerResult result) => result switch
{
TriggerResult.Running => Color.Primary,
TriggerResult.Success => Color.Success,
TriggerResult.Cancelled => Color.Dark,
TriggerResult.Timeout => Color.Warning,
_ => Color.Danger,
};
private string FormatResult(TriggerResult result) => result switch
{
TriggerResult.Running => Localizer["TriggerResult.Running"],
TriggerResult.Success => Localizer["TriggerResult.Success"],
TriggerResult.Cancelled => Localizer["TriggerResult.Timeout"],
TriggerResult.Timeout => Localizer["TriggerResult.Timeout"],
_ => Localizer["TriggerResult.Error"],
};
private static Task OnPause(IScheduler scheduler)
{
scheduler.Status = SchedulerStatus.Ready;
return Task.CompletedTask;
}
private static Task OnRun(IScheduler scheduler)
{
scheduler.Status = SchedulerStatus.Running;
return Task.CompletedTask;
}
private async Task OnLog(IScheduler scheduler)
{
var option = new DialogOption()
{
Class = "modal-dialog-task-log",
Title = Localizer["LogDialogTitle", scheduler.Name],
Component = BootstrapDynamicComponent.CreateComponent<TaskInfo>(new Dictionary<string, object?>
{
[nameof(TaskInfo.Scheduler)] = scheduler,
[nameof(TaskInfo.HeaderText)] = Localizer["LogDialogConsoleHeaderText"].Value
})
};
await DialogService.Show(option);
}
private static bool OnCheckPauseTaskStatus(IScheduler model) => model.Status != SchedulerStatus.Running;
private static bool OnCheckRunTaskStatus(IScheduler model) => model.Status == SchedulerStatus.Running;
private static string? FormatDateTime(DateTimeOffset? dateTime) => dateTime?.ToString("yyyy-MM-dd HH:mm:ss");
private async Task OnShowException(IScheduler scheduler, Exception ex)
{
var option = new DialogOption()
{
Class = "modal-dialog-task-ex",
IsScrolling = true,
Title = Localizer["ExceptionDialogTitle", scheduler.Name],
BodyTemplate = RenderException(ex)
};
await DialogService.Show(option);
}
private static RenderFragment RenderException(Exception ex) => builder => builder.AddContent(0, ex.FormatMarkupString());
}