Compare commits
No commits in common. "017701867d06e1c910067ecf65eb070e73bb04a2" and "1265c7a0720844026b88f7f73784ef8ccfeff3a7" have entirely different histories.
017701867d
...
1265c7a072
@ -11,11 +11,10 @@ public class FileLogger : LoggerBase
|
|||||||
{
|
{
|
||||||
this.logFilePath = logFilePath;
|
this.logFilePath = logFilePath;
|
||||||
|
|
||||||
DirectoryInfo dir = Directory.CreateDirectory(new FileInfo(logFilePath).DirectoryName!);
|
|
||||||
|
|
||||||
//Remove oldest logfile if more than MaxNumberOfLogFiles
|
//Remove oldest logfile if more than MaxNumberOfLogFiles
|
||||||
for (int fileCount = dir.EnumerateFiles().Count(); fileCount > MaxNumberOfLogFiles - 1; fileCount--) //-1 because we create own logfile later
|
string parentFolderPath = Path.GetDirectoryName(logFilePath)!;
|
||||||
File.Delete(dir.EnumerateFiles().MinBy(file => file.LastWriteTime)!.FullName);
|
for (int fileCount = new DirectoryInfo(parentFolderPath).EnumerateFiles().Count(); fileCount > MaxNumberOfLogFiles - 1; fileCount--) //-1 because we create own logfile later
|
||||||
|
File.Delete(new DirectoryInfo(parentFolderPath).EnumerateFiles().MinBy(file => file.LastWriteTime)!.FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Write(LogMessage logMessage)
|
protected override void Write(LogMessage logMessage)
|
||||||
|
@ -23,15 +23,14 @@ public class Logger : TextWriter
|
|||||||
public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath)
|
public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath)
|
||||||
{
|
{
|
||||||
this.Encoding = encoding ?? Encoding.UTF8;
|
this.Encoding = encoding ?? Encoding.UTF8;
|
||||||
if(enabledLoggers.Contains(LoggerType.FileLogger) && (logFilePath is null || logFilePath == ""))
|
if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null)
|
||||||
|
_fileLogger = new FileLogger(logFilePath, encoding);
|
||||||
|
else if(enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is null)
|
||||||
{
|
{
|
||||||
DateTime now = DateTime.Now;
|
|
||||||
logFilePath = Path.Join(LogDirectoryPath,
|
logFilePath = Path.Join(LogDirectoryPath,
|
||||||
$"{now.ToShortDateString()}_{now.Hour}-{now.Minute}-{now.Second}.log");
|
$"{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}.log");
|
||||||
_fileLogger = new FileLogger(logFilePath, encoding);
|
_fileLogger = new FileLogger(logFilePath, encoding);
|
||||||
}else if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null)
|
}
|
||||||
_fileLogger = new FileLogger(logFilePath, encoding);
|
|
||||||
|
|
||||||
|
|
||||||
if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is not null)
|
if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is not null)
|
||||||
{
|
{
|
||||||
|
@ -7,9 +7,6 @@ public class ProgressToken
|
|||||||
public int incrementsCompleted { get; set; }
|
public int incrementsCompleted { get; set; }
|
||||||
public float progress => GetProgress();
|
public float progress => GetProgress();
|
||||||
|
|
||||||
public DateTime executionStarted { get; private set; }
|
|
||||||
public TimeSpan timeRemaining => GetTimeRemaining();
|
|
||||||
|
|
||||||
public enum State { Running, Complete, Standby, Cancelled }
|
public enum State { Running, Complete, Standby, Cancelled }
|
||||||
public State state { get; private set; }
|
public State state { get; private set; }
|
||||||
|
|
||||||
@ -19,7 +16,6 @@ public class ProgressToken
|
|||||||
this.increments = increments;
|
this.increments = increments;
|
||||||
this.incrementsCompleted = 0;
|
this.incrementsCompleted = 0;
|
||||||
this.state = State.Complete;
|
this.state = State.Complete;
|
||||||
this.executionStarted = DateTime.UnixEpoch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private float GetProgress()
|
private float GetProgress()
|
||||||
@ -29,13 +25,6 @@ public class ProgressToken
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeSpan GetTimeRemaining()
|
|
||||||
{
|
|
||||||
if (increments > 0 && incrementsCompleted > 0)
|
|
||||||
return DateTime.Now.Subtract(this.executionStarted).Divide(incrementsCompleted).Multiply(increments - incrementsCompleted);
|
|
||||||
return TimeSpan.MaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Increment()
|
public void Increment()
|
||||||
{
|
{
|
||||||
this.incrementsCompleted++;
|
this.incrementsCompleted++;
|
||||||
@ -51,7 +40,6 @@ public class ProgressToken
|
|||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
state = State.Running;
|
state = State.Running;
|
||||||
this.executionStarted = DateTime.Now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Complete()
|
public void Complete()
|
||||||
|
@ -177,7 +177,7 @@ public class Server : GlobalBase
|
|||||||
SendResponse(HttpStatusCode.OK, response, _parent.jobBoss.jobs);
|
SendResponse(HttpStatusCode.OK, response, _parent.jobBoss.jobs);
|
||||||
break;
|
break;
|
||||||
case "Jobs/Progress":
|
case "Jobs/Progress":
|
||||||
if (requestVariables.TryGetValue("jobId", out jobId))
|
if (!requestVariables.TryGetValue("jobId", out jobId))
|
||||||
{
|
{
|
||||||
if(!_parent.jobBoss.jobs.Any(jjob => jjob.id == jobId))
|
if(!_parent.jobBoss.jobs.Any(jjob => jjob.id == jobId))
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
@ -213,9 +213,6 @@ public class Server : GlobalBase
|
|||||||
SendResponse(HttpStatusCode.OK, response,
|
SendResponse(HttpStatusCode.OK, response,
|
||||||
Enum.GetValues<LibraryConnector.LibraryType>().Select(lc => new KeyValuePair<byte, string?>((byte)lc, Enum.GetName(lc))));
|
Enum.GetValues<LibraryConnector.LibraryType>().Select(lc => new KeyValuePair<byte, string?>((byte)lc, Enum.GetName(lc))));
|
||||||
break;
|
break;
|
||||||
case "Ping":
|
|
||||||
SendResponse(HttpStatusCode.OK, response, "Pong");
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user