1- using Blazorise ;
2- using Microsoft . AspNetCore . Components ;
3- using Microsoft . Extensions . Localization ;
4- using Syrna . QuartzAdmin . Blazor . Components ;
5- using Syrna . QuartzAdmin . ExecutionLog ;
6- using Syrna . QuartzAdmin . ExecutionLog . Dtos ;
7- using Syrna . QuartzAdmin . Localization ;
8- using System . Collections . ObjectModel ;
9- using System . Linq ;
10- using System . Text ;
11- using System . Threading . Tasks ;
12-
13- namespace Syrna . QuartzAdmin . Blazor . Pages . QuartzAdmin . Schedules ;
14-
1+ using Blazorise ;
2+ using Microsoft . AspNetCore . Components ;
3+ using Microsoft . Extensions . Localization ;
4+ using Syrna . QuartzAdmin . Blazor . Components ;
5+ using Syrna . QuartzAdmin . ExecutionLog ;
6+ using Syrna . QuartzAdmin . ExecutionLog . Dtos ;
7+ using Syrna . QuartzAdmin . Localization ;
8+ using System . Collections . ObjectModel ;
9+ using System . Linq ;
10+ using System . Text ;
11+ using System . Threading . Tasks ;
12+
13+ namespace Syrna . QuartzAdmin . Blazor . Pages . QuartzAdmin . Schedules ;
14+
1515public partial class HistoryDialog
16- {
16+ {
1717 [ Inject ] protected new IStringLocalizer < QuartzAdminResource > L { get ; set ; }
18- [ Inject ] private IExecutionLogAppService LogSvc { get ; set ; } = null ! ;
19-
20- [ EditorRequired ]
21- public Key JobKey { get ; set ; } = null ! ;
22-
23- [ EditorRequired ]
24- public Key TriggerKey { get ; set ; }
25-
26- private ObservableCollection < ExecutionLogDto > ExecutionLogs { get ; } = new ( ) ;
27- private bool HasMore { get ; set ; }
28-
29- private PageMetadata _lastPageMeta ;
30- private long _firstLogId ;
18+ [ Inject ] private IExecutionLogAppService LogSvc { get ; set ; } = null ! ;
19+
20+ [ EditorRequired ]
21+ public Key JobKey { get ; set ; } = null ! ;
22+
23+ [ EditorRequired ]
24+ public Key TriggerKey { get ; set ; }
25+
26+ private ObservableCollection < ExecutionLogDto > ExecutionLogs { get ; } = new ( ) ;
27+ private bool HasMore { get ; set ; }
28+
29+ private PageMetadata _lastPageMeta ;
30+ private long _firstLogId ;
3131 Modal modalRef ;
3232
3333 public HistoryDialog ( )
3434 {
3535 LocalizationResource = typeof ( QuartzAdminResource ) ;
3636 }
37-
38- public async Task OpenModalAsync ( Key jobKey , Key triggerKey )
39- {
40- JobKey = jobKey ;
41- TriggerKey = triggerKey ;
42- await modalRef . Show ( ) ;
43- await OnRefreshHistory ( ) ;
44- }
45-
46- protected async Task Close ( )
47- {
48- await modalRef . Hide ( ) ;
49- }
50-
51- private async Task GetMoreLogs ( )
52- {
53- PageMetadata pageMeta ;
54- if ( _lastPageMeta == null )
55- {
56- pageMeta = PageMetadata . New ( 0 , 5 ) ;
57- }
58- else
59- {
60- pageMeta = new PageMetadata { Page = _lastPageMeta . Page + 1 , PageSize = _lastPageMeta . PageSize , TotalCount = _lastPageMeta . TotalCount } ;
61- }
62- LatestExecutionLogReadArgs latestExecutionLogReadArgs = new ( )
63- {
64- JobName = JobKey . Name ,
65- JobGroup = JobKey . Group ?? Constants . DEFAULT_GROUP ,
66- TriggerName = TriggerKey ? . Name ,
67- TriggerGroup = TriggerKey ? . Group ,
68- PageMetadata = pageMeta ,
69- FirstLogId = _firstLogId
70- } ;
71- var result = await LogSvc . GetLatestExecutionLog ( latestExecutionLogReadArgs ) ;
72- var items = result . Items . ToList ( ) ;
73- if ( pageMeta . Page == 0 )
74- {
75- _firstLogId = items . FirstOrDefault ( ) ? . Id ?? 0 ;
76- }
77-
78- items . ForEach ( ExecutionLogs . Add ) ;
79-
80- HasMore = result . TotalCount == pageMeta . PageSize ;
81- }
82-
83- private async Task OnRefreshHistory ( )
84- {
85- ExecutionLogs . Clear ( ) ;
86- _lastPageMeta = null ;
87- _firstLogId = 0 ;
88- HasMore = false ;
89-
90- await GetMoreLogs ( ) ;
91- }
92-
93- ExecutionDetailsDialog ExecutionDetailsDialogRef ;
94- private async Task OnMoreDetails ( ExecutionLogDto log , string titleSuffix )
95- {
96- await ExecutionDetailsDialogRef . OpenModalAsync ( log , titleSuffix ) ;
97- }
98-
99- private static string GetExecutionTime ( ExecutionLogDto log )
100- {
101- // when fire time is available, display time range
102- // otherwise just display date added
103- if ( log . FireTimeUtc . HasValue )
104- {
105- StringBuilder strBuilder = new ( log . FireTimeUtc . Value . LocalDateTime . ToShortDateString ( ) +
106- " " +
107- log . FireTimeUtc . Value . LocalDateTime . ToLongTimeString ( ) ) ;
108-
109- var finishTime = log . GetFinishTimeUtc ( ) ;
110- if ( finishTime . HasValue )
111- {
112- strBuilder . Append ( " - " ) ;
113- if ( finishTime . Value . LocalDateTime . Date != log . FireTimeUtc . Value . LocalDateTime . Date )
114- {
115- // display ending date
116- strBuilder . Append ( finishTime . Value . LocalDateTime . ToShortDateString ( ) + " " ) ;
117- }
118-
119- strBuilder . Append ( finishTime . Value . LocalDateTime . ToLongTimeString ( ) ) ;
120- }
121- return strBuilder . ToString ( ) ;
122- }
123- else
124- {
125- return log . DateAddedUtc . LocalDateTime . ToShortDateString ( ) + " " +
126- log . DateAddedUtc . LocalDateTime . ToLongTimeString ( ) ;
127- }
128- }
129-
130- private static Color GetTimelineDotColor ( ExecutionLogDto log )
131- {
132- return log . LogType switch
133- {
134- LogType . ScheduleJob => log . IsException ?? false ? Color . Danger : Color . Success ,
135- _ => Color . Default
136- } ;
37+
38+ public async Task OpenModalAsync ( Key jobKey , Key triggerKey )
39+ {
40+ JobKey = jobKey ;
41+ TriggerKey = triggerKey ;
42+ await OnRefreshHistory ( ) ;
43+ await modalRef . Show ( ) ;
44+ }
45+
46+ protected async Task Close ( )
47+ {
48+ await modalRef . Hide ( ) ;
49+ }
50+
51+ private async Task GetMoreLogs ( )
52+ {
53+ PageMetadata pageMeta ;
54+ if ( _lastPageMeta == null )
55+ {
56+ pageMeta = PageMetadata . New ( 0 , 5 ) ;
57+ }
58+ else
59+ {
60+ pageMeta = new PageMetadata { Page = _lastPageMeta . Page + 1 , PageSize = _lastPageMeta . PageSize , TotalCount = _lastPageMeta . TotalCount } ;
61+ }
62+ LatestExecutionLogReadArgs latestExecutionLogReadArgs = new ( )
63+ {
64+ JobName = JobKey . Name ,
65+ JobGroup = JobKey . Group ?? Constants . DEFAULT_GROUP ,
66+ TriggerName = TriggerKey ? . Name ,
67+ TriggerGroup = TriggerKey ? . Group ,
68+ PageMetadata = pageMeta ,
69+ FirstLogId = _firstLogId
70+ } ;
71+ var result = await LogSvc . GetLatestExecutionLog ( latestExecutionLogReadArgs ) ;
72+ var items = result . Items . ToList ( ) ;
73+ _lastPageMeta = new PageMetadata { Page = pageMeta . Page , PageSize = pageMeta . PageSize , TotalCount = ( int ) result . TotalCount } ;
74+
75+ if ( pageMeta . Page == 0 )
76+ {
77+ _firstLogId = items . FirstOrDefault ( ) ? . Id ?? 0 ;
78+ }
79+
80+ items . ForEach ( ExecutionLogs . Add ) ;
81+
82+ HasMore = items . Count == pageMeta . PageSize ;
83+ StateHasChanged ( ) ;
84+ }
85+
86+ private async Task OnRefreshHistory ( )
87+ {
88+ ExecutionLogs . Clear ( ) ;
89+ _lastPageMeta = null ;
90+ _firstLogId = 0 ;
91+ HasMore = false ;
92+
93+ await GetMoreLogs ( ) ;
94+ }
95+
96+ ExecutionDetailsDialog ExecutionDetailsDialogRef ;
97+ private async Task OnMoreDetails ( ExecutionLogDto log , string titleSuffix )
98+ {
99+ await ExecutionDetailsDialogRef . OpenModalAsync ( log , titleSuffix ) ;
100+ }
101+
102+ private static string GetExecutionTime ( ExecutionLogDto log )
103+ {
104+ // when fire time is available, display time range
105+ // otherwise just display date added
106+ if ( log . FireTimeUtc . HasValue )
107+ {
108+ StringBuilder strBuilder = new ( log . FireTimeUtc . Value . LocalDateTime . ToShortDateString ( ) +
109+ " " +
110+ log . FireTimeUtc . Value . LocalDateTime . ToLongTimeString ( ) ) ;
111+
112+ var finishTime = log . GetFinishTimeUtc ( ) ;
113+ if ( finishTime . HasValue )
114+ {
115+ strBuilder . Append ( " - " ) ;
116+ if ( finishTime . Value . LocalDateTime . Date != log . FireTimeUtc . Value . LocalDateTime . Date )
117+ {
118+ // display ending date
119+ strBuilder . Append ( finishTime . Value . LocalDateTime . ToShortDateString ( ) + " " ) ;
120+ }
121+
122+ strBuilder . Append ( finishTime . Value . LocalDateTime . ToLongTimeString ( ) ) ;
123+ }
124+ return strBuilder . ToString ( ) ;
125+ }
126+ else
127+ {
128+ return log . DateAddedUtc . LocalDateTime . ToShortDateString ( ) + " " +
129+ log . DateAddedUtc . LocalDateTime . ToLongTimeString ( ) ;
130+ }
131+ }
132+
133+ private static Color GetTimelineDotColor ( ExecutionLogDto log )
134+ {
135+ return log . LogType switch
136+ {
137+ LogType . ScheduleJob => log . IsException ?? false ? Color . Danger : Color . Success ,
138+ _ => Color . Default
139+ } ;
137140 }
138141
139142 protected override void Dispose ( bool disposing )
@@ -144,5 +147,5 @@ protected override void Dispose(bool disposing)
144147 }
145148 base . Dispose ( disposing ) ;
146149 }
147- }
148-
150+ }
151+
0 commit comments