From dd431e93b22a9d545ebf51b016ff99898a4636d4 Mon Sep 17 00:00:00 2001 From: Brett Hewitson Date: Fri, 17 Dec 2021 15:27:52 +1000 Subject: [PATCH] Changed the discord bot to be case insensitive. Added IsEmpty and HasOne IEnumerable Extensions. --- src/ARKServerManager/Lib/ServerRCON.cs | 5 +- .../Utils/DiscordBotHelper.cs | 102 ++++++++++-------- src/ARKServerManager/VersionFeed.xml | 7 +- src/ARKServerManager/VersionFeedBeta.xml | 23 ++++ .../Windows/RCONWindow.xaml.cs | 5 +- .../Utils/DiscordBotHelper.cs | 102 ++++++++++-------- src/ConanServerManager/VersionFeed.xml | 7 +- src/ConanServerManager/VersionFeedBeta.xml | 23 ++++ .../Windows/RconWindow.xaml.cs | 3 +- .../Extensions/IEnumerableExtensions.cs | 47 ++++++++ src/Plugin.Common/PluginHelper.cs | 2 +- src/Plugin.Discord/DiscordPlugin.cs | 2 +- .../Extensions/IEnumerableExtensions.cs | 47 ++++++++ .../Extensions/IEnumerableExtensions.cs | 47 ++++++++ .../Utils/TaskSchedulerUtils.cs | 9 +- src/ServerManager.Common/Utils/ZipUtils.cs | 7 +- src/ServerManager.Discord/ServerManagerBot.cs | 1 + .../Services/CommandHandlerService.cs | 2 +- .../Extensions/IEnumerableExtensions.cs | 47 ++++++++ src/ServerManager.Updater/Program.cs | 2 +- 20 files changed, 383 insertions(+), 107 deletions(-) create mode 100644 src/Plugin.Common/Extensions/IEnumerableExtensions.cs create mode 100644 src/Plugin.Discord/Extensions/IEnumerableExtensions.cs create mode 100644 src/ServerManager.Common/Extensions/IEnumerableExtensions.cs create mode 100644 src/ServerManager.Updater/Extensions/IEnumerableExtensions.cs diff --git a/src/ARKServerManager/Lib/ServerRCON.cs b/src/ARKServerManager/Lib/ServerRCON.cs index 8f4c85f5..5a86d427 100644 --- a/src/ARKServerManager/Lib/ServerRCON.cs +++ b/src/ARKServerManager/Lib/ServerRCON.cs @@ -1,5 +1,6 @@ using ArkData; using NLog; +using ServerManagerTool.Common.Extensions; using ServerManagerTool.Common.Interfaces; using ServerManagerTool.Common.Lib; using ServerManagerTool.Common.Model; @@ -325,8 +326,8 @@ namespace ServerManagerTool.Lib else if (command.command.Equals(RCON_COMMAND_GETCHAT, StringComparison.OrdinalIgnoreCase)) { // TODO: Extract the player name from the chat - var lines = command.lines.Where(l => !String.IsNullOrEmpty(l) && l != NoResponseOutput); - if (!lines.Any() && command.suppressCommand) + var lines = command.lines.Where(l => !string.IsNullOrEmpty(l) && l != NoResponseOutput); + if (lines.IsEmpty() && command.suppressCommand) { command.suppressOutput = true; } diff --git a/src/ARKServerManager/Utils/DiscordBotHelper.cs b/src/ARKServerManager/Utils/DiscordBotHelper.cs index 3ee4e57b..025f9b81 100644 --- a/src/ARKServerManager/Utils/DiscordBotHelper.cs +++ b/src/ARKServerManager/Utils/DiscordBotHelper.cs @@ -1,4 +1,5 @@ using QueryMaster; +using ServerManagerTool.Common.Extensions; using ServerManagerTool.Common.Utils; using ServerManagerTool.DiscordBot.Enums; using ServerManagerTool.Enums; @@ -109,14 +110,15 @@ namespace ServerManagerTool.Utils TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -190,7 +192,7 @@ namespace ServerManagerTool.Utils TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase)); response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}"); foreach (var server in serverList) @@ -211,8 +213,10 @@ namespace ServerManagerTool.Utils TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (string.IsNullOrWhiteSpace(profileIdOrAlias) || Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.IsNullOrWhiteSpace(profileIdOrAlias) + || string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}"); foreach (var server in serverList) @@ -245,14 +249,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -299,8 +304,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -341,14 +347,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -398,8 +405,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -440,14 +448,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -497,8 +506,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -539,14 +549,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -597,8 +608,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -639,14 +651,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -697,8 +710,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -740,14 +754,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -799,8 +814,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } diff --git a/src/ARKServerManager/VersionFeed.xml b/src/ARKServerManager/VersionFeed.xml index 4841b4be..eb307a69 100644 --- a/src/ARKServerManager/VersionFeed.xml +++ b/src/ARKServerManager/VersionFeed.xml @@ -9,8 +9,8 @@ urn:uuid:3E33DCB2-ECFE-4489-B1A4-56F5D386F9DC - 1.1.413 (1.1.413.7) - 1.1.413.7 + 1.1.413 (1.1.413.8) + 1.1.413.8 2021-12-17T00:00:00Z @@ -28,8 +28,9 @@ CHANGE
    +
  • Discord Bot - all commands are now case INsensitive, along with the profile id and the alias.
  • +
  • Discord Bot - removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.
  • Made changes to the code to help improve performance.
  • -
  • Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.
  • pt-BR Translation file updated.
  • ru-RU Translation file updated.
  • zh-CN Translation file updated.
  • diff --git a/src/ARKServerManager/VersionFeedBeta.xml b/src/ARKServerManager/VersionFeedBeta.xml index f19907f7..0f5abe1b 100644 --- a/src/ARKServerManager/VersionFeedBeta.xml +++ b/src/ARKServerManager/VersionFeedBeta.xml @@ -7,6 +7,29 @@ 2021-12-16T00:00:00Z + + urn:uuid:8EE5659C-18E6-47D3-941D-C32B129D2E06 + 1.1.413 (1.1.413.8) + 1.1.413.8 + + 2021-12-17T00:00:00Z + +
    +

    + CHANGE +
    +

      +
    • Discord Bot - all commands are now case INsensitive, along with the profile id and the alias.
    • +
    +

    +
    +
    + + bletch + bletch1971@hotmail.com + +
    + urn:uuid:8EE5659C-18E6-47D3-941D-C32B129D2E06 1.1.413 (1.1.413.7) diff --git a/src/ARKServerManager/Windows/RCONWindow.xaml.cs b/src/ARKServerManager/Windows/RCONWindow.xaml.cs index e2ec9fbf..fb75190a 100644 --- a/src/ARKServerManager/Windows/RCONWindow.xaml.cs +++ b/src/ARKServerManager/Windows/RCONWindow.xaml.cs @@ -1,4 +1,5 @@ -using ServerManagerTool.Common.Lib; +using ServerManagerTool.Common.Extensions; +using ServerManagerTool.Common.Lib; using ServerManagerTool.Common.Utils; using ServerManagerTool.Enums; using ServerManagerTool.Lib; @@ -927,7 +928,7 @@ namespace ServerManagerTool yield return new RCONOutput_Command($"> {command.rawCommand}"); } - if(!command.suppressOutput && command.lines.Count() > 0) + if(!command.suppressOutput && !command.lines.IsEmpty()) { yield return new LineBreak(); } diff --git a/src/ConanServerManager/Utils/DiscordBotHelper.cs b/src/ConanServerManager/Utils/DiscordBotHelper.cs index bd7fb824..44abc15e 100644 --- a/src/ConanServerManager/Utils/DiscordBotHelper.cs +++ b/src/ConanServerManager/Utils/DiscordBotHelper.cs @@ -1,4 +1,5 @@ using QueryMaster; +using ServerManagerTool.Common.Extensions; using ServerManagerTool.Common.Utils; using ServerManagerTool.DiscordBot.Enums; using ServerManagerTool.Enums; @@ -109,14 +110,15 @@ namespace ServerManagerTool.Utils TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -190,7 +192,7 @@ namespace ServerManagerTool.Utils TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase)); response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}"); foreach (var server in serverList) @@ -211,8 +213,10 @@ namespace ServerManagerTool.Utils TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (string.IsNullOrWhiteSpace(profileIdOrAlias) || Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.IsNullOrWhiteSpace(profileIdOrAlias) + || string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}"); foreach (var server in serverList) @@ -245,14 +249,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -299,8 +304,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -341,14 +347,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -398,8 +405,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -440,14 +448,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -497,8 +506,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -539,14 +549,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -597,8 +608,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -639,14 +651,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -697,8 +710,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } @@ -740,14 +754,15 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var serverList = ServerManager.Instance.Servers.Where(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); - if (!serverList.Any()) + if (serverList.IsEmpty()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias)); } - if (serverList.Count() > 1) + if (!serverList.HasOne()) { throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias)); } @@ -799,8 +814,9 @@ namespace ServerManagerTool.Utils { TaskUtils.RunOnUIThreadAsync(() => { - var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId) - && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias))); + var server = ServerManager.Instance.Servers.First(s => string.Equals(channelId, s.Profile.DiscordChannelId, StringComparison.OrdinalIgnoreCase) + && (string.Equals(profileIdOrAlias, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase) + || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && string.Equals(profileIdOrAlias, s.Profile.DiscordAlias, StringComparison.OrdinalIgnoreCase))); server.Runtime.UpdateServerStatus(serverStatus, true); }).Wait(); } diff --git a/src/ConanServerManager/VersionFeed.xml b/src/ConanServerManager/VersionFeed.xml index 1178578f..64d9c4ab 100644 --- a/src/ConanServerManager/VersionFeed.xml +++ b/src/ConanServerManager/VersionFeed.xml @@ -9,8 +9,8 @@ urn:uuid:19B09A66-43F2-4D5F-AF33-5C77D7EA9A6B - 1.1.58 (1.1.58.7) - 1.1.58.7 + 1.1.58 (1.1.58.8) + 1.1.58.8 2021-12-16T00:00:00Z @@ -28,8 +28,9 @@ CHANGE
      +
    • Discord Bot - all commands are now case INsensitive, along with the profile id and the alias.
    • +
    • Discord Bot - removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.
    • Made changes to the code to help improve performance.
    • -
    • Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.

    diff --git a/src/ConanServerManager/VersionFeedBeta.xml b/src/ConanServerManager/VersionFeedBeta.xml index a982233c..9483dadb 100644 --- a/src/ConanServerManager/VersionFeedBeta.xml +++ b/src/ConanServerManager/VersionFeedBeta.xml @@ -7,6 +7,29 @@ 2021-12-17T00:00:00Z + + urn:uuid:9A427D82-9904-44F5-8C1E-7C943049869A + 1.1.58 (1.1.58.8) + 1.1.58.8 + + 2021-12-17T00:00:00Z + +
    +

    + CHANGE +
    +

      +
    • Discord Bot - all commands are now case INsensitive, along with the profile id and the alias.
    • +
    +

    +
    +
    + + bletch + bletch1971@hotmail.com + +
    + urn:uuid:9A427D82-9904-44F5-8C1E-7C943049869A 1.1.58 (1.1.58.7) diff --git a/src/ConanServerManager/Windows/RconWindow.xaml.cs b/src/ConanServerManager/Windows/RconWindow.xaml.cs index 50690dde..94831f88 100644 --- a/src/ConanServerManager/Windows/RconWindow.xaml.cs +++ b/src/ConanServerManager/Windows/RconWindow.xaml.cs @@ -1,4 +1,5 @@ using ServerManagerTool.Common.Enums; +using ServerManagerTool.Common.Extensions; using ServerManagerTool.Common.Lib; using ServerManagerTool.Common.Utils; using ServerManagerTool.Enums; @@ -741,7 +742,7 @@ namespace ServerManagerTool yield return new RconOutput_Command($"> {command.rawCommand}"); } - if (!command.suppressOutput && command.lines.Count() > 0) + if (!command.suppressOutput && !command.lines.IsEmpty()) { yield return new LineBreak(); } diff --git a/src/Plugin.Common/Extensions/IEnumerableExtensions.cs b/src/Plugin.Common/Extensions/IEnumerableExtensions.cs new file mode 100644 index 00000000..7fc11629 --- /dev/null +++ b/src/Plugin.Common/Extensions/IEnumerableExtensions.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +namespace ServerManagerTool.Plugin.Common +{ + internal static class IEnumerableExtensions + { + public static bool IsEmpty(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + using (IEnumerator enumerator = source.GetEnumerator()) + { + if (enumerator.MoveNext()) + { + return false; + } + } + + return true; + } + + public static bool HasOne(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + var count = 0; + + using (IEnumerator enumerator = source.GetEnumerator()) + { + while (enumerator.MoveNext()) + { + if (++count > 1) + return false; + } + } + + return count == 1; + } + } +} diff --git a/src/Plugin.Common/PluginHelper.cs b/src/Plugin.Common/PluginHelper.cs index 8f66f984..94728e63 100644 --- a/src/Plugin.Common/PluginHelper.cs +++ b/src/Plugin.Common/PluginHelper.cs @@ -272,7 +272,7 @@ namespace ServerManagerTool.Plugin.Common return false; var plugins = Plugins.Where(p => (p.PluginType is nameof(IAlertPlugin)) && (p.Plugin?.Enabled ?? false)); - if (plugins.Count() == 0) + if (plugins.IsEmpty()) return false; lock (_syncLockProcessAlert) diff --git a/src/Plugin.Discord/DiscordPlugin.cs b/src/Plugin.Discord/DiscordPlugin.cs index 26f59402..b11ea349 100644 --- a/src/Plugin.Discord/DiscordPlugin.cs +++ b/src/Plugin.Discord/DiscordPlugin.cs @@ -115,7 +115,7 @@ namespace ServerManagerTool.Plugin.Discord && cp.AlertTypes.Any(pn => pn.Value.Equals(alertType)) && cp.ProfileNames.Any(pn => pn.Value.Equals(profileName, StringComparison.OrdinalIgnoreCase)) && !string.IsNullOrWhiteSpace(cp.DiscordWebhookUrl)); - if (configProfiles == null || configProfiles.Count() == 0) + if (configProfiles == null || configProfiles.IsEmpty()) { #if DEBUG var logFile = Path.Combine(PluginHelper.PluginFolder, "DiscordErrors.log"); diff --git a/src/Plugin.Discord/Extensions/IEnumerableExtensions.cs b/src/Plugin.Discord/Extensions/IEnumerableExtensions.cs new file mode 100644 index 00000000..d99b13b7 --- /dev/null +++ b/src/Plugin.Discord/Extensions/IEnumerableExtensions.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +namespace ServerManagerTool.Plugin.Discord +{ + internal static class IEnumerableExtensions + { + public static bool IsEmpty(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + using (IEnumerator enumerator = source.GetEnumerator()) + { + if (enumerator.MoveNext()) + { + return false; + } + } + + return true; + } + + public static bool HasOne(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + var count = 0; + + using (IEnumerator enumerator = source.GetEnumerator()) + { + while (enumerator.MoveNext()) + { + if (++count > 1) + return false; + } + } + + return count == 1; + } + } +} diff --git a/src/ServerManager.Common/Extensions/IEnumerableExtensions.cs b/src/ServerManager.Common/Extensions/IEnumerableExtensions.cs new file mode 100644 index 00000000..1c7814cd --- /dev/null +++ b/src/ServerManager.Common/Extensions/IEnumerableExtensions.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +namespace ServerManagerTool.Common.Extensions +{ + public static class IEnumerableExtensions + { + public static bool IsEmpty(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + using (IEnumerator enumerator = source.GetEnumerator()) + { + if (enumerator.MoveNext()) + { + return false; + } + } + + return true; + } + + public static bool HasOne(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + var count = 0; + + using (IEnumerator enumerator = source.GetEnumerator()) + { + while (enumerator.MoveNext()) + { + if (++count > 1) + return false; + } + } + + return count == 1; + } + } +} diff --git a/src/ServerManager.Common/Utils/TaskSchedulerUtils.cs b/src/ServerManager.Common/Utils/TaskSchedulerUtils.cs index 5b961c1d..9114452c 100644 --- a/src/ServerManager.Common/Utils/TaskSchedulerUtils.cs +++ b/src/ServerManager.Common/Utils/TaskSchedulerUtils.cs @@ -1,5 +1,6 @@ using Microsoft.Win32.TaskScheduler; using NLog; +using ServerManagerTool.Common.Extensions; using System; using System.Diagnostics; using System.Linq; @@ -202,7 +203,7 @@ namespace ServerManagerTool.Common.Utils // Add/Edit the trigger that will fire every x minutes var triggers = taskDefinition.Triggers.OfType(); - if (triggers.Count() == 0) + if (triggers.IsEmpty()) { var trigger = new TimeTrigger { @@ -445,7 +446,7 @@ namespace ServerManagerTool.Common.Utils if (onBoot) { var triggers = taskDefinition.Triggers.OfType(); - if (triggers.Count() == 0) + if (triggers.IsEmpty()) { var trigger = new BootTrigger { @@ -465,7 +466,7 @@ namespace ServerManagerTool.Common.Utils else { var triggers = taskDefinition.Triggers.OfType(); - if (triggers.Count() == 0) + if (triggers.IsEmpty()) { var trigger = new LogonTrigger { @@ -572,7 +573,7 @@ namespace ServerManagerTool.Common.Utils // Add/Edit the trigger that will fire every x minutes var triggers = taskDefinition.Triggers.OfType(); - if (triggers.Count() == 0) + if (triggers.IsEmpty()) { var trigger = new TimeTrigger { diff --git a/src/ServerManager.Common/Utils/ZipUtils.cs b/src/ServerManager.Common/Utils/ZipUtils.cs index 76468949..df1acf3b 100644 --- a/src/ServerManager.Common/Utils/ZipUtils.cs +++ b/src/ServerManager.Common/Utils/ZipUtils.cs @@ -1,4 +1,5 @@ using Ionic.Zip; +using ServerManagerTool.Common.Extensions; using System; using System.Collections.Generic; using System.IO; @@ -73,7 +74,8 @@ namespace ServerManagerTool.Common.Utils { if (string.IsNullOrWhiteSpace(zipFile)) throw new ArgumentNullException(nameof(zipFile)); - if (!filesToZip.Any()) + + if (filesToZip is null || filesToZip.IsEmpty()) return; if (!File.Exists(zipFile)) @@ -165,7 +167,8 @@ namespace ServerManagerTool.Common.Utils { if (string.IsNullOrWhiteSpace(zipFile)) throw new ArgumentNullException(nameof(zipFile)); - if (!filesToZip.Any()) + + if (filesToZip is null || filesToZip.IsEmpty()) throw new ArgumentNullException(nameof(filesToZip)); using (var zip = new ZipFile(zipFile)) diff --git a/src/ServerManager.Discord/ServerManagerBot.cs b/src/ServerManager.Discord/ServerManagerBot.cs index 957e8e82..41684c39 100644 --- a/src/ServerManager.Discord/ServerManagerBot.cs +++ b/src/ServerManager.Discord/ServerManagerBot.cs @@ -72,6 +72,7 @@ namespace ServerManagerTool.DiscordBot // Force all commands to run async DefaultRunMode = RunMode.Async, LogLevel = LogLevelHelper.GetLogSeverity(logLevel), + CaseSensitiveCommands = false, }; var discordBotConfig = new DiscordBotConfig diff --git a/src/ServerManager.Discord/Services/CommandHandlerService.cs b/src/ServerManager.Discord/Services/CommandHandlerService.cs index 6882a76b..70fc6474 100644 --- a/src/ServerManager.Discord/Services/CommandHandlerService.cs +++ b/src/ServerManager.Discord/Services/CommandHandlerService.cs @@ -71,7 +71,7 @@ namespace ServerManagerTool.DiscordBot.Services // Check if the message has a valid command prefix var argPos = 0; - if (msg.HasStringPrefix(_config["DiscordSettings:Prefix"], ref argPos) || msg.HasMentionPrefix(_discord.CurrentUser, ref argPos)) + if (msg.HasStringPrefix(_config["DiscordSettings:Prefix"], ref argPos, StringComparison.OrdinalIgnoreCase) || msg.HasMentionPrefix(_discord.CurrentUser, ref argPos)) { if (LogLevel.Debug.ToString().Equals(_config["DiscordSettings:LogLevel"])) await _logger?.OnLogAsync(new LogMessage(LogSeverity.Debug, MessageSource.System.ToString(), $"Message prefix matched, message will be processed.")); diff --git a/src/ServerManager.Updater/Extensions/IEnumerableExtensions.cs b/src/ServerManager.Updater/Extensions/IEnumerableExtensions.cs new file mode 100644 index 00000000..50db86f1 --- /dev/null +++ b/src/ServerManager.Updater/Extensions/IEnumerableExtensions.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +namespace ServerManagerTool.Updater +{ + public static class IEnumerableExtensions + { + public static bool IsEmpty(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + using (IEnumerator enumerator = source.GetEnumerator()) + { + if (enumerator.MoveNext()) + { + return false; + } + } + + return true; + } + + public static bool HasOne(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + var count = 0; + + using (IEnumerator enumerator = source.GetEnumerator()) + { + while (enumerator.MoveNext()) + { + if (++count > 1) + return false; + } + } + + return count == 1; + } + } +} diff --git a/src/ServerManager.Updater/Program.cs b/src/ServerManager.Updater/Program.cs index 2246a070..a7c9238c 100644 --- a/src/ServerManager.Updater/Program.cs +++ b/src/ServerManager.Updater/Program.cs @@ -277,7 +277,7 @@ namespace ServerManagerTool.Updater var processes = ProcessUtils.GetProcesses(process.ProcessName, executablePath); // check if there is more than one instance of the application running - if (processes.Count() != 1) + if (!processes.HasOne()) throw new Exception("The application to be updated has more than one instance running."); // get the command line of the process