Removal of ToArray()

This commit is contained in:
Brett Hewitson 2021-12-16 00:21:23 +10:00
parent 9eb22da9e7
commit 9f5cf132f0
41 changed files with 184 additions and 189 deletions

View file

@ -1790,7 +1790,7 @@ namespace ServerManagerTool.Lib
comment.AppendLine($"Profile Name: {_profile.ProfileName}");
comment.AppendLine($"Process: {ServerProcess}");
ZipUtils.ZipFiles(backupFile, files.ToArray(), comment.ToString(), false);
ZipUtils.ZipFiles(backupFile, files, comment.ToString(), false);
LogProfileMessage($"Backup file created - {backupFile}");
}
@ -1910,7 +1910,7 @@ namespace ServerManagerTool.Lib
ZipUtils.ZipAFile(backupFile, worldFileName, worldBackupFile, comment.ToString());
if (files.Count > 0)
ZipUtils.UpdateFiles(backupFile, files.ToArray(), null, false, "");
ZipUtils.UpdateFiles(backupFile, files, null, false, "");
LogProfileMessage($"Backed up world files - {saveFolder}");
LogProfileMessage($"Backup file created - {backupFile}");
@ -2851,7 +2851,7 @@ namespace ServerManagerTool.Lib
if (ExitCode == EXITCODE_NORMALEXIT)
{
// get the profile associated with the branch
var profiles = _profiles.Keys.Where(p => p.EnableAutoUpdate && p.BranchName.Equals(branch.BranchName, StringComparison.OrdinalIgnoreCase)).ToArray();
var profiles = _profiles.Keys.Where(p => p.EnableAutoUpdate && p.BranchName.Equals(branch.BranchName, StringComparison.OrdinalIgnoreCase));
var profileExitCodes = new ConcurrentDictionary<ServerProfileSnapshot, int>();
if (Config.Default.AutoUpdate_ParallelUpdate)
@ -3102,7 +3102,7 @@ namespace ServerManagerTool.Lib
if (exitCode == EXITCODE_NORMALEXIT)
{
var branches = _profiles.Keys.Where(p => p.EnableAutoUpdate).Select(p => BranchSnapshot.Create(p)).Distinct(new BranchSnapshotComparer()).ToArray();
var branches = _profiles.Keys.Where(p => p.EnableAutoUpdate).Select(p => BranchSnapshot.Create(p)).Distinct(new BranchSnapshotComparer());
var exitCodes = new ConcurrentDictionary<BranchSnapshot, int>();
// update the server cache for each branch

View file

@ -212,7 +212,7 @@ namespace ServerManagerTool.Lib
return;
// remove any players that do not have a player record.
var droppedPlayers = this._players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null).ToArray();
var droppedPlayers = this._players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null);
foreach (var droppedPlayer in droppedPlayers)
{
_players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player);

View file

@ -792,11 +792,9 @@ namespace ServerManagerTool.Lib
}
}
private static Enum[] GetExclusions()
private static IEnumerable<Enum> GetExclusions()
{
var exclusions = new List<Enum>();
return exclusions.ToArray();
return new List<Enum>();
}
public string GetLauncherFile() => Path.Combine(GetProfileServerConfigDir(), Config.Default.LauncherFile);
@ -885,7 +883,7 @@ namespace ServerManagerTool.Lib
return profile;
}
public static ServerProfile LoadFromConfigFiles(string file, ServerProfile profile, Enum[] exclusions = null)
public static ServerProfile LoadFromConfigFiles(string file, ServerProfile profile, IEnumerable<Enum> exclusions = null)
{
if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
return null;
@ -1108,7 +1106,7 @@ namespace ServerManagerTool.Lib
SaveConfigFile(serverConfigDir);
}
public void SaveConfigFile(string configDir, Enum[] exclusions = null)
public void SaveConfigFile(string configDir, IEnumerable<Enum> exclusions = null)
{
if (exclusions == null)
exclusions = GetExclusions();
@ -1656,7 +1654,7 @@ namespace ServerManagerTool.Lib
Directory.CreateDirectory(folder);
var file = Path.Combine(folder, Config.Default.ServerBlacklistFile);
File.WriteAllLines(file, this.ServerFilesBlacklisted.ToArray());
File.WriteAllLines(file, this.ServerFilesBlacklisted.ToEnumerable());
}
catch (Exception ex)
{
@ -1673,7 +1671,7 @@ namespace ServerManagerTool.Lib
Directory.CreateDirectory(folder);
var file = Path.Combine(folder, Config.Default.ServerWhitelistFile);
File.WriteAllLines(file, this.ServerFilesWhitelisted.ToArray());
File.WriteAllLines(file, this.ServerFilesWhitelisted.ToEnumerable());
}
catch (Exception ex)
{

View file

@ -450,7 +450,7 @@ namespace ServerManagerTool.Lib
return new List<string>();
// remove any players that do not have a player record.
var droppedPlayers = this._players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null).ToArray();
var droppedPlayers = this._players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null);
foreach (var droppedPlayer in droppedPlayers)
{
_players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player);