Removed unused uses
This commit is contained in:
parent
7b59c0b01f
commit
f2992f37e9
|
@ -6,7 +6,6 @@ using Discord;
|
|||
using Discord.WebSocket;
|
||||
using DML.Application.Classes;
|
||||
using DML.Client;
|
||||
using SweetLib.Utils;
|
||||
using SweetLib.Utils.Extensions;
|
||||
using static SweetLib.Utils.Logger.Logger;
|
||||
|
||||
|
@ -18,7 +17,7 @@ namespace DML.AppCore.Classes
|
|||
public ulong GuildId { get; set; }
|
||||
public ulong ChannelId { get; set; }
|
||||
public double KnownTimestamp { get; set; } = 0;
|
||||
private double StopTimestamp { get; set; } = 0;
|
||||
private double StopTimestamp { get; set; }
|
||||
private bool IsValid { get; set; } = true;
|
||||
|
||||
internal void Store()
|
||||
|
@ -30,14 +29,10 @@ namespace DML.AppCore.Classes
|
|||
Trace("Adding new value...");
|
||||
|
||||
if (jobDb.Find(x => x.ChannelId == ChannelId && x.GuildId == GuildId).Any())
|
||||
{
|
||||
jobDb.Update(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
jobDb.Insert(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
|
@ -98,27 +93,20 @@ namespace DML.AppCore.Classes
|
|||
var realMessages = await channel.GetMessagesAsync(limit).ToArrayAsync();
|
||||
|
||||
foreach (var realMessageArray in realMessages)
|
||||
{
|
||||
foreach (var realMessage in realMessageArray)
|
||||
{
|
||||
messages.Add(realMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var realMessages = await channel.GetMessagesAsync(lastId, Direction.Before, limit).ToArrayAsync();
|
||||
|
||||
foreach (var realMessageArray in realMessages)
|
||||
{
|
||||
foreach (var realMessage in realMessageArray)
|
||||
{
|
||||
messages.Add(realMessage);
|
||||
}
|
||||
}
|
||||
|
||||
//messages = await channel.GetMessagesAsync(lastId, Direction.Before, limit).ToArray() as SocketMessage[];
|
||||
}
|
||||
|
||||
Trace($"Downloaded {messages.Count} messages.");
|
||||
|
||||
isFirst = false;
|
||||
|
@ -148,14 +136,16 @@ namespace DML.AppCore.Classes
|
|||
if (m.Attachments.Count > 0)
|
||||
{
|
||||
result.Add(m);
|
||||
Core.Scheduler.TotalAttachments += (ulong)m.Attachments.Count;
|
||||
Core.Scheduler.TotalAttachments += (ulong) m.Attachments.Count;
|
||||
Trace($"Added message {m.Id}");
|
||||
}
|
||||
|
||||
Debug($"Finished message {m.Id}");
|
||||
}
|
||||
|
||||
finished = finished || messages.Count < limit;
|
||||
}
|
||||
|
||||
Trace($"Downloaded all messages for guild {GuildId} channel {ChannelId}.");
|
||||
|
||||
Trace("Sorting messages...");
|
||||
|
|
|
@ -7,7 +7,6 @@ using System.Threading.Tasks;
|
|||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using DML.Application.Classes;
|
||||
using SweetLib.Utils;
|
||||
using SweetLib.Utils.Extensions;
|
||||
using SweetLib.Utils.Logger;
|
||||
|
||||
|
@ -15,14 +14,14 @@ namespace DML.AppCore.Classes
|
|||
{
|
||||
public class JobScheduler
|
||||
{
|
||||
private ulong messageScanned = 0;
|
||||
private ulong totalAttachments = 0;
|
||||
private ulong attachmentsDownloaded = 0;
|
||||
|
||||
private bool Run { get; set; } = false;
|
||||
public List<Job> JobList { get; set; } = new List<Job>();
|
||||
private ulong attachmentsDownloaded;
|
||||
private ulong messageScanned;
|
||||
public Dictionary<int, Queue<IMessage>> RunningJobs = new Dictionary<int, Queue<IMessage>>();
|
||||
internal int RunningThreads { get; set; } = 0;
|
||||
private ulong totalAttachments;
|
||||
|
||||
private bool Run { get; set; }
|
||||
public List<Job> JobList { get; set; } = new List<Job>();
|
||||
internal int RunningThreads { get; set; }
|
||||
|
||||
internal ulong MessagesScanned
|
||||
{
|
||||
|
@ -91,7 +90,6 @@ namespace DML.AppCore.Classes
|
|||
{
|
||||
Logger.Info("Started JobScheduler...");
|
||||
while (Run)
|
||||
{
|
||||
try
|
||||
{
|
||||
Logger.Debug("Entering job list handler loop...");
|
||||
|
@ -108,6 +106,7 @@ namespace DML.AppCore.Classes
|
|||
Logger.Trace("Checking if job is already performed...");
|
||||
hasJob = RunningJobs.ContainsKey(job.Id);
|
||||
}
|
||||
|
||||
Logger.Trace("Unlocked scheduler.");
|
||||
|
||||
if (!hasJob)
|
||||
|
@ -121,6 +120,7 @@ namespace DML.AppCore.Classes
|
|||
Logger.Trace("Adding job to running jobs.");
|
||||
RunningJobs.Add(job.Id, queue);
|
||||
}
|
||||
|
||||
Logger.Trace("Unlocked scheduler.");
|
||||
|
||||
Logger.Trace("Issuing job message scan...");
|
||||
|
@ -130,10 +130,7 @@ namespace DML.AppCore.Classes
|
|||
continue;
|
||||
|
||||
Logger.Trace($"Adding {messages.Count} messages to queue...");
|
||||
foreach (var msg in messages)
|
||||
{
|
||||
queue.Enqueue(msg);
|
||||
}
|
||||
foreach (var msg in messages) queue.Enqueue(msg);
|
||||
Logger.Trace($"Added {queue.Count} messages to queue.");
|
||||
|
||||
if (messages.Count != queue.Count)
|
||||
|
@ -155,6 +152,7 @@ namespace DML.AppCore.Classes
|
|||
RunningThreads++;
|
||||
startedDownload = true;
|
||||
}
|
||||
|
||||
Logger.Trace("Unlocked scheduler.");
|
||||
}
|
||||
|
||||
|
@ -167,7 +165,6 @@ namespace DML.AppCore.Classes
|
|||
{
|
||||
Logger.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -184,6 +181,7 @@ namespace DML.AppCore.Classes
|
|||
Logger.Warn($"Associating job not found! JobId: {jobId}");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Trace("Found job.");
|
||||
|
||||
Queue<IMessage> queue;
|
||||
|
@ -196,8 +194,10 @@ namespace DML.AppCore.Classes
|
|||
Logger.Warn($"Queue for job {jobId} not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Trace("Queue found.");
|
||||
}
|
||||
|
||||
Logger.Trace("Unlocked scheduler.");
|
||||
|
||||
Logger.Debug($"Messages to process for job {jobId}: {queue.Count}");
|
||||
|
@ -212,8 +212,10 @@ namespace DML.AppCore.Classes
|
|||
Logger.Warn($"Queue for job {jobId} not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Trace("Continue working...");
|
||||
}
|
||||
|
||||
Logger.Trace("Unlocked scheduler.");
|
||||
|
||||
Logger.Trace("Dequeueing message...");
|
||||
|
@ -221,7 +223,6 @@ namespace DML.AppCore.Classes
|
|||
|
||||
Logger.Debug($"Attachments for message {message.Id}: {message.Attachments.Count}");
|
||||
foreach (var a in message.Attachments)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fileName = Path.Combine(Core.Settings.OperatingFolder, Core.Settings.FileNameScheme);
|
||||
|
@ -236,11 +237,13 @@ namespace DML.AppCore.Classes
|
|||
if (socketTextChannel != null)
|
||||
{
|
||||
serverName = socketTextChannel.Guild.Name;
|
||||
serverName = Path.GetInvalidFileNameChars().Aggregate(serverName, (current, c) => current.Replace(c, ' '));
|
||||
serverName = Path.GetInvalidFileNameChars()
|
||||
.Aggregate(serverName, (current, c) => current.Replace(c, ' '));
|
||||
}
|
||||
|
||||
var channelName = message.Channel.Name;
|
||||
channelName = Path.GetInvalidFileNameChars().Aggregate(channelName, (current, c) => current.Replace(c, ' '));
|
||||
channelName = Path.GetInvalidFileNameChars()
|
||||
.Aggregate(channelName, (current, c) => current.Replace(c, ' '));
|
||||
|
||||
fileName =
|
||||
fileName.Replace("%guild%", serverName)
|
||||
|
@ -289,7 +292,6 @@ namespace DML.AppCore.Classes
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Logger.Trace("Locking scheduler...");
|
||||
|
@ -300,6 +302,7 @@ namespace DML.AppCore.Classes
|
|||
Logger.Trace("Decreasing thread count...");
|
||||
RunningThreads--;
|
||||
}
|
||||
|
||||
Logger.Trace("Unlocked scheduler.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DML.Application.Helper
|
||||
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;
|
||||
internal T Id { get; set; }
|
||||
internal string Caption { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Caption;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,37 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using DML.AppCore.Classes;
|
||||
using DML.Application.Classes;
|
||||
using DML.Application.Helper;
|
||||
using DML.Application.Properties;
|
||||
using DML.Client;
|
||||
using static DML.Client.DMLClient;
|
||||
using static SweetLib.Utils.Logger.Logger;
|
||||
|
||||
namespace DML.Application
|
||||
{
|
||||
enum OnlineState
|
||||
internal enum OnlineState
|
||||
{
|
||||
Online,
|
||||
Idle,
|
||||
DoNotDisturb,
|
||||
Invisible
|
||||
}
|
||||
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private bool IsInitialized { get; set; } = false;
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void MainForm_Shown(object sender, System.EventArgs e)
|
||||
private bool IsInitialized { get; set; }
|
||||
|
||||
private void MainForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
Trace("MainForm shown executed.");
|
||||
RefreshComponents();
|
||||
|
@ -61,7 +61,8 @@ namespace DML.Application
|
|||
{
|
||||
Trace("Adding guilds to component...");
|
||||
|
||||
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.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.");
|
||||
|
@ -71,15 +72,14 @@ namespace DML.Application
|
|||
var oldIndex = lbxJobs.SelectedIndex;
|
||||
lbxJobs.Items.Clear();
|
||||
foreach (var job in Core.Scheduler.JobList)
|
||||
{
|
||||
lbxJobs.Items.Add(new IdentifiedString<int>(job.Id, $"{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;
|
||||
|
||||
lbStatus.Text = DMLClient.Client.CurrentUser.Status.ToString();
|
||||
}
|
||||
|
||||
private void DoSomethingChanged(object sender, System.EventArgs e)
|
||||
private void DoSomethingChanged(object sender, EventArgs e)
|
||||
{
|
||||
Debug($"DoSomethingChanged excuted by {sender}.");
|
||||
if (!IsInitialized)
|
||||
|
@ -98,7 +98,7 @@ namespace DML.Application
|
|||
Core.Settings.SkipExistingFiles = cbSkipExisting.Checked;
|
||||
|
||||
Trace("Updating thread limit...");
|
||||
Core.Settings.ThreadLimit = (int)edThreadLimit.Value;
|
||||
Core.Settings.ThreadLimit = (int) edThreadLimit.Value;
|
||||
|
||||
Trace("Storing new settings...");
|
||||
Core.Settings.Store();
|
||||
|
@ -106,7 +106,7 @@ namespace DML.Application
|
|||
Info("New settings have been saved.");
|
||||
}
|
||||
|
||||
private void btnSearchFolders_Click(object sender, System.EventArgs e)
|
||||
private void btnSearchFolders_Click(object sender, EventArgs e)
|
||||
{
|
||||
Trace("Operating folder button pressed.");
|
||||
using (var browserDialog = new FolderBrowserDialog())
|
||||
|
@ -149,7 +149,7 @@ namespace DML.Application
|
|||
return (from c in server.TextChannels where c.Id == id select c).FirstOrDefault();
|
||||
}
|
||||
|
||||
private void cbGuild_SelectedIndexChanged(object sender, System.EventArgs e)
|
||||
private void cbGuild_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
Trace("Guild index changed.");
|
||||
Debug("Updating channel dropdown component...");
|
||||
|
@ -157,7 +157,7 @@ namespace DML.Application
|
|||
UseWaitCursor = true;
|
||||
try
|
||||
{
|
||||
var guild = FindServerById(((IdentifiedString<ulong>)cbGuild.SelectedItem).Id);
|
||||
var guild = FindServerById(((IdentifiedString<ulong>) cbGuild.SelectedItem).Id);
|
||||
|
||||
if (guild != null)
|
||||
{
|
||||
|
@ -166,7 +166,8 @@ namespace DML.Application
|
|||
|
||||
Trace("Adding new channels...");
|
||||
|
||||
cbChannel.Items.AddRange(guild.TextChannels.OrderBy(c => c.Position).Select(c => new IdentifiedString<ulong>(c.Id, 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.");
|
||||
|
||||
|
@ -185,12 +186,12 @@ namespace DML.Application
|
|||
Debug("Finished updating channel dropdown component.");
|
||||
}
|
||||
|
||||
private void btnAddJob_Click(object sender, System.EventArgs e)
|
||||
private void btnAddJob_Click(object sender, EventArgs e)
|
||||
{
|
||||
var job = new Job
|
||||
{
|
||||
GuildId = ((IdentifiedString<ulong>)cbGuild.SelectedItem).Id,
|
||||
ChannelId = ((IdentifiedString<ulong>)cbChannel.SelectedItem).Id
|
||||
GuildId = ((IdentifiedString<ulong>) cbGuild.SelectedItem).Id,
|
||||
ChannelId = ((IdentifiedString<ulong>) cbChannel.SelectedItem).Id
|
||||
};
|
||||
|
||||
if (!(from j in Core.Scheduler.JobList
|
||||
|
@ -204,7 +205,7 @@ namespace DML.Application
|
|||
RefreshComponents();
|
||||
}
|
||||
|
||||
private void btnDelete_Click(object sender, System.EventArgs e)
|
||||
private void btnDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
Trace("Deleting job pressed.");
|
||||
|
||||
|
@ -214,7 +215,7 @@ namespace DML.Application
|
|||
MessageBox.Show("No job has been seleted.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
var jobId = ((IdentifiedString<int>)lbxJobs.SelectedItem).Id;
|
||||
var jobId = ((IdentifiedString<int>) lbxJobs.SelectedItem).Id;
|
||||
|
||||
var job = Core.Scheduler.JobList.FirstOrDefault(j => j.Id == jobId);
|
||||
if (job != null)
|
||||
|
@ -229,13 +230,13 @@ namespace DML.Application
|
|||
RefreshComponents();
|
||||
}
|
||||
|
||||
private void tmrRefreshProgress_Tick(object sender, System.EventArgs e)
|
||||
private void tmrRefreshProgress_Tick(object sender, EventArgs e)
|
||||
{
|
||||
var scanned = Core.Scheduler.MessagesScanned;
|
||||
var totalAttachments = Core.Scheduler.TotalAttachments;
|
||||
var done = Core.Scheduler.AttachmentsDownloaded;
|
||||
|
||||
var progress = totalAttachments > 0 ? (int)(100 * done / totalAttachments) : 0;
|
||||
var progress = totalAttachments > 0 ? (int) (100 * done / totalAttachments) : 0;
|
||||
progress = Math.Min(Math.Max(0, progress), 100);
|
||||
pgbProgress.Maximum = 100;
|
||||
pgbProgress.Value = progress;
|
||||
|
@ -243,19 +244,19 @@ namespace DML.Application
|
|||
lbProgress.Text = $"Scanned: {scanned} Downloaded: {done} Open: {totalAttachments - done}";
|
||||
}
|
||||
|
||||
private void aboutToolStripMenuItem_Click(object sender, System.EventArgs e)
|
||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show(Properties.Resources.AboutString);
|
||||
MessageBox.Show(Resources.AboutString);
|
||||
}
|
||||
|
||||
private void visitGithubToolStripMenuItem_Click(object sender, System.EventArgs e)
|
||||
private void visitGithubToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Process.Start("https://github.com/Serraniel/DiscordMediaLoader/");
|
||||
}
|
||||
|
||||
private async void toolStripDropDownButton1_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
OnlineState state = (OnlineState)Convert.ToInt32(e.ClickedItem.Tag);
|
||||
var state = (OnlineState) Convert.ToInt32(e.ClickedItem.Tag);
|
||||
|
||||
lbStatus.Text = state.ToString();
|
||||
tmrTriggerRefresh.Start();
|
||||
|
@ -292,7 +293,7 @@ namespace DML.Application
|
|||
|
||||
private void btnFileNameHelp_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show(Properties.Resources.FileNameInfo);
|
||||
MessageBox.Show(Resources.FileNameInfo);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
|
|
|
@ -5,24 +5,20 @@ using Nito.AsyncEx;
|
|||
|
||||
namespace Discord_Media_Loader
|
||||
{
|
||||
static class Program
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main(string[] paramStrings)
|
||||
private static void Main(string[] paramStrings)
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
var splashScreen = new FrmSplash();
|
||||
if (splashScreen.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DoLaunch(paramStrings);
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Restart();
|
||||
}
|
||||
}
|
||||
|
||||
private static void DoLaunch(string[] paramStrings)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
|
|
Loading…
Reference in a new issue