96 lines
3.2 KiB
C#
96 lines
3.2 KiB
C#
using DigitalData.Modules.Logging;
|
|
using DigitalData.Modules.Filesystem;
|
|
using ECM.JobRunner.Common.JobRunnerReference;
|
|
using System;
|
|
|
|
namespace ECM.JobRunner.Web.Data
|
|
{
|
|
public class HelperService
|
|
{
|
|
private readonly Logger logger;
|
|
private readonly IEDMIServiceChannel channel;
|
|
private readonly DigitalData.Modules.Filesystem.File fileEx;
|
|
|
|
public event EventHandler<string>? PageTitleChanged;
|
|
|
|
public HelperService(LoggingService Logging, WcfService Wcf)
|
|
{
|
|
logger = Logging.LogConfig.GetLogger();
|
|
fileEx = new DigitalData.Modules.Filesystem.File(Logging.LogConfig);
|
|
channel = Wcf.Channel;
|
|
}
|
|
|
|
public string GetDateDirectory(DateTime date)
|
|
{
|
|
return fileEx.GetDateString(date);
|
|
}
|
|
|
|
public void SetPageTitle(string title)
|
|
{
|
|
PageTitleChanged?.Invoke(this, title);
|
|
}
|
|
|
|
public List<StatusItem> GetItemsForTimespan(List<StatusItem> items, TimeSpan timespan)
|
|
{
|
|
return items.
|
|
Where(s => (DateTime.Now - s.CompleteTime) < timespan).
|
|
ToList();
|
|
}
|
|
|
|
public List<StatusItem> GetItemsForLastMinutes(List<StatusItem> items, int minutes) =>
|
|
GetItemsForTimespan(items, new TimeSpan(0, minutes, 0));
|
|
|
|
public List<StatusItem> GetItemsForLastHours(List<StatusItem> items, int hours) =>
|
|
GetItemsForTimespan(items, new TimeSpan(hours, 0, 0));
|
|
|
|
public List<StatusItem> GetItemsForLastSeconds(List<StatusItem> items, int seconds) =>
|
|
GetItemsForTimespan(items, new TimeSpan(0, 0, seconds));
|
|
|
|
public class JobHistory
|
|
{
|
|
public List<StatusItem>? items;
|
|
public int total;
|
|
public int success;
|
|
public int failed;
|
|
public int waiting;
|
|
}
|
|
|
|
public JobHistory GetJobHistory(List<StatusItem> items, int sinceMinutes)
|
|
{
|
|
var filteredItems = GetItemsForLastMinutes(items, sinceMinutes);
|
|
var executingItems = filteredItems.Where(s => s.Executing == false);
|
|
|
|
return new JobHistory()
|
|
{
|
|
items = executingItems.ToList(),
|
|
total = executingItems.Count(),
|
|
success = executingItems.Where(i => i.Successful && i.Waiting == false).Count(),
|
|
failed = executingItems.Where(i => i.Successful == false).Count(),
|
|
waiting = executingItems.Where(i => i.Successful && i.Waiting == true).Count()
|
|
};
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|