06-12-2022
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
using DigitalData.Modules.Messaging.WCF;
|
||||
using ECM.JobRunner.Common;
|
||||
|
||||
namespace ECM.JobRunner.Web.Data
|
||||
{
|
||||
public class ApiService
|
||||
{
|
||||
private readonly Channel<Common.JobRunnerReference.IEDMIServiceChannel> channelManager;
|
||||
private readonly Common.JobRunnerReference.IEDMIServiceChannel channel;
|
||||
private ServerAddress address;
|
||||
|
||||
private System.Timers.Timer pollingTimer = new();
|
||||
|
||||
public event EventHandler<ApiStatusResponse> DataUpdated;
|
||||
|
||||
public ApiService(LoggingService Logging, WcfService Wcf)
|
||||
{
|
||||
channel = Wcf.Channel;
|
||||
|
||||
pollingTimer.Elapsed += PollingTimer_Elapsed;
|
||||
pollingTimer.Interval = 1000;
|
||||
pollingTimer.Start();
|
||||
}
|
||||
|
||||
protected virtual void OnDataUpdated(ApiStatusResponse e)
|
||||
{
|
||||
EventHandler<ApiStatusResponse> handler = DataUpdated;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
private async void PollingTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
OnDataUpdated(await GetData());
|
||||
}
|
||||
|
||||
public async Task<List<Common.JobRunnerReference.JobDefinition>?> GetJobList()
|
||||
{
|
||||
var resp = await channel.GetJobConfigAsync();
|
||||
|
||||
if (resp != null && resp.OK)
|
||||
{
|
||||
return resp.JobDefinitions.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ApiStatusResponse> GetData()
|
||||
{
|
||||
DateTime heartbeat = await GetHeartbeat();
|
||||
List<Common.JobRunnerReference.HistoryItem> jobHistory = await GetHistoryEntries();
|
||||
|
||||
return new ApiStatusResponse()
|
||||
{
|
||||
heartbeat = heartbeat,
|
||||
jobHistory = jobHistory.OrderByDescending(e => e.CreatedAt).Take(10).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<DateTime> GetHeartbeat()
|
||||
{
|
||||
return await channel.GetHeartbeatAsync();
|
||||
}
|
||||
|
||||
private async Task<List<Common.JobRunnerReference.HistoryItem>> GetHistoryEntries()
|
||||
{
|
||||
try
|
||||
{
|
||||
var oResponse = await channel.GetJobHistoryAsync();
|
||||
|
||||
if (oResponse.OK)
|
||||
{
|
||||
return oResponse.Items.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace ECM.JobRunner.Web.Data
|
||||
{
|
||||
public class ApiStatusResponse
|
||||
public class DashboardResponse
|
||||
{
|
||||
public DateTime heartbeat = DateTime.MinValue;
|
||||
public List<HistoryItem> jobHistory = new();
|
||||
public List<StatusItem> jobStatus = new();
|
||||
}
|
||||
}
|
||||
107
ECM.JobRunner.Web/Data/DashboardService.cs
Normal file
107
ECM.JobRunner.Web/Data/DashboardService.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using DigitalData.Modules.Logging;
|
||||
using DigitalData.Modules.Messaging.WCF;
|
||||
using ECM.JobRunner.Common;
|
||||
|
||||
namespace ECM.JobRunner.Web.Data
|
||||
{
|
||||
public class DashboardService
|
||||
{
|
||||
private readonly Common.JobRunnerReference.IEDMIServiceChannel channel;
|
||||
private Logger logger;
|
||||
|
||||
private System.Timers.Timer pollingTimer = new();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<DateTime> GetHeartbeat()
|
||||
{
|
||||
return await channel.GetHeartbeatAsync();
|
||||
}
|
||||
|
||||
private async Task<List<Common.JobRunnerReference.HistoryItem>> GetHistoryItems()
|
||||
{
|
||||
try
|
||||
{
|
||||
var oResponse = await channel.GetJobStatusAsync();
|
||||
|
||||
if (oResponse.OK)
|
||||
{
|
||||
return oResponse.HistoryItems.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error(e);
|
||||
return new();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task<List<Common.JobRunnerReference.StatusItem>> GetStatusItems()
|
||||
{
|
||||
try
|
||||
{
|
||||
var oResponse = await channel.GetJobStatusAsync();
|
||||
|
||||
if (oResponse.OK)
|
||||
{
|
||||
return oResponse.StatusItems.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error(e);
|
||||
return new();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
138
ECM.JobRunner.Web/Data/JobService.cs
Normal file
138
ECM.JobRunner.Web/Data/JobService.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using DigitalData.Modules.Logging;
|
||||
using ECM.JobRunner.Common.JobRunnerReference;
|
||||
using System.Threading.Channels;
|
||||
|
||||
namespace ECM.JobRunner.Web.Data
|
||||
{
|
||||
public class JobService
|
||||
{
|
||||
private readonly Logger logger;
|
||||
private readonly Common.JobRunnerReference.IEDMIServiceChannel channel;
|
||||
|
||||
public JobService(LoggingService Logging, WcfService Wcf)
|
||||
{
|
||||
logger = Logging.LogConfig.GetLogger();
|
||||
channel = Wcf.Channel;
|
||||
}
|
||||
|
||||
public async Task<List<Common.JobRunnerReference.JobDefinition>> GetJobs()
|
||||
{
|
||||
var resp = await channel.GetJobConfigAsync();
|
||||
|
||||
if (resp != null && resp.OK)
|
||||
{
|
||||
return resp.JobDefinitions.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Common.JobRunnerReference.JobType>> GetJobTypes()
|
||||
{
|
||||
var resp = await channel.GetJobConfigAsync();
|
||||
|
||||
if (resp != null && resp.OK)
|
||||
{
|
||||
return resp.JobTypes.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Common.JobRunnerReference.JobDefinition?> GetJob(int pJobId)
|
||||
{
|
||||
var resp = await channel.GetJobConfigAsync();
|
||||
|
||||
if (resp != null && resp.OK)
|
||||
{
|
||||
return resp.JobDefinitions.
|
||||
Where(j => j.Id == pJobId).
|
||||
FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateJob(JobDefinition job)
|
||||
{
|
||||
var resp = await channel.UpdateJobAsync(new UpdateJobUpdateJobRequest {
|
||||
Job = job,
|
||||
Action = UpdateJobUpdateJobRequest.UpdateJobAction.Update
|
||||
});
|
||||
|
||||
if (resp != null && resp.OK)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> CreateJob(JobDefinition job)
|
||||
{
|
||||
var resp = await channel.UpdateJobAsync(new UpdateJobUpdateJobRequest
|
||||
{
|
||||
Job = job,
|
||||
Action = UpdateJobUpdateJobRequest.UpdateJobAction.Create
|
||||
});
|
||||
|
||||
if (resp != null && resp.OK)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteJob(JobDefinition job)
|
||||
{
|
||||
var resp = await channel.UpdateJobAsync(new UpdateJobUpdateJobRequest
|
||||
{
|
||||
Job = job,
|
||||
Action = UpdateJobUpdateJobRequest.UpdateJobAction.Delete
|
||||
});
|
||||
|
||||
if (resp != null && resp.OK)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime GetNextExecutionTime(string pCronExpression)
|
||||
{
|
||||
Quartz.CronExpression expression = new(pCronExpression);
|
||||
|
||||
if (expression != null)
|
||||
{
|
||||
var next = expression.GetNextValidTimeAfter(DateTimeOffset.Now);
|
||||
|
||||
if (next != null)
|
||||
{
|
||||
return ((DateTimeOffset)next).DateTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user