Compare commits

..

No commits in common. "4156365b183551dbef7dc71588c24503ea2f6986" and "f08b9e85ec82a66959d4b83edd82a4292fc2738d" have entirely different histories.

View File

@ -27,7 +27,7 @@ public class JobBoss : GlobalBase
{
Log($"Added {job}");
this.jobs.Add(job);
UpdateJobFile(job);
ExportJob(job);
}
}
@ -37,10 +37,6 @@ public class JobBoss : GlobalBase
AddJob(job);
}
/// <summary>
/// Compares contents of the provided job and all current jobs
/// Does not check if objects are the same
/// </summary>
public bool ContainsJobLike(Job job)
{
if (job is DownloadChapter dcJob)
@ -61,14 +57,13 @@ public class JobBoss : GlobalBase
this.jobs.Remove(job);
if(job.subJobs is not null && job.subJobs.Any())
RemoveJobs(job.subJobs);
UpdateJobFile(job);
ExportJob(job);
}
public void RemoveJobs(IEnumerable<Job?> jobsToRemove)
{
List<Job?> toRemove = jobsToRemove.ToList(); //Prevent multiple enumeration
Log($"Removing {toRemove.Count()} jobs.");
foreach (Job? job in toRemove)
Log($"Removing {jobsToRemove.Count()} jobs.");
foreach (Job? job in jobsToRemove)
if(job is not null)
RemoveJob(job);
}
@ -127,52 +122,47 @@ public class JobBoss : GlobalBase
private bool QueueContainsJob(Job job)
{
if (mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>()))//If we can add the queue, there is certainly no job in it
return true;
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
return mangaConnectorJobQueue[job.mangaConnector].Contains(job);
}
public void AddJobToQueue(Job job)
{
Log($"Adding Job to Queue. {job}");
if(!QueueContainsJob(job))
mangaConnectorJobQueue[job.mangaConnector].Enqueue(job);
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
Queue<Job> connectorJobQueue = mangaConnectorJobQueue[job.mangaConnector];
if(!connectorJobQueue.Contains(job))
connectorJobQueue.Enqueue(job);
job.ExecutionEnqueue();
}
private void AddJobsToQueue(IEnumerable<Job> newJobs)
public void AddJobsToQueue(IEnumerable<Job> jobs)
{
foreach(Job job in newJobs)
foreach(Job job in jobs)
AddJobToQueue(job);
}
private void LoadJobsList(HashSet<MangaConnector> connectors)
{
if (!Directory.Exists(settings.jobsFolderPath)) //No jobs to load
public void LoadJobsList(HashSet<MangaConnector> connectors)
{
Directory.CreateDirectory(settings.jobsFolderPath);
return;
}
Regex idRex = new (@"(.*)\.json");
//Load json-job-files
foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name)))
foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles())
if (idRex.IsMatch(file.Name))
{
Job job = JsonConvert.DeserializeObject<Job>(File.ReadAllText(file.FullName),
new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors)))!;
this.jobs.Add(job);
}
//Connect jobs to parent-jobs and add Publications to cache
foreach (Job job in this.jobs)
{
this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job);
if(job is DownloadNewChapters dncJob)
cachedPublications.Add(dncJob.manga);
}
foreach (DownloadNewChapters ncJob in this.jobs.Where(job => job is DownloadNewChapters))
cachedPublications.Add(ncJob.manga);
}
private void UpdateJobFile(Job job)
public void ExportJob(Job job)
{
string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json");
@ -200,11 +190,11 @@ public class JobBoss : GlobalBase
}
}
private void UpdateAllJobFiles()
public void ExportJobsList()
{
Log("Exporting Jobs");
foreach (Job job in this.jobs)
UpdateJobFile(job);
ExportJob(job);
//Remove files with jobs not in this.jobs-list
Regex idRex = new (@"(.*)\.json");
@ -238,10 +228,9 @@ public class JobBoss : GlobalBase
Job queueHead = jobQueue.Peek();
if (queueHead.progressToken.state is ProgressToken.State.Complete or ProgressToken.State.Cancelled)
{
queueHead.ResetProgress();
if(!queueHead.recurring)
RemoveJob(queueHead);
else
queueHead.ResetProgress();
jobQueue.Dequeue();
Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}");
}else if (queueHead.progressToken.state is ProgressToken.State.Standby)