qol: inline variable declaration

This commit is contained in:
Gary Sharp
2025-07-20 15:12:33 +10:00
parent 5792771ea1
commit 1add4ee0f5
89 changed files with 1229 additions and 1512 deletions
@@ -88,8 +88,7 @@ namespace Disco.Services
{
foreach (var certificateProviderId in dp.CertificateProviders.Split(','))
{
PluginFeatureManifest featureManifest = null;
if (Plugins.Plugins.TryGetPluginFeature(certificateProviderId.Trim(), typeof(CertificateProviderFeature), out featureManifest))
if (Plugins.Plugins.TryGetPluginFeature(certificateProviderId.Trim(), typeof(CertificateProviderFeature), out var featureManifest))
{
yield return featureManifest;
}
@@ -103,8 +102,7 @@ namespace Disco.Services
{
foreach (var certificateAuthorityProviderId in dp.CertificateAuthorityProviders.Split(','))
{
PluginFeatureManifest featureManifest = null;
if (Plugins.Plugins.TryGetPluginFeature(certificateAuthorityProviderId.Trim(), typeof(CertificateAuthorityProviderFeature), out featureManifest))
if (Plugins.Plugins.TryGetPluginFeature(certificateAuthorityProviderId.Trim(), typeof(CertificateAuthorityProviderFeature), out var featureManifest))
{
yield return featureManifest;
}
@@ -118,8 +116,7 @@ namespace Disco.Services
{
foreach (var wirelessProfileProviderId in dp.WirelessProfileProviders.Split(','))
{
PluginFeatureManifest featureManifest = null;
if (Plugins.Plugins.TryGetPluginFeature(wirelessProfileProviderId.Trim(), typeof(WirelessProfileProviderFeature), out featureManifest))
if (Plugins.Plugins.TryGetPluginFeature(wirelessProfileProviderId.Trim(), typeof(WirelessProfileProviderFeature), out var featureManifest))
{
yield return featureManifest;
}
@@ -92,10 +92,9 @@ namespace Disco.Services.Devices.Enrolment
var devices = database.Devices.Include("DeviceDetails").ToList();
Tuple<string, string> addressResult;
foreach (var device in devices)
{
if (addresses.TryGetValue(device.SerialNumber.ToLower(), out addressResult))
if (addresses.TryGetValue(device.SerialNumber.ToLower(), out var addressResult))
{
if (!string.IsNullOrEmpty(addressResult.Item1))
device.DeviceDetails.LanMacAddress(device, addressResult.Item1);
@@ -73,9 +73,8 @@ namespace Disco.Services.Devices.Enrolment
foreach (var node in profilerData.OfType<DictionaryNode>())
{
var nodeItems = ((ArrayNode)node["_items"]);
PNode nodeDataType;
if (node.TryGetValue("_dataType", out nodeDataType) && nodeDataType is StringNode)
if (node.TryGetValue("_dataType", out var nodeDataType) && nodeDataType is StringNode)
{
switch (((StringNode)nodeDataType).Value)
{
@@ -374,11 +374,10 @@ namespace Disco.Services.Devices.Enrolment
else
device.DeviceDomainId = $@"{domain.NetBiosName}\{Request.ComputerName}";
string offlineProvisionDiagnosicInfo;
EnrolmentLog.LogSessionTaskProvisioningADAccount(sessionId, device.SerialNumber, device.DeviceDomainId);
adMachineAccount = domainController.Value.RetrieveADMachineAccount(device.DeviceDomainId);
response.OfflineDomainJoinManifest = domainController.Value.OfflineDomainJoinProvision(device.DeviceDomainId, device.DeviceProfile.OrganisationalUnit, ref adMachineAccount, out offlineProvisionDiagnosicInfo);
response.OfflineDomainJoinManifest = domainController.Value.OfflineDomainJoinProvision(device.DeviceDomainId, device.DeviceProfile.OrganisationalUnit, ref adMachineAccount, out var offlineProvisionDiagnosicInfo);
EnrolmentLog.LogSessionDiagnosticInformation(sessionId, offlineProvisionDiagnosicInfo);
@@ -415,8 +414,7 @@ namespace Disco.Services.Devices.Enrolment
domain = ActiveDirectory.Context.GetDomainFromDistinguishedName(device.DeviceProfile.OrganisationalUnit);
var calculatedComputerName = device.ComputerNameRender(Database, domain);
string calculatedAccountUsername;
ActiveDirectory.ParseDomainAccountId(calculatedComputerName, out calculatedAccountUsername);
ActiveDirectory.ParseDomainAccountId(calculatedComputerName, out string calculatedAccountUsername);
if (!Request.ComputerName.Equals(calculatedAccountUsername, StringComparison.OrdinalIgnoreCase))
{
@@ -428,9 +426,8 @@ namespace Disco.Services.Devices.Enrolment
response.ComputerName = calculatedAccountUsername;
// Create New Account
string offlineProvisionDiagnosicInfo;
response.OfflineDomainJoinManifest = domainController.Value.OfflineDomainJoinProvision(device.DeviceDomainId, device.DeviceProfile.OrganisationalUnit, ref adMachineAccount, out offlineProvisionDiagnosicInfo);
response.OfflineDomainJoinManifest = domainController.Value.OfflineDomainJoinProvision(device.DeviceDomainId, device.DeviceProfile.OrganisationalUnit, ref adMachineAccount, out var offlineProvisionDiagnosicInfo);
EnrolmentLog.LogSessionDiagnosticInformation(sessionId, offlineProvisionDiagnosicInfo);
@@ -510,8 +507,7 @@ namespace Disco.Services.Devices.Enrolment
{
EnrolmentLog.LogSessionProgress(sessionId, 90, "Provisioning Certificates");
List<DeviceCertificate> provisionedCertificates;
var provisionResult = device.ProvisionCertificates(Database, Request, out provisionedCertificates);
var provisionResult = device.ProvisionCertificates(Database, Request, out var provisionedCertificates);
if (provisionedCertificates != null && provisionedCertificates.Count > 0)
{
@@ -113,8 +113,7 @@ namespace Disco.Services.Devices.Importing
if (columnsByType == null)
throw new ArgumentNullException(nameof(columnsByType));
DeviceImportColumn column;
if (columnsByType.TryGetValue(FieldType, out column))
if (columnsByType.TryGetValue(FieldType, out var column))
{
return column.Index;
}
@@ -102,8 +102,7 @@ namespace Disco.Services.Devices.Importing
return rawData.Select(r => r[ColumnIndex])
.All(c =>
{
int? value;
return TryGetNullableInt(c, out value);
return TryGetNullableInt(c, out var value);
});
}
@@ -112,8 +111,7 @@ namespace Disco.Services.Devices.Importing
return rawData.Select(r => r[ColumnIndex])
.All(c =>
{
int? value;
return TryGetNullableInt(c, out value) && value.HasValue;
return TryGetNullableInt(c, out var value) && value.HasValue;
});
}
@@ -122,8 +120,7 @@ namespace Disco.Services.Devices.Importing
return rawData.Select(r => r[ColumnIndex])
.All(c =>
{
bool? value;
return TryGetNullableBool(c, out value);
return TryGetNullableBool(c, out var value);
});
}
@@ -132,8 +129,7 @@ namespace Disco.Services.Devices.Importing
return rawData.Select(r => r[ColumnIndex])
.All(c =>
{
DateTime? value;
return TryGetNullableDateTime(c, out value);
return TryGetNullableDateTime(c, out var value);
});
}
@@ -153,8 +149,7 @@ namespace Disco.Services.Devices.Importing
{
content = content.Trim();
DateTime valueDateTime;
if (DateTime.TryParse(content, CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal, out valueDateTime))
if (DateTime.TryParse(content, CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal, out var valueDateTime))
{
value = valueDateTime;
return true;
@@ -205,8 +200,7 @@ namespace Disco.Services.Devices.Importing
}
else
{
int intValue;
if (int.TryParse(content, out intValue))
if (int.TryParse(content, out var intValue))
{
value = intValue;
return true;
@@ -40,8 +40,7 @@ namespace Disco.Services.Devices.Importing.Fields
parsedValue = new DateTime((parsedValue.Value.Ticks / 10000000L) * 10000000L);
}
string errorMessage;
if (parsedValue.HasValue && !CanDecommissionDevice(ExistingDevice, Context, DataReader, out errorMessage))
if (parsedValue.HasValue && !CanDecommissionDevice(ExistingDevice, Context, DataReader, out var errorMessage))
return Error(errorMessage);
var decommissionReasonIndex = Context.GetColumnByType(DeviceImportFieldTypes.DeviceDecommissionedReason);
@@ -55,8 +55,7 @@ namespace Disco.Services.Devices.Importing.Fields
}
else
{
DecommissionReasons valueReason;
if (!decommissionReasonsMap.Value.TryGetValue(value.Trim(), out valueReason))
if (!decommissionReasonsMap.Value.TryGetValue(value.Trim(), out var valueReason))
{
rawValue = value.Trim();
return Error("Cannot parse the value as a Decommission Reason");
@@ -24,8 +24,7 @@ namespace Disco.Services.Devices.Importing.Fields
public override bool Parse(DiscoDataContext Database, IDeviceImportCache Cache, IDeviceImportContext Context, string DeviceSerialNumber, Device ExistingDevice, List<IDeviceImportRecord> PreviousRecords, IDeviceImportDataReader DataReader, int ColumnIndex)
{
int? intValue;
if (DataReader.TryGetNullableInt(ColumnIndex, out intValue))
if (DataReader.TryGetNullableInt(ColumnIndex, out var intValue))
{
if (!intValue.HasValue)
{
@@ -24,8 +24,7 @@ namespace Disco.Services.Devices.Importing.Fields
public override bool Parse(DiscoDataContext Database, IDeviceImportCache Cache, IDeviceImportContext Context, string DeviceSerialNumber, Device ExistingDevice, List<IDeviceImportRecord> PreviousRecords, IDeviceImportDataReader DataReader, int ColumnIndex)
{
int? intValue;
if (DataReader.TryGetNullableInt(ColumnIndex, out intValue))
if (DataReader.TryGetNullableInt(ColumnIndex, out var intValue))
{
if (!intValue.HasValue)
{
@@ -102,8 +102,7 @@ namespace Disco.Services.Devices.Importing
return rawData.Select(r => r[ColumnIndex])
.All(c =>
{
int? value;
return TryGetNullableInt(c, out value);
return TryGetNullableInt(c, out var value);
});
}
@@ -112,8 +111,7 @@ namespace Disco.Services.Devices.Importing
return rawData.Select(r => r[ColumnIndex])
.All(c =>
{
int? value;
return TryGetNullableInt(c, out value) && value.HasValue;
return TryGetNullableInt(c, out var value) && value.HasValue;
});
}
@@ -122,8 +120,7 @@ namespace Disco.Services.Devices.Importing
return rawData.Select(r => r[ColumnIndex])
.All(c =>
{
bool? value;
return TryGetNullableBool(c, out value);
return TryGetNullableBool(c, out var value);
});
}
@@ -132,8 +129,7 @@ namespace Disco.Services.Devices.Importing
return rawData.Select(r => r[ColumnIndex])
.All(c =>
{
DateTime? value;
return TryGetNullableDateTime(c, out value);
return TryGetNullableDateTime(c, out var value);
});
}
@@ -167,8 +163,7 @@ namespace Disco.Services.Devices.Importing
{
stringValue = stringValue.Trim();
DateTime valueDateTime;
if (DateTime.TryParse(stringValue, CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal, out valueDateTime))
if (DateTime.TryParse(stringValue, CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal, out var valueDateTime))
{
value = valueDateTime;
return true;
@@ -247,8 +242,7 @@ namespace Disco.Services.Devices.Importing
}
else
{
int intValue;
if (int.TryParse(stringValue, out intValue))
if (int.TryParse(stringValue, out var intValue))
{
value = intValue;
return true;
@@ -76,10 +76,9 @@ namespace Disco.Services.Devices.ManagedGroups
public static bool TryGetManagedGroup(DeviceBatch DeviceBatch, out DeviceBatchAssignedUsersManagedGroup ManagedGroup)
{
ADManagedGroup managedGroup;
string key = GetKey(DeviceBatch);
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out managedGroup))
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out var managedGroup))
{
ManagedGroup = (DeviceBatchAssignedUsersManagedGroup)managedGroup;
return true;
@@ -74,10 +74,9 @@ namespace Disco.Services.Devices.ManagedGroups
public static bool TryGetManagedGroup(DeviceBatch DeviceBatch, out DeviceBatchDevicesManagedGroup ManagedGroup)
{
ADManagedGroup managedGroup;
string key = GetKey(DeviceBatch);
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out managedGroup))
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out var managedGroup))
{
ManagedGroup = (DeviceBatchDevicesManagedGroup)managedGroup;
return true;
@@ -76,10 +76,9 @@ namespace Disco.Services.Devices.ManagedGroups
public static bool TryGetManagedGroup(DeviceProfile DeviceProfile, out DeviceProfileAssignedUsersManagedGroup ManagedGroup)
{
ADManagedGroup managedGroup;
string key = GetKey(DeviceProfile);
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out managedGroup))
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out var managedGroup))
{
ManagedGroup = (DeviceProfileAssignedUsersManagedGroup)managedGroup;
return true;
@@ -75,10 +75,9 @@ namespace Disco.Services.Devices.ManagedGroups
public static bool TryGetManagedGroup(DeviceProfile DeviceProfile, out DeviceProfileDevicesManagedGroup ManagedGroup)
{
ADManagedGroup managedGroup;
string key = GetKey(DeviceProfile);
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out managedGroup))
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out var managedGroup))
{
ManagedGroup = (DeviceProfileDevicesManagedGroup)managedGroup;
return true;