Add run time to queue
This commit is contained in:
@@ -144,6 +144,7 @@
|
||||
<Compile Include="Utility\ParseInfoPropertyMatcherWithCache.cs" />
|
||||
<Compile Include="Utility\ReflectionExtensions.cs" />
|
||||
<Compile Include="Utility\StringExtensions.cs" />
|
||||
<Compile Include="Utility\TimeSpanExtensions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
|
||||
@@ -8,15 +8,13 @@ using System.Linq;
|
||||
|
||||
namespace LeafWeb.Core.Entities
|
||||
{
|
||||
public class LeafInput
|
||||
public abstract class LeafInputBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public virtual ICollection<LeafInputFile> InputFiles { get; set; }
|
||||
public virtual ICollection<LeafOutputFile> OutputFiles { get; set; }
|
||||
public LeafOutputFile OutputErrorMessage => OutputFiles?.FirstOrDefault(f => f.IsErrorMessage);
|
||||
public LeafOutputFile OutputWarningMessage => OutputFiles?.FirstOrDefault(f => f.IsWarningMessage);
|
||||
public virtual ICollection<LeafInputData> LeafInputData { get; set; }
|
||||
public bool HasOutputFiles => OutputFiles.Any();
|
||||
public bool HasLeafChart => OutputFiles.Any(f => f.IsLeafChartFile);
|
||||
|
||||
public LeafInputStatusType CurrentStatus { get; set; }
|
||||
public virtual ICollection<LeafInputStatus> StatusHistory { get; set; }
|
||||
@@ -36,12 +34,71 @@ namespace LeafWeb.Core.Entities
|
||||
|| IsFinishing
|
||||
|| IsCancelPending
|
||||
|| IsCancelling;
|
||||
public bool IsDeletable => !IsInProgress;
|
||||
public bool HasOutputFiles => OutputFiles.Any();
|
||||
|
||||
public bool IsCancellable =>
|
||||
IsRunning
|
||||
|| IsPending;
|
||||
|
||||
public bool IsDeletable => !IsInProgress;
|
||||
public bool IsAtEndState => IsComplete || IsException || IsCancelled;
|
||||
|
||||
|
||||
public DateTime? StartTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsPending)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return StatusHistory.FirstOrDefault(s => s.Status == LeafInputStatusType.Starting)?.DateTime;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime? EndTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsAtEndState)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return StatusHistory.FirstOrDefault(
|
||||
s =>
|
||||
s.Status == LeafInputStatusType.Complete
|
||||
|| s.Status == LeafInputStatusType.Exception
|
||||
|| s.Status == LeafInputStatusType.Cancelled)?.DateTime;
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan TotalInProgressTime
|
||||
{
|
||||
get
|
||||
{
|
||||
var start = StartTime;
|
||||
if (!start.HasValue)
|
||||
{
|
||||
return TimeSpan.Zero;
|
||||
}
|
||||
|
||||
var end = EndTime;
|
||||
if (!end.HasValue)
|
||||
{
|
||||
return DateTime.Now - start.Value;
|
||||
}
|
||||
|
||||
return end.Value - start.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LeafInput : LeafInputBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public virtual ICollection<LeafInputFile> InputFiles { get; set; }
|
||||
public virtual ICollection<LeafInputData> LeafInputData { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Name required")]
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
|
||||
namespace LeafWeb.Core.Utility
|
||||
{
|
||||
public static class TimeSpanExtensions
|
||||
{
|
||||
public static string ToReadableString(this TimeSpan span)
|
||||
{
|
||||
Func<int, string> pluralize = i => i > 1 ? "s" : string.Empty;
|
||||
var formatted = string.Format("{0}{1}{2}{3}",
|
||||
span.Duration().Days > 0 ? $"{span.Days:0} day{pluralize(span.Days)}, " : string.Empty,
|
||||
span.Duration().Hours > 0 ? $"{span.Hours:0} hour{pluralize(span.Hours)}, " : string.Empty,
|
||||
span.Duration().Minutes > 0 ? $"{span.Minutes:0} minute{pluralize(span.Minutes)}, " : string.Empty,
|
||||
span.Duration().Seconds > 0 ? $"{span.Seconds:0} second{pluralize(span.Seconds)}" : string.Empty);
|
||||
|
||||
if (formatted.EndsWith(", ")) formatted = formatted.Substring(0, formatted.Length - 2);
|
||||
|
||||
if (string.IsNullOrEmpty(formatted)) formatted = "0 seconds";
|
||||
|
||||
return formatted;
|
||||
}
|
||||
|
||||
public static string ToRoundedReadableString(this TimeSpan span)
|
||||
{
|
||||
Func<int, string> pluralize = i => i > 1 ? "s" : string.Empty;
|
||||
Func<int, string, string> formatTime = (i, s) => $"{i:0} {s}{pluralize(i)}";
|
||||
if (span.Duration().Days > 0)
|
||||
return formatTime(span.Days, "day");
|
||||
if (span.Duration().Hours > 0)
|
||||
return formatTime(span.Hours, "hour");
|
||||
if (span.Duration().Minutes > 0)
|
||||
return formatTime(span.Minutes, "minute");
|
||||
if (span.Duration().Seconds > 0)
|
||||
return formatTime(span.Seconds, "second");
|
||||
|
||||
return "0 seconds";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user