Update InformMiddleware function

This commit is contained in:
atef 2023-11-27 15:19:28 +01:00
parent e143a4be6e
commit 9840e0c9f8
1 changed files with 11 additions and 13 deletions

View File

@ -261,6 +261,7 @@ internal static class Program
private static void SendSalimaxStateAlarm(StatusMessage currentSalimaxState) private static void SendSalimaxStateAlarm(StatusMessage currentSalimaxState)
{ {
var s3Bucket = Config.Load().S3?.Bucket; var s3Bucket = Config.Load().S3?.Bucket;
_heartBitInterval++; _heartBitInterval++;
//When the controller boots, it tries to subscribe to the queue //When the controller boots, it tries to subscribe to the queue
@ -279,7 +280,7 @@ internal static class Program
{ {
_prevSalimaxState = currentSalimaxState.Status; _prevSalimaxState = currentSalimaxState.Status;
if (s3Bucket != null) if (s3Bucket != null)
InformMiddleware(s3Bucket, currentSalimaxState); InformMiddleware(currentSalimaxState);
} }
else if (_subscribedToQueue && _heartBitInterval>=15) else if (_subscribedToQueue && _heartBitInterval>=15)
{ {
@ -288,7 +289,7 @@ internal static class Program
currentSalimaxState.Type = MessageType.Heartbit; currentSalimaxState.Type = MessageType.Heartbit;
if (s3Bucket != null) if (s3Bucket != null)
InformMiddleware(s3Bucket, currentSalimaxState); InformMiddleware(currentSalimaxState);
} }
//If there is an available message from the RabbitMQ Broker, subscribe to the queue //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"); 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; _subscribedToQueue = true;
} }
@ -356,11 +357,8 @@ internal static class Program
return IPAddress.None; return IPAddress.None;
} }
private static void InformMiddleware(String? bucket, StatusMessage status) private static void InformMiddleware(StatusMessage status)
{ {
//dddddddddff
int.TryParse(bucket[0].ToString(), out var installationId);
var message = JsonSerializer.Serialize(status); var message = JsonSerializer.Serialize(status);
var body = Encoding.UTF8.GetBytes(message); var body = Encoding.UTF8.GetBytes(message);
@ -480,7 +478,7 @@ internal static class Program
? SalimaxAlarmState.Red ? SalimaxAlarmState.Red
: salimaxAlarmsState; // this will be replaced by LedState : 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 var returnedStatus = new StatusMessage
{ {