qol: interpolated strings

This commit is contained in:
Gary Sharp
2025-07-20 11:56:34 +10:00
parent 4e518d6684
commit 7faebe56a8
108 changed files with 342 additions and 350 deletions
@@ -156,7 +156,7 @@ namespace Disco.Services
if (j.CanDelete())
j.OnDelete(Database);
else
throw new InvalidOperationException(string.Format("Deletion of Device is Denied (See Job# {0})", j.Id));
throw new InvalidOperationException($"Deletion of Device is Denied (See Job# {j.Id})");
}
else
{
@@ -169,8 +169,7 @@ namespace Disco.Services
JobId = j.Id,
TechUserId = UserService.CurrentUser.UserId,
Timestamp = DateTime.Now,
Comments = string.Format("# Device Deleted\r\n\r\nSerial Number: **{0}**\r\nComputer Name: **{1}**\r\nModel: **{2}**\r\nProfile: **{3}**",
d.SerialNumber, d.DeviceDomainId, d.DeviceModel, d.DeviceProfile)
Comments = $"# Device Deleted\r\n\r\nSerial Number: **{d.SerialNumber}**\r\nComputer Name: **{d.DeviceDomainId}**\r\nModel: **{d.DeviceModel}**\r\nProfile: **{d.DeviceProfile}**"
};
Database.JobLogs.Add(jobLog);
}
@@ -55,7 +55,7 @@ namespace Disco.Services
var deviceModelImagesDataStore = DataStore.CreateLocation(configCache, "DeviceModelImages");
return Path.Combine(deviceModelImagesDataStore, string.Format("{0}.png", deviceModel.Id));
return Path.Combine(deviceModelImagesDataStore, $"{deviceModel.Id}.png");
}
public static string ImageHash(this DeviceModel deviceModel)
+3 -3
View File
@@ -32,14 +32,14 @@ namespace Disco.Services
}
catch (Exception ex)
{
throw new InvalidOperationException(string.Format("An error occurred rendering the computer name: [{0}] {1}", ex.GetType().Name, ex.Message), ex.InnerException);
throw new InvalidOperationException($"An error occurred rendering the computer name: [{ex.GetType().Name}] {ex.Message}", ex.InnerException);
}
if (rendered == null || rendered.Length > 24)
{
throw new InvalidOperationException("The rendered computer name would be invalid or longer than 24 characters");
}
return string.Format(@"{0}\{1}", Domain.NetBiosName, rendered);
return $@"{Domain.NetBiosName}\{rendered}";
}
public static List<DocumentTemplate> AvailableDocumentTemplates(this Device d, DiscoDataContext Database, User User, DateTime TimeStamp)
{
@@ -250,7 +250,7 @@ namespace Disco.Services
public static string Status(this Device Device)
{
if (Device.DecommissionedDate.HasValue)
return string.Format("Decommissioned ({0})", Device.DecommissionReason.ReasonMessage());
return $"Decommissioned ({Device.DecommissionReason.ReasonMessage()})";
if (!Device.EnrolledDate.HasValue)
return "Not Enrolled";
@@ -32,7 +32,7 @@ namespace Disco.Services.Devices.DeviceFlags
if (flag == null)
throw new Exception("Invalid Device Flag Id");
Status.UpdateStatus(0, string.Format("Bulk Assigning Devices to Device Flag: {0}", flag.Name), "Preparing to start");
Status.UpdateStatus(0, $"Bulk Assigning Devices to Device Flag: {flag.Name}", "Preparing to start");
// Load Technician
var technician = Database.Users.FirstOrDefault(user => user.UserId == technicianUserId);
@@ -48,7 +48,7 @@ namespace Disco.Services.Devices.DeviceFlags
var missingDevices = deviceSerialNumbers.Where(sn => !devices.Any(u => string.Equals(sn, u.SerialNumber, StringComparison.OrdinalIgnoreCase))).ToList();
if (missingDevices.Count > 0)
{
throw new InvalidOperationException(string.Format("Bulk assignment aborted, invalid Serial Numbers: {0}", string.Join(", ", missingDevices)));
throw new InvalidOperationException($"Bulk assignment aborted, invalid Serial Numbers: {string.Join(", ", missingDevices)}");
}
devices = devices.OrderBy(d => d.SerialNumber).ToList();
@@ -81,14 +81,14 @@ namespace Disco.Services.Devices.Enrolment
};
var results = logRetriever.Query(database);
Status.UpdateStatus(50, string.Format("Passing {0} logs", results.Count));
Status.UpdateStatus(50, $"Passing {results.Count} logs");
Dictionary<string, Tuple<string, string>> addresses = new Dictionary<string, Tuple<string, string>>();
foreach (var result in results.OrderBy(r => r.Timestamp))
addresses[((string)result.Arguments[1]).ToLower()] = new Tuple<string, string>((string)result.Arguments[4], (string)result.Arguments[5]);
Status.UpdateStatus(75, string.Format("Importing {0} details", addresses.Count));
Status.UpdateStatus(75, $"Importing {addresses.Count} details");
var devices = database.Devices.Include("DeviceDetails").ToList();
@@ -118,7 +118,7 @@ namespace Disco.Services.Devices.Importing
{
string deviceSerialNumber = DeviceSerialNumberImportField.ParseRawDeviceSerialNumber(dataReader.GetString(deviceSerialNumberIndex));
Status.UpdateStatus(((double)dataReader.Index / Context.RecordCount) * 100, string.Format("Parsing: {0}", deviceSerialNumber));
Status.UpdateStatus(((double)dataReader.Index / Context.RecordCount) * 100, $"Parsing: {deviceSerialNumber}");
Device existingDevice = null;
if (DeviceSerialNumberImportField.IsDeviceSerialNumberValid(deviceSerialNumber))