Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into Server-V2

This commit is contained in:
Glax 2024-09-16 22:51:57 +02:00
commit c36204c7a8

View File

@ -163,6 +163,7 @@ public class JobBoss : GlobalBase
{ {
Log($"Adding Job {job}"); Log($"Adding Job {job}");
this.jobs.Add(job); this.jobs.Add(job);
UpdateJobFile(job, file.Name);
} }
} }
@ -203,23 +204,23 @@ public class JobBoss : GlobalBase
internal void UpdateJobFile(Job job, string? oldFile = null) internal void UpdateJobFile(Job job, string? oldFile = null)
{ {
string newJobFilePath = Path.Join(TrangaSettings.jobsFolderPath, $"{job.id}.json"); string newJobFilePath = Path.Join(TrangaSettings.jobsFolderPath, $"{job.id}.json");
string oldFilePath = Path.Join(TrangaSettings.jobsFolderPath, oldFile);
if (!this.jobs.Any(jjob => jjob.id == job.id)) if (File.Exists(oldFilePath))
{ {
Log($"Deleting Job-file {oldFilePath}");
try try
{ {
Log($"Deleting Job-file {newJobFilePath}"); while(IsFileInUse(oldFilePath))
while(IsFileInUse(newJobFilePath))
Thread.Sleep(10); Thread.Sleep(10);
File.Delete(newJobFilePath); File.Delete(oldFilePath);
} }
catch (Exception e) catch (Exception e)
{ {
Log(e.ToString()); Log(e.ToString());
} }
} }
else
{
Log($"Exporting Job {newJobFilePath}"); Log($"Exporting Job {newJobFilePath}");
string jobStr = JsonConvert.SerializeObject(job, Formatting.Indented); string jobStr = JsonConvert.SerializeObject(job, Formatting.Indented);
while(IsFileInUse(newJobFilePath)) while(IsFileInUse(newJobFilePath))
@ -227,20 +228,6 @@ public class JobBoss : GlobalBase
File.WriteAllText(newJobFilePath, jobStr); File.WriteAllText(newJobFilePath, jobStr);
} }
if(oldFile is not null)
try
{
Log($"Deleting old Job-file {oldFile}");
while(IsFileInUse(oldFile))
Thread.Sleep(10);
File.Delete(oldFile);
}
catch (Exception e)
{
Log(e.ToString());
}
}
private void UpdateAllJobFiles() private void UpdateAllJobFiles()
{ {
Log("Exporting Jobs"); Log("Exporting Jobs");