Changed the discord bot to be case insensitive.

Added IsEmpty and HasOne IEnumerable Extensions.
This commit is contained in:
Brett Hewitson 2021-12-17 15:27:52 +10:00
parent 734332f10c
commit dd431e93b2
20 changed files with 383 additions and 107 deletions

View file

@ -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;
}

View file

@ -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();
}

View file

@ -9,8 +9,8 @@
<entry>
<id>urn:uuid:3E33DCB2-ECFE-4489-B1A4-56F5D386F9DC</id>
<title>1.1.413 (1.1.413.7)</title>
<summary>1.1.413.7</summary>
<title>1.1.413 (1.1.413.8)</title>
<summary>1.1.413.8</summary>
<link href="" />
<updated>2021-12-17T00:00:00Z</updated>
<content type="xhtml">
@ -28,8 +28,9 @@
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Discord Bot - all commands are now case INsensitive, along with the profile id and the alias.</li>
<li>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.</li>
<li>Made changes to the code to help improve performance.</li>
<li>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.</li>
<li>pt-BR Translation file updated.</li>
<li>ru-RU Translation file updated.</li>
<li>zh-CN Translation file updated.</li>

View file

@ -7,6 +7,29 @@
<link href="http://arkservermanager.freeforums.net/" />
<updated>2021-12-16T00:00:00Z</updated>
<entry>
<id>urn:uuid:8EE5659C-18E6-47D3-941D-C32B129D2E06</id>
<title>1.1.413 (1.1.413.8)</title>
<summary>1.1.413.8</summary>
<link href="" />
<updated>2021-12-17T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Discord Bot - all commands are now case INsensitive, along with the profile id and the alias.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:8EE5659C-18E6-47D3-941D-C32B129D2E06</id>
<title>1.1.413 (1.1.413.7)</title>

View file

@ -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();
}

View file

@ -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();
}

View file

@ -9,8 +9,8 @@
<entry>
<id>urn:uuid:19B09A66-43F2-4D5F-AF33-5C77D7EA9A6B</id>
<title>1.1.58 (1.1.58.7)</title>
<summary>1.1.58.7</summary>
<title>1.1.58 (1.1.58.8)</title>
<summary>1.1.58.8</summary>
<link href="" />
<updated>2021-12-16T00:00:00Z</updated>
<content type="xhtml">
@ -28,8 +28,9 @@
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Discord Bot - all commands are now case INsensitive, along with the profile id and the alias.</li>
<li>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.</li>
<li>Made changes to the code to help improve performance.</li>
<li>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.</li>
</ul>
</p>
</div>

View file

@ -7,6 +7,29 @@
<link href="http://servermanagers.freeforums.net/" />
<updated>2021-12-17T00:00:00Z</updated>
<entry>
<id>urn:uuid:9A427D82-9904-44F5-8C1E-7C943049869A</id>
<title>1.1.58 (1.1.58.8)</title>
<summary>1.1.58.8</summary>
<link href="" />
<updated>2021-12-17T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Discord Bot - all commands are now case INsensitive, along with the profile id and the alias.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:9A427D82-9904-44F5-8C1E-7C943049869A</id>
<title>1.1.58 (1.1.58.7)</title>

View file

@ -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();
}

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
namespace ServerManagerTool.Plugin.Common
{
internal static class IEnumerableExtensions
{
public static bool IsEmpty<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
if (enumerator.MoveNext())
{
return false;
}
}
return true;
}
public static bool HasOne<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
var count = 0;
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (++count > 1)
return false;
}
}
return count == 1;
}
}
}

View file

@ -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)

View file

@ -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");

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
namespace ServerManagerTool.Plugin.Discord
{
internal static class IEnumerableExtensions
{
public static bool IsEmpty<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
if (enumerator.MoveNext())
{
return false;
}
}
return true;
}
public static bool HasOne<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
var count = 0;
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (++count > 1)
return false;
}
}
return count == 1;
}
}
}

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
namespace ServerManagerTool.Common.Extensions
{
public static class IEnumerableExtensions
{
public static bool IsEmpty<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
if (enumerator.MoveNext())
{
return false;
}
}
return true;
}
public static bool HasOne<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
var count = 0;
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (++count > 1)
return false;
}
}
return count == 1;
}
}
}

View file

@ -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<TimeTrigger>();
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<BootTrigger>();
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<LogonTrigger>();
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<TimeTrigger>();
if (triggers.Count() == 0)
if (triggers.IsEmpty())
{
var trigger = new TimeTrigger
{

View file

@ -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))

View file

@ -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

View file

@ -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."));

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
namespace ServerManagerTool.Updater
{
public static class IEnumerableExtensions
{
public static bool IsEmpty<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
if (enumerator.MoveNext())
{
return false;
}
}
return true;
}
public static bool HasOne<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
var count = 0;
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (++count > 1)
return false;
}
}
return count == 1;
}
}
}

View file

@ -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