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;
@ -94,17 +94,24 @@ namespace DML.Application.Classes
Logger.Debug("Entering job list handler loop..."); Logger.Debug("Entering job list handler loop...");
//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--)
{
if (JobList[i].State == JobState.Idle)
{ {
try try
{ {
var job = JobList[i]; var job = JobList[i];
Logger.Debug($"Checking job {job}"); Logger.Debug($"Checking job {job.Id}");
Task.Run(async () => Task.Run(async () =>
{ {
var foundCount = await job.Scan(); var scanFinished = await job.Scan();
while (foundCount > 0) Logger.Trace($"Scan result of {job.Id}: {scanFinished}");
foundCount = await job.Scan();
while (!scanFinished)
{
scanFinished = await job.Scan();
Logger.Trace($"Scan result of {job.Id}: {scanFinished}");
}
}); });
} }
catch (Exception ex) catch (Exception ex)
@ -114,4 +121,5 @@ namespace DML.Application.Classes
} }
} }
} }
}
} }