qol: inline variable declaration
This commit is contained in:
@@ -298,8 +298,7 @@ namespace Disco.Services.Documents.AttachmentImport
|
||||
|
||||
if (qrCodeResult != null && qrCodeResult.ResultPoints.Length == 4)
|
||||
{
|
||||
float thumbnailScale;
|
||||
var thumbnailOffset = renderedImage.CalculateResize(renderedThumbnail.Width, renderedThumbnail.Height, out thumbnailScale);
|
||||
var thumbnailOffset = renderedImage.CalculateResize(renderedThumbnail.Width, renderedThumbnail.Height, out var thumbnailScale);
|
||||
thumbnailScale = thumbnailScale / qrCodeResultScale;
|
||||
|
||||
using (Graphics thumbnailGraphics = Graphics.FromImage(renderedThumbnail))
|
||||
|
||||
@@ -29,11 +29,10 @@ namespace Disco.Services
|
||||
try
|
||||
{
|
||||
var er = compiledExpression.EvaluateFirst<object>(Data, evaluatorVariables);
|
||||
if (er is bool)
|
||||
if (er is bool erBool)
|
||||
{
|
||||
return (bool)er;
|
||||
return erBool;
|
||||
}
|
||||
bool erBool;
|
||||
if (bool.TryParse(er.ToString(), out erBool))
|
||||
{
|
||||
return erBool;
|
||||
|
||||
@@ -91,11 +91,10 @@ namespace Disco.Services
|
||||
try
|
||||
{
|
||||
object er = compiledExpression.EvaluateFirst<object>(Data, evaluatorVariables);
|
||||
if (er is bool)
|
||||
if (er is bool erBool)
|
||||
{
|
||||
return (bool)er;
|
||||
return erBool;
|
||||
}
|
||||
bool erBool;
|
||||
if (bool.TryParse(er.ToString(), out erBool))
|
||||
{
|
||||
return erBool;
|
||||
|
||||
@@ -35,8 +35,7 @@ namespace Disco.Services.Documents
|
||||
|
||||
public static DocumentTemplatePackage GetPackage(string Id)
|
||||
{
|
||||
DocumentTemplatePackage package;
|
||||
if (cache.TryGetValue(Id, out package))
|
||||
if (cache.TryGetValue(Id, out var package))
|
||||
return package;
|
||||
else
|
||||
return null;
|
||||
@@ -142,11 +141,10 @@ namespace Disco.Services.Documents
|
||||
|
||||
public static DocumentTemplatePackage UpdatePackage(DocumentTemplatePackage Package)
|
||||
{
|
||||
DocumentTemplatePackage existingPackage;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Package.Id))
|
||||
throw new ArgumentNullException(nameof(Package), "The Package Id is required");
|
||||
if (!cache.TryGetValue(Package.Id, out existingPackage)) // Name Unique
|
||||
if (!cache.TryGetValue(Package.Id, out var existingPackage)) // Name Unique
|
||||
throw new ArgumentException("The Package Id does not exist", nameof(Package));
|
||||
if (string.IsNullOrWhiteSpace(Package.Description))
|
||||
throw new ArgumentNullException(nameof(Package), "The Package Description is required");
|
||||
@@ -162,8 +160,7 @@ namespace Disco.Services.Documents
|
||||
|
||||
public static void RemovePackage(string Id)
|
||||
{
|
||||
DocumentTemplatePackage existingPackage;
|
||||
if (cache.TryRemove(Id, out existingPackage))
|
||||
if (cache.TryRemove(Id, out _))
|
||||
{
|
||||
PersistCache();
|
||||
}
|
||||
|
||||
@@ -312,28 +312,17 @@ namespace Disco.Services.Documents
|
||||
|
||||
public static DocumentUniqueIdentifier Parse(DiscoDataContext Database, byte[] UniqueIdentifier)
|
||||
{
|
||||
DocumentUniqueIdentifier identifier;
|
||||
if (TryParse(Database, UniqueIdentifier, out identifier))
|
||||
{
|
||||
if (TryParse(Database, UniqueIdentifier, out var identifier))
|
||||
return identifier;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FormatException("Invalid Document Unique Identifier");
|
||||
}
|
||||
throw new FormatException("Invalid Document Unique Identifier");
|
||||
}
|
||||
|
||||
public static DocumentUniqueIdentifier Parse(DiscoDataContext Database, string UniqueIdentifier)
|
||||
{
|
||||
DocumentUniqueIdentifier identifier;
|
||||
if (TryParse(Database, UniqueIdentifier, out identifier))
|
||||
{
|
||||
if (TryParse(Database, UniqueIdentifier, out var identifier))
|
||||
return identifier;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FormatException("Invalid Document Unique Identifier");
|
||||
}
|
||||
throw new FormatException("Invalid Document Unique Identifier");
|
||||
|
||||
}
|
||||
|
||||
public static bool TryParse(DiscoDataContext Database, string UniqueIdentifier, out DocumentUniqueIdentifier Identifier)
|
||||
@@ -417,7 +406,7 @@ namespace Disco.Services.Documents
|
||||
// Has document template id flag
|
||||
if ((flags & 0x8) == 0x8)
|
||||
{
|
||||
documentTemplateId = DocumentUniqueIdentifierExtensions.BinaryDecode(Data, position, out position);
|
||||
documentTemplateId = DocumentUniqueIdentifierExtensions.BinaryDecode(Data, position, out _);
|
||||
}
|
||||
|
||||
AttachmentTypes? attachmentType = null;
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace Disco.Services
|
||||
if (Data == null)
|
||||
throw new ArgumentNullException(nameof(Data));
|
||||
|
||||
byte[] result;
|
||||
|
||||
if (Data.Length == 0)
|
||||
{
|
||||
@@ -33,7 +32,7 @@ namespace Disco.Services
|
||||
}
|
||||
|
||||
// Try Numeric Encode
|
||||
if (TryBinaryNumericEncode(Data, out result))
|
||||
if (TryBinaryNumericEncode(Data, out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
@@ -88,8 +87,7 @@ namespace Disco.Services
|
||||
// Z = number of leading zeros
|
||||
// Y = number component < 0x0FFFFFFF (268,435,455)
|
||||
|
||||
uint number;
|
||||
if (uint.TryParse(Data, out number) && number <= 0x0FFFFFFF)
|
||||
if (uint.TryParse(Data, out var number) && number <= 0x0FFFFFFF)
|
||||
{
|
||||
Result = new byte[4];
|
||||
int leadingZeros = 0;
|
||||
@@ -250,12 +248,10 @@ namespace Disco.Services
|
||||
// A,B,C = character component in
|
||||
// alpha encoded format
|
||||
|
||||
short number;
|
||||
byte[] chars;
|
||||
if (Data.Length == 7 &&
|
||||
short.TryParse(Data.Substring(3), out number) &&
|
||||
short.TryParse(Data.Substring(3), out var number) &&
|
||||
number <= 9999 &&
|
||||
TryBinaryAlphaEncode(Data.Substring(0, 3), out chars))
|
||||
TryBinaryAlphaEncode(Data.Substring(0, 3), out var chars))
|
||||
{
|
||||
Result = new byte[4];
|
||||
Result[0] = (byte)(0x80 | (number >> 8));
|
||||
|
||||
@@ -109,10 +109,9 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
|
||||
public static bool TryGetManagedGroup(DocumentTemplate DocumentTemplate, out DocumentTemplateDevicesManagedGroup ManagedGroup)
|
||||
{
|
||||
ADManagedGroup managedGroup;
|
||||
string key = GetKey(DocumentTemplate);
|
||||
|
||||
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out managedGroup))
|
||||
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out var managedGroup))
|
||||
{
|
||||
ManagedGroup = (DocumentTemplateDevicesManagedGroup)managedGroup;
|
||||
return true;
|
||||
@@ -230,8 +229,7 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
{
|
||||
var attachment = (DeviceAttachment)e.Entity;
|
||||
|
||||
string deviceAccountId;
|
||||
if (DeviceContainsAttachment(e.Database, attachment.DeviceSerialNumber, out deviceAccountId))
|
||||
if (DeviceContainsAttachment(e.Database, attachment.DeviceSerialNumber, out var deviceAccountId))
|
||||
AddMember(attachment.DeviceSerialNumber, (database) => new string[] { deviceAccountId });
|
||||
}
|
||||
private void ProcessDeviceAttachmentRemoveEvent(Tuple<DiscoDataContext, int, string, string> e)
|
||||
@@ -240,8 +238,7 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
|
||||
RemoveMember(deviceSerialNumber, (database) =>
|
||||
{
|
||||
string deviceAccountId;
|
||||
if (!DeviceContainsAttachment(database, deviceSerialNumber, out deviceAccountId) && deviceAccountId != null)
|
||||
if (!DeviceContainsAttachment(database, deviceSerialNumber, out var deviceAccountId) && deviceAccountId != null)
|
||||
return new string[] { deviceAccountId };
|
||||
else
|
||||
return null;
|
||||
@@ -279,9 +276,7 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
{
|
||||
var attachment = (JobAttachment)e.Entity;
|
||||
|
||||
string deviceAccountId;
|
||||
string deviceSerialNumber;
|
||||
if (JobsContainAttachment(e.Database, attachment.JobId, out deviceAccountId, out deviceSerialNumber))
|
||||
if (JobsContainAttachment(e.Database, attachment.JobId, out var deviceAccountId, out var deviceSerialNumber))
|
||||
AddMember(deviceSerialNumber, (database) => new string[] { deviceAccountId });
|
||||
}
|
||||
private void ProcessJobAttachmentRemoveEvent(Tuple<DiscoDataContext, int, string, int> e)
|
||||
@@ -293,8 +288,7 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
{
|
||||
RemoveMember(deviceSerialNumber, (database) =>
|
||||
{
|
||||
string deviceAccountId;
|
||||
if (!JobsContainAttachment(database, jobId, out deviceAccountId, out deviceSerialNumber) &&
|
||||
if (!JobsContainAttachment(database, jobId, out var deviceAccountId, out deviceSerialNumber) &&
|
||||
deviceSerialNumber != null && deviceAccountId != null)
|
||||
return new string[] { deviceAccountId };
|
||||
else
|
||||
@@ -335,8 +329,7 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
{
|
||||
var attachment = (UserAttachment)e.Entity;
|
||||
|
||||
List<Tuple<string, string>> devices;
|
||||
if (DeviceUserContainAttachment(e.Database, attachment.UserId, out devices) && devices != null)
|
||||
if (DeviceUserContainAttachment(e.Database, attachment.UserId, out var devices) && devices != null)
|
||||
devices.ForEach(d => AddMember(d.Item2, (database) => new string[] { d.Item1 }));
|
||||
}
|
||||
private void ProcessUserAttachmentRemoveEvent(Tuple<DiscoDataContext, int, string, string> e)
|
||||
@@ -345,8 +338,7 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
|
||||
RemoveMember(userId, (database) =>
|
||||
{
|
||||
List<Tuple<string, string>> devices;
|
||||
if (!DeviceUserContainAttachment(database, userId, out devices) && devices != null)
|
||||
if (!DeviceUserContainAttachment(database, userId, out var devices) && devices != null)
|
||||
return devices.Select(d => d.Item1);
|
||||
else
|
||||
return null;
|
||||
|
||||
@@ -104,10 +104,9 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
|
||||
public static bool TryGetManagedGroup(DocumentTemplate DocumentTemplate, out DocumentTemplateUsersManagedGroup ManagedGroup)
|
||||
{
|
||||
ADManagedGroup managedGroup;
|
||||
string key = GetKey(DocumentTemplate);
|
||||
|
||||
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out managedGroup))
|
||||
if (ActiveDirectory.Context.ManagedGroups.TryGetValue(key, out var managedGroup))
|
||||
{
|
||||
ManagedGroup = (DocumentTemplateUsersManagedGroup)managedGroup;
|
||||
return true;
|
||||
@@ -217,8 +216,7 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
{
|
||||
var attachment = (DeviceAttachment)e.Entity;
|
||||
|
||||
string userId;
|
||||
if (DeviceContainsAttachment(e.Database, attachment.DeviceSerialNumber, out userId) && userId != null)
|
||||
if (DeviceContainsAttachment(e.Database, attachment.DeviceSerialNumber, out var userId) && userId != null)
|
||||
AddMember(userId, (database) => new string[] { userId });
|
||||
}
|
||||
private void ProcessDeviceAttachmentRemoveEvent(Tuple<DiscoDataContext, int, string, string> e)
|
||||
@@ -273,8 +271,7 @@ namespace Disco.Services.Documents.ManagedGroups
|
||||
{
|
||||
var attachment = (JobAttachment)e.Entity;
|
||||
|
||||
string userId;
|
||||
if (JobsContainAttachment(e.Database, attachment.JobId, out userId) && userId != null)
|
||||
if (JobsContainAttachment(e.Database, attachment.JobId, out var userId) && userId != null)
|
||||
AddMember(userId, (database) => new string[] { userId });
|
||||
}
|
||||
private void ProcessJobAttachmentRemoveEvent(Tuple<DiscoDataContext, int, string, int> e)
|
||||
|
||||
@@ -11,8 +11,6 @@ namespace Disco.Services.Documents
|
||||
public static byte[] Encode(string content, ErrorCorrectionLevel ecLevel, out int width, out int height)
|
||||
{
|
||||
var code = Encoder.encode(content, ecLevel, null);
|
||||
|
||||
var array = code.Matrix.Array;
|
||||
width = code.Matrix.Width;
|
||||
height = code.Matrix.Height;
|
||||
|
||||
@@ -140,11 +138,9 @@ namespace Disco.Services.Documents
|
||||
for (int i = 0; i < numRSBlocks; ++i)
|
||||
{
|
||||
|
||||
int numDataBytesInBlock;
|
||||
int numEcBytesInBlock;
|
||||
getNumDataBytesAndNumECBytesForBlockID(
|
||||
numTotalBytes, numDataBytes, numRSBlocks, i,
|
||||
out numDataBytesInBlock, out numEcBytesInBlock);
|
||||
out var numDataBytesInBlock, out var numEcBytesInBlock);
|
||||
|
||||
byte[] dataBytes = new byte[numDataBytesInBlock];
|
||||
bits.toBytes(8 * dataBytesOffset, dataBytes, 0, numDataBytesInBlock);
|
||||
|
||||
Reference in New Issue
Block a user