Switched joblist to IdentifiedString objects

This commit is contained in:
Serraniel 2018-06-15 18:46:44 +02:00
parent 5e940c09bd
commit 5c93684164

View file

@ -72,8 +72,7 @@ namespace DML.Application
lbxJobs.Items.Clear(); lbxJobs.Items.Clear();
foreach (var job in Core.Scheduler.JobList) foreach (var job in Core.Scheduler.JobList)
{ {
lbxJobs.Items.Add( lbxJobs.Items.Add(new IdentifiedString<int>(job.Id, $"{FindServerById(job.GuildId)?.Name}:{FindChannelById(FindServerById(job.GuildId), job.ChannelId)?.Name}"));
$"{FindServerById(job.GuildId)?.Name}:{FindChannelById(FindServerById(job.GuildId), job.ChannelId)?.Name}");
} }
lbxJobs.SelectedIndex = oldIndex; lbxJobs.SelectedIndex = oldIndex;
@ -215,28 +214,15 @@ namespace DML.Application
MessageBox.Show("No job has been seleted.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("No job has been seleted.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
var jobNameData = lbxJobs.SelectedItem.ToString().Split(':'); var jobId = ((IdentifiedString<int>)lbxJobs.SelectedItem).Id;
var guildName = ""; var job = Core.Scheduler.JobList.FirstOrDefault(j => j.Id == jobId);
for (var i = 0; i < jobNameData.Length - 1; i++) if (job != null)
guildName += jobNameData[i] + ":";
guildName = guildName.Substring(0, guildName.Length - 1);
var channelName = jobNameData[jobNameData.Length - 1];
var guild = FindServerByName(guildName);
var channel = FindChannelByName(guild, channelName);
foreach (var job in Core.Scheduler.JobList)
{
if (job.GuildId == guild.Id && job.ChannelId == channel.Id)
{ {
Core.Scheduler.JobList.Remove(job); Core.Scheduler.JobList.Remove(job);
Core.Scheduler.RunningJobs.Remove(job.Id); Core.Scheduler.RunningJobs.Remove(job.Id);
job.Stop(); job.Stop();
job.Delete(); job.Delete();
break;
}
} }
lbxJobs.SelectedIndex = -1; lbxJobs.SelectedIndex = -1;