From 9840e0c9f8b28356032ba33015058e00e3d282f8 Mon Sep 17 00:00:00 2001 From: atef Date: Mon, 27 Nov 2023 15:19:28 +0100 Subject: [PATCH] Update InformMiddleware function --- csharp/App/SaliMax/src/Program.cs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 127556f9a..b9c6dbbeb 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -261,6 +261,7 @@ internal static class Program private static void SendSalimaxStateAlarm(StatusMessage currentSalimaxState) { var s3Bucket = Config.Load().S3?.Bucket; + _heartBitInterval++; //When the controller boots, it tries to subscribe to the queue @@ -279,7 +280,7 @@ internal static class Program { _prevSalimaxState = currentSalimaxState.Status; if (s3Bucket != null) - InformMiddleware(s3Bucket, currentSalimaxState); + InformMiddleware(currentSalimaxState); } else if (_subscribedToQueue && _heartBitInterval>=15) { @@ -288,7 +289,7 @@ internal static class Program currentSalimaxState.Type = MessageType.Heartbit; if (s3Bucket != null) - InformMiddleware(s3Bucket, currentSalimaxState); + InformMiddleware(currentSalimaxState); } //If there is an available message from the RabbitMQ Broker, subscribe to the queue @@ -324,7 +325,7 @@ internal static class Program Console.WriteLine("The controller sends its status to the middleware for the first time"); - if (s3Bucket != null) InformMiddleware(s3Bucket, currentSalimaxState); + if (s3Bucket != null) InformMiddleware(currentSalimaxState); _subscribedToQueue = true; } @@ -356,11 +357,8 @@ internal static class Program return IPAddress.None; } - private static void InformMiddleware(String? bucket, StatusMessage status) - { - //dddddddddff - int.TryParse(bucket[0].ToString(), out var installationId); - + private static void InformMiddleware(StatusMessage status) + { var message = JsonSerializer.Serialize(status); var body = Encoding.UTF8.GetBytes(message); @@ -480,15 +478,15 @@ internal static class Program ? SalimaxAlarmState.Red : salimaxAlarmsState; // this will be replaced by LedState - int.TryParse(s3Bucket[0].ToString(), out var installationId); + int.TryParse(s3Bucket?.Split("-")[0], out var installationId); var returnedStatus = new StatusMessage { InstallationId = installationId, - Status = salimaxAlarmsState, - Type= MessageType.AlarmOrWarning, - Alarms = alarmList, - Warnings = warningList + Status = salimaxAlarmsState, + Type = MessageType.AlarmOrWarning, + Alarms = alarmList, + Warnings = warningList }; return returnedStatus;