diff --git a/application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/RetrieveMeshFile.cs b/application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/RetrieveMeshFile.cs index 13ec26ba9..d79fed0e8 100644 --- a/application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/RetrieveMeshFile.cs +++ b/application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/RetrieveMeshFile.cs @@ -2,6 +2,7 @@ namespace NHS.Screening.RetrieveMeshFile; using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Text; using System.Text.Json; using System.Threading.Tasks; @@ -30,7 +31,7 @@ public RetrieveMeshFile(ILogger logger, IMeshToBlobTransferHan _meshToBlobTransferHandler = meshToBlobTransferHandler; _blobStorageHelper = blobStorageHelper; _mailboxId = options.Value.BSSMailBox; - _blobConnectionString = Environment.GetEnvironmentVariable("caasfolder_STORAGE"); + _blobConnectionString = Environment.GetEnvironmentVariable("caasfolder_STORAGE"); } /// /// This function polls the MESH Mailbox every 5 minutes, if there is a file posted to the mailbox. @@ -39,40 +40,40 @@ public RetrieveMeshFile(ILogger logger, IMeshToBlobTransferHan [Function("RetrieveMeshFile")] public async Task RunAsync([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer) { - _logger.LogInformation("C# Timer trigger function executed at: ,{datetime}",DateTime.Now); + _logger.LogInformation("C# Timer trigger function executed at: ,{datetime}", DateTime.Now); static bool messageFilter(MessageMetaData i) => true; // No current filter defined there might be business rules here - static string fileNameFunction(MessageMetaData i) => string.Concat(i.MessageId, "_-_", i.WorkflowID,".parquet"); + static string fileNameFunction(MessageMetaData i) => string.Concat(i.MessageId, "_-_", i.WorkflowID, ".parquet"); try { var shouldExecuteHandShake = await ShouldExecuteHandShake(); - var result = await _meshToBlobTransferHandler.MoveFilesFromMeshToBlob(messageFilter, fileNameFunction, _mailboxId,_blobConnectionString,"inbound",shouldExecuteHandShake); + var result = await _meshToBlobTransferHandler.MoveFilesFromMeshToBlob(messageFilter, fileNameFunction, _mailboxId, _blobConnectionString, "inbound", shouldExecuteHandShake); - if(!result) + if (!result) { _logger.LogError("An error was encountered while moving files from Mesh to Blob"); } } - catch(Exception ex) + catch (Exception ex) { - _logger.LogError(ex,"An error encountered while moving files from Mesh to Blob"); + _logger.LogError(ex, "An error encountered while moving files from Mesh to Blob"); } if (myTimer.ScheduleStatus is not null) { - _logger.LogInformation("Next timer schedule at: {scheduleStatus}",myTimer.ScheduleStatus.Next); + _logger.LogInformation("Next timer schedule at: {scheduleStatus}", myTimer.ScheduleStatus.Next); } } private async Task ShouldExecuteHandShake() { - Dictionary configValues; + Dictionary configValues; TimeSpan handShakeInterval = new TimeSpan(0, 23, 54, 0); - var meshState = await _blobStorageHelper.GetFileFromBlobStorage(_blobConnectionString,"config",ConfigFileName); - if(meshState == null) + var meshState = await _blobStorageHelper.GetFileFromBlobStorage(_blobConnectionString, "config", ConfigFileName); + if (meshState == null) { _logger.LogInformation("MeshState File did not exist, Creating new MeshState File in blob Storage"); @@ -85,15 +86,16 @@ private async Task ShouldExecuteHandShake() return true; } - using(StreamReader reader = new StreamReader(meshState.Data)){ - meshState.Data.Seek(0,SeekOrigin.Begin); + using (StreamReader reader = new StreamReader(meshState.Data)) + { + meshState.Data.Seek(0, SeekOrigin.Begin); string jsonData = await reader.ReadToEndAsync(); - configValues = JsonSerializer.Deserialize>(jsonData); + configValues = JsonSerializer.Deserialize>(jsonData); } string nextHandShakeDateString; //config value doenst exist - if(!configValues.TryGetValue(NextHandShakeTimeConfigKey, out nextHandShakeDateString)) + if (!configValues.TryGetValue(NextHandShakeTimeConfigKey, out nextHandShakeDateString)) { _logger.LogInformation("NextHandShakeTime config item does not exist, creating new config item"); configValues.Add(NextHandShakeTimeConfigKey, DateTime.UtcNow.Add(handShakeInterval).ToString()); @@ -104,7 +106,7 @@ private async Task ShouldExecuteHandShake() } DateTime nextHandShakeDateTime; //date cannot be parsed - if(!DateTime.TryParse(nextHandShakeDateString, out nextHandShakeDateTime)) + if (!DateTime.TryParse(nextHandShakeDateString, CultureInfo.InvariantCulture, out nextHandShakeDateTime)) { _logger.LogInformation("Unable to Parse NextHandShakeTime, Updating config value"); configValues[NextHandShakeTimeConfigKey] = DateTime.UtcNow.Add(handShakeInterval).ToString(); @@ -112,7 +114,8 @@ private async Task ShouldExecuteHandShake() return true; } - if(DateTime.Compare(nextHandShakeDateTime,DateTime.UtcNow) <= 0){ + if (DateTime.Compare(nextHandShakeDateTime, DateTime.UtcNow) <= 0) + { _logger.LogInformation("Next HandShakeTime was in the past, will execute handshake"); var NextHandShakeTimeConfig = DateTime.UtcNow.Add(handShakeInterval).ToString(); @@ -127,20 +130,21 @@ private async Task ShouldExecuteHandShake() } - private async Task SetConfigState(Dictionary state) + private async Task SetConfigState(Dictionary state) { - try{ + try + { string jsonString = JsonSerializer.Serialize(state); - using(var stream = GenerateStreamFromString(jsonString)) + using (var stream = GenerateStreamFromString(jsonString)) { - var blobFile = new BlobFile(stream,ConfigFileName); - var result = await _blobStorageHelper.UploadFileToBlobStorage(_blobConnectionString,"config",blobFile,true); + var blobFile = new BlobFile(stream, ConfigFileName); + var result = await _blobStorageHelper.UploadFileToBlobStorage(_blobConnectionString, "config", blobFile, true); return result; } } - catch(Exception ex) + catch (Exception ex) { - _logger.LogError(ex,"Unable To set Config State"); + _logger.LogError(ex, "Unable To set Config State"); return false; } } diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/addParticipant/addParticipant.cs b/application/CohortManager/src/Functions/ParticipantManagementServices/addParticipant/addParticipant.cs index 86606ed25..0e5942be6 100644 --- a/application/CohortManager/src/Functions/ParticipantManagementServices/addParticipant/addParticipant.cs +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/addParticipant/addParticipant.cs @@ -109,7 +109,6 @@ public async Task Run([QueueTrigger("%AddQueueName%", Connection = "AzureWebJobs { _logger.LogInformation(ex, "Unable to call function.\nMessage: {Message}\nStack Trace: {StackTrace}", ex.Message, ex.StackTrace); await _handleException.CreateSystemExceptionLog(ex, basicParticipantCsvRecord.Participant, basicParticipantCsvRecord.FileName); - return; } } diff --git a/application/CohortManager/src/Functions/Shared/Common/AzureQueueStorageHelper.cs b/application/CohortManager/src/Functions/Shared/Common/AzureQueueStorageHelper.cs index 50560ec62..039aafb97 100644 --- a/application/CohortManager/src/Functions/Shared/Common/AzureQueueStorageHelper.cs +++ b/application/CohortManager/src/Functions/Shared/Common/AzureQueueStorageHelper.cs @@ -9,7 +9,6 @@ namespace Common; public class AzureQueueStorageHelper : IAzureQueueStorageHelper { - private QueueClient _queueClient; private readonly string storageConnectionString; @@ -23,7 +22,7 @@ public AzureQueueStorageHelper(ILogger logger) public async Task AddItemToQueueAsync(T participantCsvRecord, string queueName) { - _queueClient = new QueueClient(storageConnectionString, queueName); + var _queueClient = new QueueClient(storageConnectionString, queueName); await _queueClient.CreateIfNotExistsAsync(); var json = JsonSerializer.Serialize(participantCsvRecord); var bytes = Encoding.UTF8.GetBytes(json); diff --git a/application/CohortManager/src/Functions/Shared/Common/EnumHelper.cs b/application/CohortManager/src/Functions/Shared/Common/EnumHelper.cs index 0051ff01d..9d3956afb 100644 --- a/application/CohortManager/src/Functions/Shared/Common/EnumHelper.cs +++ b/application/CohortManager/src/Functions/Shared/Common/EnumHelper.cs @@ -12,8 +12,7 @@ public static class EnumHelper public static string GetDisplayName(Enum enumValue) { var displayName = enumValue.GetType() - .GetMember(enumValue.ToString()) - .First() + .GetMember(enumValue.ToString())[0] .GetCustomAttribute()? .GetName();