Removed unused uses

This commit is contained in:
Serraniel 2021-12-05 20:39:46 +01:00
parent 7b59c0b01f
commit f2992f37e9
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3
7 changed files with 79 additions and 94 deletions

View file

@ -6,7 +6,6 @@ using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using DML.Application.Classes; using DML.Application.Classes;
using DML.Client; using DML.Client;
using SweetLib.Utils;
using SweetLib.Utils.Extensions; using SweetLib.Utils.Extensions;
using static SweetLib.Utils.Logger.Logger; using static SweetLib.Utils.Logger.Logger;
@ -18,7 +17,7 @@ namespace DML.AppCore.Classes
public ulong GuildId { get; set; } public ulong GuildId { get; set; }
public ulong ChannelId { get; set; } public ulong ChannelId { get; set; }
public double KnownTimestamp { get; set; } = 0; public double KnownTimestamp { get; set; } = 0;
private double StopTimestamp { get; set; } = 0; private double StopTimestamp { get; set; }
private bool IsValid { get; set; } = true; private bool IsValid { get; set; } = true;
internal void Store() internal void Store()
@ -30,14 +29,10 @@ namespace DML.AppCore.Classes
Trace("Adding new value..."); Trace("Adding new value...");
if (jobDb.Find(x => x.ChannelId == ChannelId && x.GuildId == GuildId).Any()) if (jobDb.Find(x => x.ChannelId == ChannelId && x.GuildId == GuildId).Any())
{
jobDb.Update(this); jobDb.Update(this);
}
else else
{
jobDb.Insert(this); jobDb.Insert(this);
} }
}
public void Delete() public void Delete()
{ {
@ -98,27 +93,20 @@ namespace DML.AppCore.Classes
var realMessages = await channel.GetMessagesAsync(limit).ToArrayAsync(); var realMessages = await channel.GetMessagesAsync(limit).ToArrayAsync();
foreach (var realMessageArray in realMessages) foreach (var realMessageArray in realMessages)
{
foreach (var realMessage in realMessageArray) foreach (var realMessage in realMessageArray)
{
messages.Add(realMessage); messages.Add(realMessage);
} }
}
}
else else
{ {
var realMessages = await channel.GetMessagesAsync(lastId, Direction.Before, limit).ToArrayAsync(); var realMessages = await channel.GetMessagesAsync(lastId, Direction.Before, limit).ToArrayAsync();
foreach (var realMessageArray in realMessages) foreach (var realMessageArray in realMessages)
{
foreach (var realMessage in realMessageArray) foreach (var realMessage in realMessageArray)
{
messages.Add(realMessage); messages.Add(realMessage);
}
}
//messages = await channel.GetMessagesAsync(lastId, Direction.Before, limit).ToArray() as SocketMessage[]; //messages = await channel.GetMessagesAsync(lastId, Direction.Before, limit).ToArray() as SocketMessage[];
} }
Trace($"Downloaded {messages.Count} messages."); Trace($"Downloaded {messages.Count} messages.");
isFirst = false; isFirst = false;
@ -151,11 +139,13 @@ namespace DML.AppCore.Classes
Core.Scheduler.TotalAttachments += (ulong) m.Attachments.Count; Core.Scheduler.TotalAttachments += (ulong) m.Attachments.Count;
Trace($"Added message {m.Id}"); Trace($"Added message {m.Id}");
} }
Debug($"Finished message {m.Id}"); Debug($"Finished message {m.Id}");
} }
finished = finished || messages.Count < limit; finished = finished || messages.Count < limit;
} }
Trace($"Downloaded all messages for guild {GuildId} channel {ChannelId}."); Trace($"Downloaded all messages for guild {GuildId} channel {ChannelId}.");
Trace("Sorting messages..."); Trace("Sorting messages...");

View file

@ -7,7 +7,6 @@ using System.Threading.Tasks;
using Discord; using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using DML.Application.Classes; using DML.Application.Classes;
using SweetLib.Utils;
using SweetLib.Utils.Extensions; using SweetLib.Utils.Extensions;
using SweetLib.Utils.Logger; using SweetLib.Utils.Logger;
@ -15,14 +14,14 @@ namespace DML.AppCore.Classes
{ {
public class JobScheduler public class JobScheduler
{ {
private ulong messageScanned = 0; private ulong attachmentsDownloaded;
private ulong totalAttachments = 0; private ulong messageScanned;
private ulong attachmentsDownloaded = 0;
private bool Run { get; set; } = false;
public List<Job> JobList { get; set; } = new List<Job>();
public Dictionary<int, Queue<IMessage>> RunningJobs = new Dictionary<int, Queue<IMessage>>(); 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 internal ulong MessagesScanned
{ {
@ -91,7 +90,6 @@ namespace DML.AppCore.Classes
{ {
Logger.Info("Started JobScheduler..."); Logger.Info("Started JobScheduler...");
while (Run) while (Run)
{
try try
{ {
Logger.Debug("Entering job list handler loop..."); Logger.Debug("Entering job list handler loop...");
@ -108,6 +106,7 @@ namespace DML.AppCore.Classes
Logger.Trace("Checking if job is already performed..."); Logger.Trace("Checking if job is already performed...");
hasJob = RunningJobs.ContainsKey(job.Id); hasJob = RunningJobs.ContainsKey(job.Id);
} }
Logger.Trace("Unlocked scheduler."); Logger.Trace("Unlocked scheduler.");
if (!hasJob) if (!hasJob)
@ -121,6 +120,7 @@ namespace DML.AppCore.Classes
Logger.Trace("Adding job to running jobs."); Logger.Trace("Adding job to running jobs.");
RunningJobs.Add(job.Id, queue); RunningJobs.Add(job.Id, queue);
} }
Logger.Trace("Unlocked scheduler."); Logger.Trace("Unlocked scheduler.");
Logger.Trace("Issuing job message scan..."); Logger.Trace("Issuing job message scan...");
@ -130,10 +130,7 @@ namespace DML.AppCore.Classes
continue; continue;
Logger.Trace($"Adding {messages.Count} messages to queue..."); Logger.Trace($"Adding {messages.Count} messages to queue...");
foreach (var msg in messages) foreach (var msg in messages) queue.Enqueue(msg);
{
queue.Enqueue(msg);
}
Logger.Trace($"Added {queue.Count} messages to queue."); Logger.Trace($"Added {queue.Count} messages to queue.");
if (messages.Count != queue.Count) if (messages.Count != queue.Count)
@ -155,6 +152,7 @@ namespace DML.AppCore.Classes
RunningThreads++; RunningThreads++;
startedDownload = true; startedDownload = true;
} }
Logger.Trace("Unlocked scheduler."); Logger.Trace("Unlocked scheduler.");
} }
@ -167,7 +165,6 @@ namespace DML.AppCore.Classes
{ {
Logger.Error(ex.Message); Logger.Error(ex.Message);
} }
}
}); });
} }
@ -184,6 +181,7 @@ namespace DML.AppCore.Classes
Logger.Warn($"Associating job not found! JobId: {jobId}"); Logger.Warn($"Associating job not found! JobId: {jobId}");
return; return;
} }
Logger.Trace("Found job."); Logger.Trace("Found job.");
Queue<IMessage> queue; Queue<IMessage> queue;
@ -196,8 +194,10 @@ namespace DML.AppCore.Classes
Logger.Warn($"Queue for job {jobId} not found!"); Logger.Warn($"Queue for job {jobId} not found!");
return; return;
} }
Logger.Trace("Queue found."); Logger.Trace("Queue found.");
} }
Logger.Trace("Unlocked scheduler."); Logger.Trace("Unlocked scheduler.");
Logger.Debug($"Messages to process for job {jobId}: {queue.Count}"); 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!"); Logger.Warn($"Queue for job {jobId} not found!");
return; return;
} }
Logger.Trace("Continue working..."); Logger.Trace("Continue working...");
} }
Logger.Trace("Unlocked scheduler."); Logger.Trace("Unlocked scheduler.");
Logger.Trace("Dequeueing message..."); Logger.Trace("Dequeueing message...");
@ -221,7 +223,6 @@ namespace DML.AppCore.Classes
Logger.Debug($"Attachments for message {message.Id}: {message.Attachments.Count}"); Logger.Debug($"Attachments for message {message.Id}: {message.Attachments.Count}");
foreach (var a in message.Attachments) foreach (var a in message.Attachments)
{
try try
{ {
var fileName = Path.Combine(Core.Settings.OperatingFolder, Core.Settings.FileNameScheme); var fileName = Path.Combine(Core.Settings.OperatingFolder, Core.Settings.FileNameScheme);
@ -236,11 +237,13 @@ namespace DML.AppCore.Classes
if (socketTextChannel != null) if (socketTextChannel != null)
{ {
serverName = socketTextChannel.Guild.Name; 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; 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 =
fileName.Replace("%guild%", serverName) fileName.Replace("%guild%", serverName)
@ -289,7 +292,6 @@ namespace DML.AppCore.Classes
} }
} }
} }
}
finally finally
{ {
Logger.Trace("Locking scheduler..."); Logger.Trace("Locking scheduler...");
@ -300,6 +302,7 @@ namespace DML.AppCore.Classes
Logger.Trace("Decreasing thread count..."); Logger.Trace("Decreasing thread count...");
RunningThreads--; RunningThreads--;
} }
Logger.Trace("Unlocked scheduler."); Logger.Trace("Unlocked scheduler.");
} }
} }

View file

@ -1,22 +1,19 @@
using System; namespace DML.Application.Helper
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DML.Application.Helper
{ {
internal class IdentifiedString<T> internal class IdentifiedString<T>
{ {
internal T Id { get; set; }
internal string Caption { get; set; }
internal IdentifiedString(T id, string caption) internal IdentifiedString(T id, string caption)
{ {
Id = id; Id = id;
Caption = caption; Caption = caption;
} }
public override string ToString() => Caption; internal T Id { get; set; }
internal string Caption { get; set; }
public override string ToString()
{
return Caption;
}
} }
} }

View file

@ -1,37 +1,37 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Discord; using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using DML.AppCore.Classes; using DML.AppCore.Classes;
using DML.Application.Classes; using DML.Application.Classes;
using DML.Application.Helper; using DML.Application.Helper;
using DML.Application.Properties;
using DML.Client; using DML.Client;
using static DML.Client.DMLClient;
using static SweetLib.Utils.Logger.Logger; using static SweetLib.Utils.Logger.Logger;
namespace DML.Application namespace DML.Application
{ {
enum OnlineState internal enum OnlineState
{ {
Online, Online,
Idle, Idle,
DoNotDisturb, DoNotDisturb,
Invisible Invisible
} }
public partial class MainForm : Form public partial class MainForm : Form
{ {
private bool IsInitialized { get; set; } = false;
public MainForm() public MainForm()
{ {
InitializeComponent(); 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."); Trace("MainForm shown executed.");
RefreshComponents(); RefreshComponents();
@ -61,7 +61,8 @@ namespace DML.Application
{ {
Trace("Adding guilds to component..."); 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; cbGuild.SelectedIndex = 0;
Trace("Guild component initialized."); Trace("Guild component initialized.");
@ -71,15 +72,14 @@ namespace DML.Application
var oldIndex = lbxJobs.SelectedIndex; var oldIndex = lbxJobs.SelectedIndex;
lbxJobs.Items.Clear(); lbxJobs.Items.Clear();
foreach (var job in Core.Scheduler.JobList) foreach (var job in Core.Scheduler.JobList)
{ lbxJobs.Items.Add(new IdentifiedString<int>(job.Id,
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;
lbStatus.Text = DMLClient.Client.CurrentUser.Status.ToString(); 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}."); Debug($"DoSomethingChanged excuted by {sender}.");
if (!IsInitialized) if (!IsInitialized)
@ -106,7 +106,7 @@ namespace DML.Application
Info("New settings have been saved."); 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."); Trace("Operating folder button pressed.");
using (var browserDialog = new FolderBrowserDialog()) 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(); 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."); Trace("Guild index changed.");
Debug("Updating channel dropdown component..."); Debug("Updating channel dropdown component...");
@ -166,7 +166,8 @@ namespace DML.Application
Trace("Adding new channels..."); 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."); Trace($"Added {cbChannel.Items.Count} channels.");
@ -185,7 +186,7 @@ namespace DML.Application
Debug("Finished updating channel dropdown component."); 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 var job = new Job
{ {
@ -204,7 +205,7 @@ namespace DML.Application
RefreshComponents(); RefreshComponents();
} }
private void btnDelete_Click(object sender, System.EventArgs e) private void btnDelete_Click(object sender, EventArgs e)
{ {
Trace("Deleting job pressed."); Trace("Deleting job pressed.");
@ -229,7 +230,7 @@ namespace DML.Application
RefreshComponents(); RefreshComponents();
} }
private void tmrRefreshProgress_Tick(object sender, System.EventArgs e) private void tmrRefreshProgress_Tick(object sender, EventArgs e)
{ {
var scanned = Core.Scheduler.MessagesScanned; var scanned = Core.Scheduler.MessagesScanned;
var totalAttachments = Core.Scheduler.TotalAttachments; var totalAttachments = Core.Scheduler.TotalAttachments;
@ -243,19 +244,19 @@ namespace DML.Application
lbProgress.Text = $"Scanned: {scanned} Downloaded: {done} Open: {totalAttachments - done}"; 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/"); Process.Start("https://github.com/Serraniel/DiscordMediaLoader/");
} }
private async void toolStripDropDownButton1_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) 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(); lbStatus.Text = state.ToString();
tmrTriggerRefresh.Start(); tmrTriggerRefresh.Start();
@ -292,7 +293,7 @@ namespace DML.Application
private void btnFileNameHelp_Click(object sender, EventArgs e) private void btnFileNameHelp_Click(object sender, EventArgs e)
{ {
MessageBox.Show(Properties.Resources.FileNameInfo); MessageBox.Show(Resources.FileNameInfo);
} }
} }
} }

View file

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // Allgemeine Informationen über eine Assembly werden über die folgenden

View file

@ -5,24 +5,20 @@ using Nito.AsyncEx;
namespace Discord_Media_Loader namespace Discord_Media_Loader
{ {
static class Program internal static class Program
{ {
[STAThread] [STAThread]
static void Main(string[] paramStrings) private static void Main(string[] paramStrings)
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
var splashScreen = new FrmSplash(); var splashScreen = new FrmSplash();
if (splashScreen.ShowDialog() == DialogResult.OK) if (splashScreen.ShowDialog() == DialogResult.OK)
{
DoLaunch(paramStrings); DoLaunch(paramStrings);
}
else else
{
Application.Restart(); Application.Restart();
} }
}
private static void DoLaunch(string[] paramStrings) private static void DoLaunch(string[] paramStrings)
{ {

View file

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // Allgemeine Informationen über eine Assembly werden über die folgenden