qol: use type keywords and more interpolated strings

This commit is contained in:
Gary Sharp
2025-07-20 15:44:44 +10:00
parent 58546ed16d
commit 4c27b0ff3c
16 changed files with 66 additions and 86 deletions
+1 -1
View File
@@ -105,7 +105,7 @@ namespace Disco.Client
}
}
Debug.WriteLine("Error Report Logged to Server; Response: {0}", reportResponse);
Debug.WriteLine($"Error Report Logged to Server; Response: {reportResponse}");
}
#endregion
+1 -1
View File
@@ -104,7 +104,7 @@ namespace Disco.Client.Extensions
using (RegistryKey regWinlogon = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true))
{
regWinlogon.SetValue("DefaultDomainName", enrolResponse.DomainName, RegistryValueKind.String);
regWinlogon.SetValue("DefaultUserName", String.Empty, RegistryValueKind.String);
regWinlogon.SetValue("DefaultUserName", string.Empty, RegistryValueKind.String);
}
using (RegistryKey regLogonUI = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI", true))
{
@@ -44,7 +44,7 @@ namespace Disco.ClientBootstrapper.Interop
}
catch (Exception ex)
{
throw new IOException(string.Format("Unable to delete folder: ", InstallLocation), ex);
throw new IOException($"Unable to delete folder: {InstallLocation}", ex);
}
}
if (!Directory.Exists(InstallLocation))
@@ -14,8 +14,8 @@ namespace Disco.ClientBootstrapper.Interop
public string Name { get; set; }
public string NetConnectionID { get; set; }
public string MACAddress { get; set; }
public UInt64 Speed { get; set; }
public UInt16 LastConnectionStatus { get; set; }
public ulong Speed { get; set; }
public ushort LastConnectionStatus { get; set; }
public bool IsWireless { get; set; }
public string WirelessInterfaceDescription { get; set; }
public int LastWirelessConnectionStatus { get; set; }
@@ -28,12 +28,12 @@ namespace Disco.ClientBootstrapper.Interop
private void UpdateFromWmi(ManagementObject wmiObject)
{
WmiPath = (string)wmiObject.GetPropertyValue("__PATH");
Index = (UInt32)wmiObject.GetPropertyValue("Index");
Index = (uint)wmiObject.GetPropertyValue("Index");
Guid = Guid.Parse((string)wmiObject.GetPropertyValue("GUID"));
MACAddress = (string)wmiObject.GetPropertyValue("MACAddress");
Name = (string)wmiObject.GetPropertyValue("Name");
NetConnectionID = (string)wmiObject.GetPropertyValue("NetConnectionID");
Speed = (UInt64)wmiObject.GetPropertyValue("Speed");
Speed = (ulong)wmiObject.GetPropertyValue("Speed");
_ = ConnectionStatus;
IsWireless = true;
try
@@ -111,46 +111,46 @@ namespace Disco.ClientBootstrapper.Interop
}
}
public UInt16 ConnectionStatus
public ushort ConnectionStatus
{
get
{
using (var wmiObject = new ManagementObject(WmiPath))
{
LastConnectionStatus = (UInt16)wmiObject.GetPropertyValue("NetConnectionStatus");
LastConnectionStatus = (ushort)wmiObject.GetPropertyValue("NetConnectionStatus");
}
return LastConnectionStatus;
}
}
public string ConnectionStatusMeaning(UInt16 status)
public string ConnectionStatusMeaning(ushort status)
{
switch (status)
{
case (UInt16)0:
case (ushort)0:
return "Disconnected";
case (UInt16)1:
case (ushort)1:
return "Connecting";
case (UInt16)2:
case (ushort)2:
return "Connected";
case (UInt16)3:
case (ushort)3:
return "Disconnecting";
case (UInt16)4:
case (ushort)4:
return "Hardware not present";
case (UInt16)5:
case (ushort)5:
return "Hardware disabled";
case (UInt16)6:
case (ushort)6:
return "Hardware malfunction";
case (UInt16)7:
case (ushort)7:
return "Media disconnected";
case (UInt16)8:
case (ushort)8:
return "Authenticating";
case (UInt16)9:
case (ushort)9:
return "Authentication succeeded";
case (UInt16)10:
case (ushort)10:
return "Authentication failed";
case (UInt16)11:
case (ushort)11:
return "Invalid address";
case (UInt16)12:
case (ushort)12:
return "Credentials required";
default:
return "Unknown";
+20 -40
View File
@@ -139,8 +139,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
CreateFileAccessPrivate fileAccess = GetMappedFileAccess(access);
if (fileAccess == CreateFileAccessPrivate.Read && (!File.Exists(imageFilePath) || (CreateFileMode.OpenExisting != mode)))
{
throw new System.UnauthorizedAccessException(string.Format(CultureInfo.CurrentCulture,
"Read access can be specified only with OpenExisting mode or OpenAlways mode when the .wim file does not exist."));
throw new System.UnauthorizedAccessException("Read access can be specified only with OpenExisting mode or OpenAlways mode when the .wim file does not exist.");
}
//
@@ -153,7 +152,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
}
catch (System.DllNotFoundException ex)
{
throw new System.DllNotFoundException(string.Format(CultureInfo.CurrentCulture,
throw new System.DllNotFoundException(string.Format(
"Unable to load WIM libraries. Make sure the correct DLLs are present (Wimgapi.dll and Xmlrw.dll)."), ex.InnerException);
}
@@ -172,8 +171,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Unable to open the .wim file {0}.", imageFilePath));
throw new System.InvalidOperationException($"Unable to open the .wim file {imageFilePath}.");
}
//
@@ -575,12 +573,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//1. Leading 0xFEFF
//2. Be in <IMAGE></IMAGE>
//
string formattedXml = String.Format(CultureInfo.InvariantCulture,
"{0}{1}{2}{3}",
UNICODE_FILE_MARKER,
"<IMAGE>",
imageInformation,
"</IMAGE>");
string formattedXml = $"{UNICODE_FILE_MARKER}{"<IMAGE>"}{imageInformation}{"</IMAGE>"}";
NativeMethods.SetImageInformation(m_ImageHandle, formattedXml);
GC.KeepAlive(this);
@@ -691,9 +684,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Everything failed; throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Unable to open/create .wim file {0}. Error = {1}",
imageFile, rc));
throw new System.InvalidOperationException($"Unable to open/create .wim file {imageFile}. Error = {rc}");
}
return windowsImageHandle;
@@ -728,8 +719,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Unable to close image handle. Error = {0}", rc));
throw new System.InvalidOperationException($"Unable to close image handle. Error = {rc}");
}
}
@@ -764,7 +754,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unable to set temporary path. Error = {0}", rc));
throw new System.InvalidOperationException($"Unable to set temporary path. Error = {rc}");
}
}
@@ -801,7 +791,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unable to load image. Error = {0}", rc));
throw new System.InvalidOperationException($"Unable to load image. Error = {rc}");
}
return hWim;
@@ -839,8 +829,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Failed to capture image from {0}. Error = {1}", path, rc));
throw new System.InvalidOperationException($"Failed to capture image from {path}. Error = {rc}");
}
return hImage;
}
@@ -880,7 +869,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unable to get image count. Error = {0}", rc));
throw new System.InvalidOperationException($"Unable to get image count. Error = {rc}");
}
return count;
@@ -982,17 +971,14 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Unable to mount image {0} to {1}.", windowsImageFileName, mountPath));
throw new System.InvalidOperationException($"Unable to mount image {windowsImageFileName} to {mountPath}.");
}
if (status == false)
{
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Unable to mount image {0} to {1}. Error = {2}",
windowsImageFileName, mountPath, rc));
throw new System.InvalidOperationException($"Unable to mount image {windowsImageFileName} to {mountPath}. Error = {rc}");
}
}
@@ -1029,8 +1015,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Unable to apply image to {0}. Error = {1}", applicationPath, rc));
throw new System.InvalidOperationException($"Unable to apply image to {applicationPath}. Error = {rc}");
}
}
@@ -1070,8 +1055,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Unable to get image information. Error = {0}", rc));
throw new System.InvalidOperationException($"Unable to get image information. Error = {rc}");
}
string s = Marshal.PtrToStringUni(info);
@@ -1119,8 +1103,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Unable to set image information. Error = {0}", rc));
throw new System.InvalidOperationException($"Unable to set image information. Error = {rc}");
}
}
@@ -1161,8 +1144,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.StackOverflowException(string.Format(CultureInfo.CurrentCulture,
"Unable to unmount image {0} from {1}.", wimdowsImageFileName, mountPath),
throw new System.StackOverflowException($"Unable to unmount image {wimdowsImageFileName} from {mountPath}.",
ex.InnerException);
}
if (status == false)
@@ -1170,9 +1152,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Unable to unmount image {0} from {1}. Error = {2}",
wimdowsImageFileName, mountPath, rc));
throw new System.InvalidOperationException($"Unable to unmount image {wimdowsImageFileName} from {mountPath}. Error = {rc}");
}
}
@@ -1228,7 +1208,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
//Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unable to register message callback."));
throw new System.InvalidOperationException("Unable to register message callback.");
}
}
@@ -1260,7 +1240,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
//
// Throw an exception
//
throw new System.InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unable to unregister message callback."));
throw new System.InvalidOperationException("Unable to unregister message callback.");
}
}
@@ -1358,7 +1338,7 @@ namespace Disco.ClientBootstrapper.Interop.WIMInterop
fileAccess = CreateFileAccessPrivate.Write;
break;
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "No file access level specified."));
throw new ArgumentException("No file access level specified.");
}
return fileAccess;
}
+11 -11
View File
@@ -177,18 +177,18 @@ namespace Disco.Data.Configuration
#region Helpers
private static bool IsConvertableFromString(Type t)
{
if (t == typeof(Boolean) ||
t == typeof(Char) ||
t == typeof(SByte) ||
t == typeof(Byte) ||
t == typeof(Int16) || t == typeof(UInt16) ||
t == typeof(Int32) || t == typeof(UInt32) ||
t == typeof(Int64) || t == typeof(UInt64) ||
t == typeof(Single) ||
t == typeof(Double) ||
t == typeof(Decimal) ||
if (t == typeof(bool) ||
t == typeof(char) ||
t == typeof(sbyte) ||
t == typeof(byte) ||
t == typeof(short) || t == typeof(ushort) ||
t == typeof(int) || t == typeof(uint) ||
t == typeof(long) || t == typeof(ulong) ||
t == typeof(float) ||
t == typeof(double) ||
t == typeof(decimal) ||
t == typeof(DateTime) ||
t == typeof(String))
t == typeof(string))
return true;
else
return false;
@@ -236,7 +236,7 @@ namespace Disco.Services.Documents
private static int chooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, ZXing.QrCode.Internal.Version version, ByteMatrix matrix)
{
int minPenalty = Int32.MaxValue; // Lower penalty is better.
int minPenalty = int.MaxValue; // Lower penalty is better.
int bestMaskPattern = -1;
// We try all mask patterns to choose the best one.
for (int maskPattern = 0; maskPattern < QRCode.NUM_MASK_PATTERNS; maskPattern++)
+2 -2
View File
@@ -203,7 +203,7 @@ namespace Disco.Services
AttachmentDataStoreExtensions.RepositoryFilename);
if (!publishJobResult.Success)
throw new Exception(string.Format("Disco ICT Online Services failed with the following message: ", publishJobResult.ErrorMessage));
throw new Exception($"Disco ICT Online Services failed with the following message: {publishJobResult.ErrorMessage}");
if (string.IsNullOrWhiteSpace(FaultDescription))
FaultDescription = publishJobResult.PublishMessage;
@@ -433,7 +433,7 @@ namespace Disco.Services
AttachmentDataStoreExtensions.RepositoryFilename);
if (!publishJobResult.Success)
throw new Exception(string.Format("Disco ICT Online Services failed with the following message: ", publishJobResult.ErrorMessage));
throw new Exception($"Disco ICT Online Services failed with the following message: {publishJobResult.ErrorMessage}");
if (string.IsNullOrWhiteSpace(RepairDescription))
RepairDescription = publishJobResult.PublishMessage;
@@ -126,7 +126,7 @@ namespace Disco.Services.Jobs.JobQueues
JobId = jqj.JobId,
TechUserId = jqj.AddedUserId,
Timestamp = jqj.AddedDate,
Comments = string.Format("# Added to Queue\r\n**{0}**\r\nPriority: **{1}**\r\n{2}", Environment.NewLine, queue.Name, jqj.Priority.ToString(), string.IsNullOrWhiteSpace(jqj.AddedComment) ? "<no comment>" : jqj.AddedComment)
Comments = $"# Added to Queue\r\n**{queue.Name}**\r\nPriority: **{jqj.Priority.ToString()}**\r\n{(string.IsNullOrWhiteSpace(jqj.AddedComment) ? "<no comment>" : jqj.AddedComment)}"
});
Database.JobLogs.Add(new JobLog()
{
+1 -1
View File
@@ -16,7 +16,7 @@ namespace Disco.Services.Logging
private static object _LogModulesLock = new object();
private static LogContext _Current;
private static object _CurrentLock = new Object();
private static object _CurrentLock = new object();
public static LogContext Current
{
get
+1 -1
View File
@@ -260,7 +260,7 @@ namespace Disco.Services.Plugins
int num = (obj2 != null) ? (((int)obj2) + 1) : 1000;
ViewPage.ViewContext.HttpContext.Items["DiscoPluginLastFormNum"] = num;
builder.GenerateId(string.Format(CultureInfo.InvariantCulture, "form{0}", new object[] { num }));
builder.GenerateId($"form{num}");
}
ViewPage.ViewContext.Writer.Write(builder.ToString(TagRenderMode.StartTag));
MvcForm form = new MvcForm(ViewPage.ViewContext);
+1 -1
View File
@@ -369,7 +369,7 @@ namespace Disco.Services.Plugins
_PluginAssemblyManifests = _PluginManifests.Values.ToDictionary(p => p.PluginAssembly, p => p);
}
public static PluginManifest UpdatePlugin(DiscoDataContext Database, PluginManifest ExistingManifest, String UpdatePluginPackageFilePath, PluginLibraryIncompatibility PluginLibraryIncompatibility = null)
public static PluginManifest UpdatePlugin(DiscoDataContext Database, PluginManifest ExistingManifest, string UpdatePluginPackageFilePath, PluginLibraryIncompatibility PluginLibraryIncompatibility = null)
{
PluginManifest updatedManifest;
+1 -1
View File
@@ -63,7 +63,7 @@ namespace Disco.Services.Plugins
int num = (lastFormNumber != null) ? (((int)lastFormNumber) + 1) : 1000;
ViewPage.ViewContext.HttpContext.Items["DiscoPluginLastFormNum"] = num;
builder.GenerateId(string.Format(CultureInfo.InvariantCulture, "form{0}", new object[] { num }));
builder.GenerateId($"form{num}");
}
ViewPage.ViewContext.Writer.Write(builder.ToString(TagRenderMode.StartTag));
MvcForm form = new MvcForm(ViewPage.ViewContext);
@@ -27,7 +27,7 @@ namespace Disco.Web.Extensions
selectItems = organisationAddressess.Select(wpd => new SelectListItem { Value = wpd.Id.Value.ToString(), Text = $"{wpd.Name} ({wpd.ShortName})", Selected = (SelectedId.Equals(wpd.Id)) }).ToList();
if (IncludeInstructionFirst)
selectItems.Insert(0, new SelectListItem() { Value = String.Empty, Text = $"<{InstructionMessage}>", Selected = !SelectedId.HasValue });
selectItems.Insert(0, new SelectListItem() { Value = string.Empty, Text = $"<{InstructionMessage}>", Selected = !SelectedId.HasValue });
return selectItems;
}
@@ -52,7 +52,7 @@ namespace Disco.Web.Extensions
var selectItems = items.OrderBy(i => i.Text).ToList();
if (IncludeInstructionFirst)
selectItems.Insert(0, new SelectListItem() { Value = String.Empty, Text = $"<{InstructionMessage}>", Selected = (selectedIds?.Count ?? 0) != 0 });
selectItems.Insert(0, new SelectListItem() { Value = string.Empty, Text = $"<{InstructionMessage}>", Selected = (selectedIds?.Count ?? 0) != 0 });
return selectItems;
}
@@ -76,7 +76,7 @@ namespace Disco.Web.Extensions
selectItems = PluginDefinitions.Select(wpd => new SelectListItem { Value = wpd.Id, Text = wpd.Name, Selected = (SelectedId.Equals(wpd.Id)) }).ToList();
if (IncludeInstructionFirst)
selectItems.Insert(0, new SelectListItem() { Value = String.Empty, Text = $"<{InstructionMessage}>", Selected = String.IsNullOrEmpty(SelectedId) });
selectItems.Insert(0, new SelectListItem() { Value = string.Empty, Text = $"<{InstructionMessage}>", Selected = string.IsNullOrEmpty(SelectedId) });
return selectItems;
}
+1 -1
View File
@@ -45,7 +45,7 @@ namespace Disco.Web
BundleTable.Add(new FileBundle($"~/ClientScripts/Modules/{f.Name.Substring(0, f.Name.Length - 3)}", f.FullName));
#else
foreach (FileInfo f in new DirectoryInfo(HttpContext.Current.Server.MapPath("~/ClientSource/Scripts/Modules")).EnumerateFiles("*.min.js", SearchOption.TopDirectoryOnly))
BundleTable.Add(new FileBundle(string.Format("~/ClientScripts/Modules/{0}", f.Name.Substring(0, f.Name.Length - 7)), f.FullName));
BundleTable.Add(new FileBundle($"~/ClientScripts/Modules/{f.Name.Substring(0, f.Name.Length - 7)}", f.FullName));
#endif
}