Projektdateien hinzufügen.
This commit is contained in:
92
ECM.JobRunner.Web/Data/ApiService.cs
Normal file
92
ECM.JobRunner.Web/Data/ApiService.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
10
ECM.JobRunner.Web/Data/ApiStatusResponse.cs
Normal file
10
ECM.JobRunner.Web/Data/ApiStatusResponse.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using ECM.JobRunner.Common.JobRunnerReference;
|
||||
|
||||
namespace ECM.JobRunner.Web.Data
|
||||
{
|
||||
public class ApiStatusResponse
|
||||
{
|
||||
public DateTime heartbeat = DateTime.MinValue;
|
||||
public List<HistoryItem> jobHistory = new();
|
||||
}
|
||||
}
|
||||
24
ECM.JobRunner.Web/Data/DatabaseService.cs
Normal file
24
ECM.JobRunner.Web/Data/DatabaseService.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using DigitalData.Modules.Database;
|
||||
using System.Data;
|
||||
|
||||
namespace ECM.JobRunner.Web.Data
|
||||
{
|
||||
public class DatabaseService
|
||||
{
|
||||
|
||||
private const string QUERY_GET_JOBS = "";
|
||||
|
||||
public MSSQLServer MSSQL { get; set; }
|
||||
|
||||
public DatabaseService(LoggingService Logging, IConfiguration Config)
|
||||
{
|
||||
var oLogConfig = Logging.LogConfig;
|
||||
var oLogger = Logging.LogConfig.GetLogger();
|
||||
var oConnectionString = Config["Config:ConnectionString"];
|
||||
|
||||
oLogger.Debug("Establishing MSSQL Database connection..");
|
||||
MSSQL = new MSSQLServer(oLogConfig, oConnectionString);
|
||||
oLogger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
ECM.JobRunner.Web/Data/LoggingService.cs
Normal file
17
ECM.JobRunner.Web/Data/LoggingService.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using DigitalData.Modules.Logging;
|
||||
|
||||
namespace ECM.JobRunner.Web.Data
|
||||
{
|
||||
public class LoggingService
|
||||
{
|
||||
public LogConfig LogConfig { get; set; }
|
||||
|
||||
public LoggingService(IConfiguration Config)
|
||||
{
|
||||
LogConfig = new LogConfig(LogConfig.PathType.CustomPath, Config["Config:LogPath"], null, "Digital Data", "ECM.JobRunner.Web")
|
||||
{
|
||||
Debug = bool.Parse(Config["Config:LogDebug"])
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
22
ECM.JobRunner.Web/Data/WcfService.cs
Normal file
22
ECM.JobRunner.Web/Data/WcfService.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using DigitalData.Modules.Messaging.WCF;
|
||||
using System.Net;
|
||||
|
||||
namespace ECM.JobRunner.Web.Data
|
||||
{
|
||||
public class WcfService
|
||||
{
|
||||
private readonly Channel<Common.JobRunnerReference.IEDMIServiceChannel> channelManager;
|
||||
private ServerAddress address;
|
||||
|
||||
public readonly Common.JobRunnerReference.IEDMIServiceChannel Channel;
|
||||
|
||||
public WcfService(LoggingService Logging)
|
||||
{
|
||||
address.Host = "172.24.12.39";
|
||||
address.Port = 9001;
|
||||
|
||||
channelManager = new Channel<Common.JobRunnerReference.IEDMIServiceChannel>(Logging.LogConfig, address, "JobRunner");
|
||||
Channel = channelManager.GetChannel();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user