mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Removal of ToArray()
This commit is contained in:
parent
9eb22da9e7
commit
9f5cf132f0
41 changed files with 184 additions and 189 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using ServerManagerTool.Common.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
|
@ -13,13 +14,13 @@ namespace ServerManagerTool.Common.Utils
|
|||
/// <param name="file">The name of the initialization file.</param>
|
||||
/// <param name="sectionName">The name of the section in the initialization file.</param>
|
||||
/// <returns>A string array containing the key name and value pairs associated with the named section.</returns>
|
||||
public static string[] ReadSection(string file, string sectionName)
|
||||
public static IEnumerable<string> ReadSection(string file, string sectionName)
|
||||
{
|
||||
if (sectionName == null)
|
||||
return new string[0];
|
||||
|
||||
var iniFile = ReadFromFile(file);
|
||||
return iniFile?.GetSection(sectionName)?.KeysToStringArray() ?? new string[0];
|
||||
return iniFile?.GetSection(sectionName)?.KeysToStringEnumerable() ?? new string[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -46,7 +47,7 @@ namespace ServerManagerTool.Common.Utils
|
|||
/// <param name="sectionName">The name of the section in which data is written.</param>
|
||||
/// <param name="keysValuePairs">An array of key names and associated values that are to be written to the named section.</param>
|
||||
/// <returns>True if the function succeeds; otherwise False.</returns>
|
||||
public static bool WriteSection(string file, string sectionName, string[] keysValuePairs)
|
||||
public static bool WriteSection(string file, string sectionName, IEnumerable<string> keysValuePairs)
|
||||
{
|
||||
if (sectionName == null)
|
||||
return false;
|
||||
|
|
@ -165,7 +166,7 @@ namespace ServerManagerTool.Common.Utils
|
|||
{
|
||||
writer.WriteLine($"[{section.SectionName}]");
|
||||
|
||||
foreach (var keyString in section.KeysToStringArray())
|
||||
foreach (var keyString in section.KeysToStringEnumerable())
|
||||
{
|
||||
writer.WriteLine(keyString);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ namespace ServerManagerTool.Common.Utils
|
|||
}
|
||||
}
|
||||
|
||||
public static BigInteger[] GetProcessorAffinityList()
|
||||
public static IEnumerable<BigInteger> GetProcessorAffinityList()
|
||||
{
|
||||
var processorCount = ProcessorCount;
|
||||
var results = new List<BigInteger>(processorCount + 1);
|
||||
|
|
@ -295,7 +295,7 @@ namespace ServerManagerTool.Common.Utils
|
|||
{
|
||||
results.Add((BigInteger)Math.Pow(2, index));
|
||||
}
|
||||
return results.ToArray();
|
||||
return results;
|
||||
}
|
||||
|
||||
public static string[] GetProcessPriorityList()
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace ServerManagerTool.Common.Utils
|
|||
|
||||
try
|
||||
{
|
||||
var filesToDelete = new DirectoryInfo(backupPath).GetFiles($"{settingsFileName}_*{settingsFileExt}").Where(f => f.LastWriteTimeUtc.AddDays(7) < DateTime.UtcNow).ToArray();
|
||||
var filesToDelete = new DirectoryInfo(backupPath).GetFiles($"{settingsFileName}_*{settingsFileExt}").Where(f => f.LastWriteTimeUtc.AddDays(7) < DateTime.UtcNow);
|
||||
foreach (var fileToDelete in filesToDelete)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using Ionic.Zip;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
|
@ -68,11 +69,11 @@ namespace ServerManagerTool.Common.Utils
|
|||
}
|
||||
}
|
||||
|
||||
public static void UpdateFiles(string zipFile, string[] filesToZip, string comment = "", bool preserveDirHierarchy = true, string directoryPathInArchive = "")
|
||||
public static void UpdateFiles(string zipFile, IEnumerable<string> filesToZip, string comment = "", bool preserveDirHierarchy = true, string directoryPathInArchive = "")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(zipFile))
|
||||
throw new ArgumentNullException(nameof(zipFile));
|
||||
if (filesToZip == null || filesToZip.Length == 0)
|
||||
if (!filesToZip.Any())
|
||||
return;
|
||||
|
||||
if (!File.Exists(zipFile))
|
||||
|
|
@ -160,11 +161,11 @@ namespace ServerManagerTool.Common.Utils
|
|||
}
|
||||
}
|
||||
|
||||
public static void ZipFiles(string zipFile, string[] filesToZip, string comment = "", bool preserveDirHierarchy = true, string directoryPathInArchive = "")
|
||||
public static void ZipFiles(string zipFile, IEnumerable<string> filesToZip, string comment = "", bool preserveDirHierarchy = true, string directoryPathInArchive = "")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(zipFile))
|
||||
throw new ArgumentNullException(nameof(zipFile));
|
||||
if (filesToZip == null || filesToZip.Length == 0)
|
||||
if (!filesToZip.Any())
|
||||
throw new ArgumentNullException(nameof(filesToZip));
|
||||
|
||||
using (var zip = new ZipFile(zipFile))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue