Skip to content

Commit

Permalink
Merge branch 'support/1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Serraniel committed Jun 15, 2018
2 parents 786c5ee + 145a5eb commit 49b8d4e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
1 change: 1 addition & 0 deletions Discord Media Loader.Application/DML.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<Compile Include="FrmInternalSplash.Designer.cs">
<DependentUpon>FrmInternalSplash.cs</DependentUpon>
</Compile>
<Compile Include="Helper\IdentifiedString.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
22 changes: 22 additions & 0 deletions Discord Media Loader.Application/Helper/IdentifiedString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DML.Application.Helper
{
internal class IdentifiedString<T>
{
internal T Id { get; set; }
internal string Caption { get; set; }

internal IdentifiedString(T id, string caption)
{
Id = id;
Caption = caption;
}

public override string ToString() => Caption;
}
}
47 changes: 20 additions & 27 deletions Discord Media Loader.Application/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
Expand All @@ -8,7 +9,9 @@
using Discord.WebSocket;
using DML.AppCore.Classes;
using DML.Application.Classes;
using DML.Application.Helper;
using DML.Client;
using static DML.Client.DMLClient;
using static SweetLib.Utils.Logger.Logger;

namespace DML.Application
Expand Down Expand Up @@ -57,7 +60,9 @@ private void RefreshComponents()
if (cbGuild.Items.Count == 0)
{
Trace("Adding guilds to component...");
cbGuild.Items.AddRange(DMLClient.Client.Guilds.Where(g => g.Name != null).OrderBy(g => g.Name).Select(g => g.Name).ToArray());

cbGuild.Items.AddRange(DMLClient.Client.Guilds.Where(g => g.Name != null).OrderBy(g => g.Name).Select(g => new IdentifiedString<ulong>(g.Id, g.Name)).ToArray());

cbGuild.SelectedIndex = 0;
Trace("Guild component initialized.");
}
Expand All @@ -67,8 +72,7 @@ private void RefreshComponents()
lbxJobs.Items.Clear();
foreach (var job in Core.Scheduler.JobList)
{
lbxJobs.Items.Add(
$"{FindServerById(job.GuildId)?.Name}:{FindChannelById(FindServerById(job.GuildId), job.ChannelId)?.Name}");
lbxJobs.Items.Add(new IdentifiedString<int>(job.Id, $"{FindServerById(job.GuildId)?.Name}:{FindChannelById(FindServerById(job.GuildId), job.ChannelId)?.Name}"));
}
lbxJobs.SelectedIndex = oldIndex;

Expand Down Expand Up @@ -153,15 +157,17 @@ private void cbGuild_SelectedIndexChanged(object sender, System.EventArgs e)
UseWaitCursor = true;
try
{
var guild = FindServerByName(cbGuild.Text);
var guild = FindServerById(((IdentifiedString<ulong>)cbGuild.SelectedItem).Id);

if (guild != null)
{
Trace("Cleaning channel component from old values...");
cbChannel.Items.Clear();

Trace("Adding new channels...");
cbChannel.Items.AddRange(guild.TextChannels.OrderBy(c => c.Position).Select(c => c.Name).ToArray());

cbChannel.Items.AddRange(guild.TextChannels.OrderBy(c => c.Position).Select(c => new IdentifiedString<ulong>(c.Id, c.Name)).ToArray());

Trace($"Added {cbChannel.Items.Count} channels.");

cbChannel.SelectedIndex = 0;
Expand All @@ -183,8 +189,8 @@ private void btnAddJob_Click(object sender, System.EventArgs e)
{
var job = new Job
{
GuildId = FindServerByName(cbGuild.Text).Id,
ChannelId = FindChannelByName(FindServerByName(cbGuild.Text), cbChannel.Text).Id
GuildId = ((IdentifiedString<ulong>)cbGuild.SelectedItem).Id,
ChannelId = ((IdentifiedString<ulong>)cbChannel.SelectedItem).Id
};

if (!(from j in Core.Scheduler.JobList
Expand All @@ -208,28 +214,15 @@ private void btnDelete_Click(object sender, System.EventArgs e)
MessageBox.Show("No job has been seleted.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

var jobNameData = lbxJobs.SelectedItem.ToString().Split(':');

var guildName = "";
for (var i = 0; i < jobNameData.Length - 1; i++)
guildName += jobNameData[i] + ":";
guildName = guildName.Substring(0, guildName.Length - 1);

var channelName = jobNameData[jobNameData.Length - 1];
var jobId = ((IdentifiedString<int>)lbxJobs.SelectedItem).Id;

var guild = FindServerByName(guildName);
var channel = FindChannelByName(guild, channelName);

foreach (var job in Core.Scheduler.JobList)
var job = Core.Scheduler.JobList.FirstOrDefault(j => j.Id == jobId);
if (job != null)
{
if (job.GuildId == guild.Id && job.ChannelId == channel.Id)
{
Core.Scheduler.JobList.Remove(job);
Core.Scheduler.RunningJobs.Remove(job.Id);
job.Stop();
job.Delete();
break;
}
Core.Scheduler.JobList.Remove(job);
Core.Scheduler.RunningJobs.Remove(job.Id);
job.Stop();
job.Delete();
}

lbxJobs.SelectedIndex = -1;
Expand Down
4 changes: 2 additions & 2 deletions Discord Media Loader.Application/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyVersion("1.1.2.0")]
[assembly: AssemblyFileVersion("1.1.2.0")]

0 comments on commit 49b8d4e

Please sign in to comment.