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

@@ -7,5 +7,12 @@ namespace ECM.JobRunner.Web.Data
public DateTime heartbeat = DateTime.MinValue;
public List<HistoryItem> jobHistory = new();
public List<StatusItem> jobStatus = new();
public List<HistoryItem> GetHistoryForLastMinutes(int pMinutes)
{
return jobHistory.
Where(h => (DateTime.Now - h.CreatedAt) < new TimeSpan(0, pMinutes, 0)).
ToList();
}
}
}

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

View File

@@ -0,0 +1,40 @@
using DigitalData.Modules.Logging;
using ECM.JobRunner.Common.JobRunnerReference;
namespace ECM.JobRunner.Web.Data
{
public class HelperService
{
private readonly Logger logger;
private readonly IEDMIServiceChannel channel;
public HelperService(LoggingService Logging, WcfService Wcf)
{
logger = Logging.LogConfig.GetLogger();
channel = Wcf.Channel;
}
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;
}
}
}
}

View File

@@ -0,0 +1,93 @@
using DigitalData.Modules.Logging;
using ECM.JobRunner.Common.JobRunnerReference;
namespace ECM.JobRunner.Web.Data
{
public class ImportProfileService
{
private readonly Logger logger;
private readonly IEDMIServiceChannel channel;
public ImportProfileService(LoggingService Logging, WcfService Wcf)
{
logger = Logging.LogConfig.GetLogger();
channel = Wcf.Channel;
}
public async Task<List<ImportProfile>> GetProfiles()
{
try
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
var profiles = resp.ProfileDefinitions.ImportProfiles.ToList();
return profiles;
}
catch (Exception ex)
{
logger.Error(ex);
return new();
}
}
public async Task<ImportProfile?> GetProfile(int pProfileId)
{
try
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return null;
if (resp.OK == false) return null;
var jobs = resp.JobDefinitions.ToList();
var profiles = resp.ProfileDefinitions.ImportProfiles.ToList();
return profiles.
Where(p => p.Id == pProfileId).
SingleOrDefault();
}
catch (Exception ex)
{
logger.Error(ex);
return null;
}
}
public async Task<bool> CreateProfile(ImportProfile profile) =>
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Create);
public async Task<bool> UpdateProfile(ImportProfile profile) =>
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Update);
public async Task<bool> DeleteProfile(ImportProfile profile) =>
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Delete);
private async Task<bool> DoUpdateProfile(ImportProfile profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction action)
{
try
{
var req = new UpdateProfileUpdateProfileRequest()
{
ImportProfile = profile,
Action = action
};
var resp = await channel.UpdateProfileAsync(req);
if (resp == null) return false;
if (resp.OK == false) return false;
return true;
}
catch (Exception ex)
{
logger.Error(ex);
return false;
}
}
}
}

View File

@@ -1,67 +0,0 @@
using DigitalData.Modules.Logging;
using ECM.JobRunner.Common.JobRunnerReference;
namespace ECM.JobRunner.Web.Data
{
public class ImportService
{
private readonly Logger logger;
private readonly IEDMIServiceChannel channel;
public ImportService(LoggingService Logging, WcfService Wcf)
{
logger = Logging.LogConfig.GetLogger();
channel = Wcf.Channel;
}
public async Task<List<ImportProfile>> GetProfiles()
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
var profiles = resp.ProfileDefinitions.ImportProfiles.ToList();
return profiles;
}
public async Task<ImportProfile?> GetProfile(int pProfileId)
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
var jobs = resp.JobDefinitions.ToList();
var profiles = resp.ProfileDefinitions.ImportProfiles.ToList();
return profiles.
Where(p => p.Id == pProfileId).
SingleOrDefault();
}
public async Task<bool> CreateProfile(ImportProfile profile) =>
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Create);
public async Task<bool> UpdateProfile(ImportProfile profile) =>
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Update);
public async Task<bool> DeleteProfile(ImportProfile profile) =>
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Delete);
private async Task<bool> DoUpdateProfile(ImportProfile profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction action)
{
var req = new UpdateProfileUpdateProfileRequest()
{
ImportProfile = profile,
Action = action
};
var resp = await channel.UpdateProfileAsync(req);
if (resp == null) return false;
if (resp.OK == false) return false;
return true;
}
}
}

View File

@@ -1,131 +0,0 @@
using DigitalData.Modules.Logging;
using ECM.JobRunner.Common.JobRunnerReference;
namespace ECM.JobRunner.Web.Data
{
public class JobService
{
private readonly Logger logger;
private readonly IEDMIServiceChannel channel;
public JobService(LoggingService Logging, WcfService Wcf)
{
logger = Logging.LogConfig.GetLogger();
channel = Wcf.Channel;
}
public async Task<List<JobDefinition>> GetJobs()
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
return resp.JobDefinitions.ToList();
}
public async Task<List<ObjectType>> GetObjectTypes()
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
return resp.WindreamObjectTypes.ToList();
}
public async Task<List<JobType>> GetJobTypes()
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
return resp.JobTypes.ToList();
}
public async Task<JobDefinition?> GetJob(int pJobId)
{
var resp = await channel.GetJobConfigAsync();
if (resp == null) return null;
if (resp.OK == false) return null;
return resp.JobDefinitions.
Where(j => j.Id == pJobId).
FirstOrDefault();
}
public async Task<bool> UpdateJob(JobDefinition job)
{
var resp = await channel.UpdateJobAsync(new UpdateJobUpdateJobRequest {
Job = job,
Action = UpdateJobUpdateJobRequest.UpdateJobAction.Update
});
if (resp == null) return false;
if (resp.OK == false) return false;
return true;
}
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;
}
}
}
}

View File

@@ -10,7 +10,8 @@ namespace ECM.JobRunner.Web.Data
{
LogConfig = new LogConfig(LogConfig.PathType.CustomPath, Config["Config:LogPath"], null, "Digital Data", "ECM.JobRunner.Web")
{
Debug = bool.Parse(Config["Config:LogDebug"])
Debug = bool.Parse(Config["Config:LogDebug"]),
EnableJsonLog = bool.Parse(Config["Config:LogJson"])
};
}
}

View File

@@ -1,22 +1,77 @@
using DigitalData.Modules.Messaging.WCF;
using System.Net;
using ECM.JobRunner.Common.JobRunnerReference;
using System.Timers;
namespace ECM.JobRunner.Web.Data
{
public class WcfService
{
private readonly Channel<Common.JobRunnerReference.IEDMIServiceChannel> channelManager;
private ServerAddress address;
private readonly Channel<IEDMIServiceChannel> _channelManager;
private ServerAddress _address;
private bool _connected = false;
private System.Timers.Timer heartbeatTimer = new();
public readonly Common.JobRunnerReference.IEDMIServiceChannel Channel;
private IEDMIServiceChannel _channel;
public IEDMIServiceChannel Channel { get { return _channel; } }
public event EventHandler<bool>? ConnectedChanged;
public bool Connected { get { return _connected; } }
public WcfService(LoggingService Logging)
{
address.Host = "172.24.12.39";
address.Port = 9001;
_address.Host = "172.24.12.39";
_address.Port = 9001;
channelManager = new Channel<Common.JobRunnerReference.IEDMIServiceChannel>(Logging.LogConfig, address, "JobRunner");
Channel = channelManager.GetChannel();
_channelManager = new Channel<IEDMIServiceChannel>(Logging.LogConfig, _address, "JobRunner");
_channel = _channelManager.GetChannel();
_connected = true;
heartbeatTimer.Elapsed += HeartbeatTimer_Elapsed;
heartbeatTimer.Interval = 1000;
heartbeatTimer.Start();
}
private void CallConnectedChanged(bool pConnected)
{
if (ConnectedChanged != null && pConnected != _connected)
{
_connected = pConnected;
ConnectedChanged(this, pConnected);
}
}
private async void HeartbeatTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
try
{
await _channel.GetHeartbeatAsync();
CallConnectedChanged(true);
}
catch (Exception)
{
CallConnectedChanged(false);
}
}
public async Task<List<ObjectType>> GetObjectTypes()
{
var resp = await _channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
return resp.WindreamObjectTypes.ToList();
}
public async Task<List<JobType>> GetJobTypes()
{
var resp = await _channel.GetJobConfigAsync();
if (resp == null) return new();
if (resp.OK == false) return new();
return resp.JobTypes.ToList();
}
}
}