16-12-2022

This commit is contained in:
Jonathan Jenne
2022-12-16 15:59:26 +01:00
parent 63edd9e542
commit 45f8dd2aad
32 changed files with 431 additions and 276 deletions

View File

@@ -9,53 +9,39 @@ namespace ECM.JobRunner.Web.Data
private readonly Common.JobRunnerReference.IEDMIServiceChannel channel;
private Logger logger;
private System.Timers.Timer pollingTimer = new();
private readonly System.Timers.Timer pollingTimer = new();
public event EventHandler<DashboardResponse> DataUpdated;
public event EventHandler<DashboardResponse>? DataUpdated;
public DashboardService(LoggingService Logging, WcfService Wcf)
{
logger = Logging.LogConfig.GetLogger();
channel = Wcf.Channel;
pollingTimer.Elapsed += PollingTimer_Elapsed;
pollingTimer.Interval = 1000;
pollingTimer.Start();
}
protected virtual void OnDataUpdated(DashboardResponse e)
{
EventHandler<DashboardResponse> handler = DataUpdated;
if (handler != null)
{
handler(this, e);
}
DataUpdated?.Invoke(this, e);
}
private async void PollingTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
private async void PollingTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
OnDataUpdated(await GetData());
}
public async Task<DashboardResponse> GetData()
{
DateTime heartbeat = await GetHeartbeat();
List<Common.JobRunnerReference.HistoryItem> jobHistory = await GetHistoryItems();
List<Common.JobRunnerReference.StatusItem> jobStatus = await GetStatusItems();
return new DashboardResponse()
{
heartbeat = heartbeat,
jobHistory = jobHistory.OrderByDescending(e => e.CreatedAt).Take(10).ToList(),
jobStatus = jobStatus.OrderByDescending(e => e.StartTime).Take(10).ToList()
jobHistory = jobHistory.OrderByDescending(e => e.CreatedAt).ToList(),
jobStatus = jobStatus.OrderByDescending(e => e.StartTime).ToList()
};
}
private async Task<DateTime> GetHeartbeat()
{
return await channel.GetHeartbeatAsync();
}
private async Task<List<Common.JobRunnerReference.HistoryItem>> GetHistoryItems()
{
try