Some fixes so it does compile again

This commit is contained in:
Serraniel 2018-06-25 21:14:10 +02:00
parent b52b6b4189
commit 3eb8750df7
2 changed files with 35 additions and 14 deletions

View file

@ -12,6 +12,13 @@ using static SweetLib.Utils.Logger.Logger;
namespace DML.AppCore.Classes namespace DML.AppCore.Classes
{ {
internal enum JobState
{
Idle,
Scanning,
Listening
}
public class Job public class Job
{ {
public int Id { get; set; } public int Id { get; set; }
@ -20,6 +27,8 @@ namespace DML.AppCore.Classes
public double KnownTimestamp { get; set; } = 0; public double KnownTimestamp { get; set; } = 0;
private double StopTimestamp { get; set; } = 0; private double StopTimestamp { get; set; } = 0;
private bool IsValid { get; set; } = true; private bool IsValid { get; set; } = true;
internal JobState State { get; set; } = JobState.Idle;
internal void Store() internal void Store()
{ {
@ -61,6 +70,10 @@ namespace DML.AppCore.Classes
return (from c in server.TextChannels where c.Id == id select c).FirstOrDefault(); return (from c in server.TextChannels where c.Id == id select c).FirstOrDefault();
} }
/// <summary>
/// Performs scanning task of the job.
/// </summary>
/// <returns>Returns true if the newest messages have been scanned.</returns>
internal async Task<bool> Scan() internal async Task<bool> Scan()
{ {
Debug($"Starting scan of guild {GuildId} channel {ChannelId}..."); Debug($"Starting scan of guild {GuildId} channel {ChannelId}...");

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using DML.AppCore.Classes; using DML.AppCore.Classes;
@ -7,7 +8,6 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks;
using Discord; using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using DML.Application.Classes; using DML.Application.Classes;
@ -95,21 +95,29 @@ namespace DML.Application.Classes
//foreach (var job in JobList) //foreach (var job in JobList)
for (var i = JobList.Count - 1; i >= 0; i--) for (var i = JobList.Count - 1; i >= 0; i--)
{ {
try if (JobList[i].State == JobState.Idle)
{ {
var job = JobList[i]; try
Logger.Debug($"Checking job {job}");
Task.Run(async () =>
{ {
var foundCount = await job.Scan(); var job = JobList[i];
while (foundCount > 0) Logger.Debug($"Checking job {job.Id}");
foundCount = await job.Scan();
}); Task.Run(async () =>
} {
catch (Exception ex) var scanFinished = await job.Scan();
{ Logger.Trace($"Scan result of {job.Id}: {scanFinished}");
Logger.Error(ex.Message);
while (!scanFinished)
{
scanFinished = await job.Scan();
Logger.Trace($"Scan result of {job.Id}: {scanFinished}");
}
});
}
catch (Exception ex)
{
Logger.Error(ex.Message);
}
} }
} }
} }