Skip to content

Commit

Permalink
imp - brk|doc - Driver management code improved
Browse files Browse the repository at this point in the history
---

We've got rid of another dictionary in favor of lists to use the DriverName property to query the driver name for consistency.

---

Type: imp
Breaking: True
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Feb 28, 2024
1 parent 6fd775b commit fa1cfba
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 143 deletions.
24 changes: 12 additions & 12 deletions private/Nitrocid.Tests/Drivers/DriverManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ public void TestGetDriverNames(DriverTypes type)

[TestMethod]
[DataRow(DriverTypes.Console, "Default")]
[DataRow(DriverTypes.Encryption, "SHA256")]
[DataRow(DriverTypes.Encryption, "Default")]
[DataRow(DriverTypes.Filesystem, "Default")]
[DataRow(DriverTypes.Network, "Default")]
[DataRow(DriverTypes.RNG, "Default")]
[DataRow(DriverTypes.Regexp, "Default")]
[DataRow(DriverTypes.DebugLogger, "Default")]
[DataRow(DriverTypes.Encoding, "AES")]
[DataRow(DriverTypes.Encoding, "Default")]
[DataRow(DriverTypes.HardwareProber, "Default")]
[DataRow(DriverTypes.Sorting, "Default")]
[DataRow(DriverTypes.Input, "Default")]
Expand Down Expand Up @@ -277,13 +277,13 @@ public void TestGetFallbackDriverName(DriverTypes type)

[TestMethod]
[DataRow(DriverTypes.Console, "Default")]
[DataRow(DriverTypes.Encryption, "SHA256")]
[DataRow(DriverTypes.Encryption, "Default")]
[DataRow(DriverTypes.Filesystem, "Default")]
[DataRow(DriverTypes.Network, "Default")]
[DataRow(DriverTypes.RNG, "Default")]
[DataRow(DriverTypes.Regexp, "Default")]
[DataRow(DriverTypes.DebugLogger, "Default")]
[DataRow(DriverTypes.Encoding, "AES")]
[DataRow(DriverTypes.Encoding, "Default")]
[DataRow(DriverTypes.HardwareProber, "Default")]
[DataRow(DriverTypes.Sorting, "Default")]
[DataRow(DriverTypes.Input, "Default")]
Expand All @@ -296,13 +296,13 @@ public void TestGetCurrentDriver(DriverTypes driverType, string expectedName)

[TestMethod]
[DataRow(DriverTypes.Console, "Default")]
[DataRow(DriverTypes.Encryption, "SHA256")]
[DataRow(DriverTypes.Encryption, "Default")]
[DataRow(DriverTypes.Filesystem, "Default")]
[DataRow(DriverTypes.Network, "Default")]
[DataRow(DriverTypes.RNG, "Default")]
[DataRow(DriverTypes.Regexp, "Default")]
[DataRow(DriverTypes.DebugLogger, "Default")]
[DataRow(DriverTypes.Encoding, "AES")]
[DataRow(DriverTypes.Encoding, "Default")]
[DataRow(DriverTypes.HardwareProber, "Default")]
[DataRow(DriverTypes.Sorting, "Default")]
[DataRow(DriverTypes.Input, "Default")]
Expand All @@ -315,13 +315,13 @@ public void TestGetCurrentDriverLocal(DriverTypes driverType, string expectedNam

[TestMethod]
[DataRow(DriverTypes.Console, "File", "File", "Default")]
[DataRow(DriverTypes.Encryption, "SHA512", "SHA512", "SHA256")]
[DataRow(DriverTypes.Encryption, "SHA512", "SHA512", "Default")]
[DataRow(DriverTypes.Filesystem, "Default", "Default", "Default")]
[DataRow(DriverTypes.Network, "Default", "Default", "Default")]
[DataRow(DriverTypes.RNG, "Standard", "Standard", "Default")]
[DataRow(DriverTypes.Regexp, "Default", "Default", "Default")]
[DataRow(DriverTypes.DebugLogger, "UnitTest", "UnitTest", "Default")]
[DataRow(DriverTypes.Encoding, "RSA", "RSA", "AES")]
[DataRow(DriverTypes.Encoding, "RSA", "RSA", "Default")]
[DataRow(DriverTypes.HardwareProber, "Default", "Default", "Default")]
[DataRow(DriverTypes.Sorting, "Default", "Default", "Default")]
[DataRow(DriverTypes.Input, "Default", "Default", "Default")]
Expand All @@ -338,13 +338,13 @@ public void TestBeginLocalDriver(DriverTypes type, string name, string expectedN

[TestMethod]
[DataRow(DriverTypes.Console, "File", "Default", "Default")]
[DataRow(DriverTypes.Encryption, "SHA512", "SHA512", "SHA256")]
[DataRow(DriverTypes.Encryption, "SHA512", "SHA512", "Default")]
[DataRow(DriverTypes.Filesystem, "Default", "Default", "Default")]
[DataRow(DriverTypes.Network, "Default", "Default", "Default")]
[DataRow(DriverTypes.RNG, "Standard", "Standard", "Default")]
[DataRow(DriverTypes.Regexp, "Default", "Default", "Default")]
[DataRow(DriverTypes.DebugLogger, "UnitTest", "Default", "Default")]
[DataRow(DriverTypes.Encoding, "RSA", "RSA", "AES")]
[DataRow(DriverTypes.Encoding, "RSA", "RSA", "Default")]
[DataRow(DriverTypes.HardwareProber, "Default", "Default", "Default")]
[DataRow(DriverTypes.Sorting, "Default", "Default", "Default")]
[DataRow(DriverTypes.Input, "Default", "Default", "Default")]
Expand Down Expand Up @@ -530,8 +530,8 @@ public void TestGetDebugLoggerDriverNames()
public void TestSetEncodingDriver()
{
EncodingDriverTools.SetEncodingDriver("AES");
DriverHandler.CurrentEncodingDriver.DriverName.ShouldBe("AES");
DriverHandler.CurrentEncodingDriverLocal.DriverName.ShouldBe("AES");
DriverHandler.CurrentEncodingDriver.DriverName.ShouldBe("Default");
DriverHandler.CurrentEncodingDriverLocal.DriverName.ShouldBe("Default");
}

[TestMethod]
Expand Down
10 changes: 5 additions & 5 deletions public/Nitrocid/Drivers/Console/ConsoleDriverTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public static void SetConsoleDriver(string name) =>
/// Gets the console drivers
/// </summary>
/// <exception cref="KernelException"></exception>
public static Dictionary<string, IDriver> GetConsoleDrivers()
public static List<IDriver> GetConsoleDrivers()
{
// First, exclude internal drivers from the list
var filteredDrivers = DriverHandler.drivers[DriverTypes.Console].Where((kvp) => !kvp.Value.DriverInternal);
var filteredCustomDrivers = DriverHandler.customDrivers[DriverTypes.Console].Where((kvp) => !kvp.Value.DriverInternal);
var filteredDrivers = DriverHandler.drivers[DriverTypes.Console].Where((kvp) => !kvp.DriverInternal);
var filteredCustomDrivers = DriverHandler.customDrivers[DriverTypes.Console].Where((kvp) => !kvp.DriverInternal);

// Then, get the list of drivers
return filteredDrivers.Union(filteredCustomDrivers).ToDictionary((kvp) => kvp.Key, (kvp) => kvp.Value);
return filteredDrivers.Union(filteredCustomDrivers).ToList();
}

/// <summary>
Expand All @@ -58,7 +58,7 @@ public static string[] GetConsoleDriverNames()
{
// Get the drivers and fetch their names
var drivers = GetConsoleDrivers();
return drivers.Select((kvp) => kvp.Key).ToArray();
return drivers.Select((kvp) => kvp.DriverName).ToArray();
}
}
}
10 changes: 5 additions & 5 deletions public/Nitrocid/Drivers/DebugLogger/DebugLoggerDriverTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public static void SetDebugLoggerDriver(string name) =>
/// Gets the regular expression drivers
/// </summary>
/// <exception cref="KernelException"></exception>
public static Dictionary<string, IDriver> GetDebugLoggerDrivers()
public static List<IDriver> GetDebugLoggerDrivers()
{
// First, exclude internal drivers from the list
var filteredDrivers = DriverHandler.drivers[DriverTypes.DebugLogger].Where((kvp) => !kvp.Value.DriverInternal);
var filteredCustomDrivers = DriverHandler.customDrivers[DriverTypes.DebugLogger].Where((kvp) => !kvp.Value.DriverInternal);
var filteredDrivers = DriverHandler.drivers[DriverTypes.DebugLogger].Where((kvp) => !kvp.DriverInternal);
var filteredCustomDrivers = DriverHandler.customDrivers[DriverTypes.DebugLogger].Where((kvp) => !kvp.DriverInternal);

// Then, get the list of drivers
return filteredDrivers.Union(filteredCustomDrivers).ToDictionary((kvp) => kvp.Key, (kvp) => kvp.Value);
return filteredDrivers.Union(filteredCustomDrivers).ToList();
}

/// <summary>
Expand All @@ -58,7 +58,7 @@ public static string[] GetDebugLoggerDriverNames()
{
// Get the drivers and fetch their names
var drivers = GetDebugLoggerDrivers();
return drivers.Select((kvp) => kvp.Key).ToArray();
return drivers.Select((kvp) => kvp.DriverName).ToArray();
}
}
}
Loading

0 comments on commit fa1cfba

Please sign in to comment.