Added Hearbit functionality to SodioHome
This commit is contained in:
parent
bbb0d21759
commit
8ba880df05
|
|
@ -35,8 +35,8 @@ public static class Program
|
|||
private static Boolean _subscribedToQueue = false;
|
||||
private static Boolean _subscribeToQueueForTheFirstTime = false;
|
||||
private static Int32 _failsCounter = 0; // move to a config file
|
||||
private static SodistoreAlarmState _prevSodistoreAlarmState = SodistoreAlarmState.Green;
|
||||
private static SodistoreAlarmState _sodistoreAlarmState = SodistoreAlarmState.Green;
|
||||
private static SodistoreAlarmState _prevSodiohomeAlarmState = SodistoreAlarmState.Green;
|
||||
private static SodistoreAlarmState _sodiohomeAlarmState = SodistoreAlarmState.Green;
|
||||
|
||||
|
||||
// move all this to config file
|
||||
|
|
@ -210,13 +210,13 @@ public static class Program
|
|||
}
|
||||
}
|
||||
|
||||
_sodistoreAlarmState = warningList.Any()
|
||||
_sodiohomeAlarmState = warningList.Any()
|
||||
? SodistoreAlarmState.Orange
|
||||
: SodistoreAlarmState.Green; // this will be replaced by LedState
|
||||
|
||||
_sodistoreAlarmState = alarmList.Any()
|
||||
_sodiohomeAlarmState = alarmList.Any()
|
||||
? SodistoreAlarmState.Red
|
||||
: _sodistoreAlarmState; // this will be replaced by LedState
|
||||
: _sodiohomeAlarmState; // this will be replaced by LedState
|
||||
|
||||
var installationId = GetInstallationId(s3Bucket ?? string.Empty);
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ public static class Program
|
|||
{
|
||||
InstallationId = installationId,
|
||||
Product = 2,
|
||||
Status = _sodistoreAlarmState,
|
||||
Status = _sodiohomeAlarmState,
|
||||
Type = MessageType.AlarmOrWarning,
|
||||
Alarms = alarmList,
|
||||
Warnings = warningList
|
||||
|
|
@ -249,14 +249,14 @@ public static class Program
|
|||
{
|
||||
subscribedNow = true;
|
||||
_subscribeToQueueForTheFirstTime = true;
|
||||
_prevSodistoreAlarmState = currentSalimaxState.Status;
|
||||
_prevSodiohomeAlarmState = currentSalimaxState.Status;
|
||||
_subscribedToQueue = RabbitMqManager.SubscribeToQueue(currentSalimaxState, s3Bucket, VpnServerIp);
|
||||
}
|
||||
|
||||
//If already subscribed to the queue and the status has been changed, update the queue
|
||||
if (!subscribedNow && _subscribedToQueue && currentSalimaxState.Status != _prevSodistoreAlarmState)
|
||||
if (!subscribedNow && _subscribedToQueue && currentSalimaxState.Status != _prevSodiohomeAlarmState)
|
||||
{
|
||||
_prevSodistoreAlarmState = currentSalimaxState.Status;
|
||||
_prevSodiohomeAlarmState = currentSalimaxState.Status;
|
||||
if (s3Bucket != null)
|
||||
RabbitMqManager.InformMiddleware(currentSalimaxState);
|
||||
}
|
||||
|
|
@ -515,7 +515,7 @@ public static class Program
|
|||
Console.WriteLine(error);
|
||||
|
||||
await SaveToLocalCompressedFallback(compressedBytes, fileNameWithoutExtension);
|
||||
//Heartbit();
|
||||
Heartbit();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -523,7 +523,7 @@ public static class Program
|
|||
Console.WriteLine("✅ File uploaded to S3 successfully.");
|
||||
|
||||
Console.WriteLine("---------------------------------------- Resending FailedUploadedFiles----------------------------------------");
|
||||
// Heartbit();
|
||||
Heartbit();
|
||||
|
||||
await ResendLocalFailedFilesAsync(s3Config); // retry any pending failed files
|
||||
}
|
||||
|
|
@ -536,7 +536,7 @@ public static class Program
|
|||
await SaveToLocalCompressedFallback(compressedBytes, fileNameWithoutExtension);
|
||||
}
|
||||
|
||||
//Heartbit();
|
||||
Heartbit();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -544,6 +544,25 @@ public static class Program
|
|||
_fileCounter++;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void Heartbit()
|
||||
{
|
||||
var s3Bucket = Config.Load().S3?.Bucket;
|
||||
var tryParse = int.TryParse(s3Bucket?.Split("-")[0], out var installationId);
|
||||
|
||||
if (tryParse)
|
||||
{
|
||||
var returnedStatus = new StatusMessage
|
||||
{
|
||||
InstallationId = installationId,
|
||||
Product = 2,
|
||||
Status = _sodiohomeAlarmState,
|
||||
Type = MessageType.Heartbit,
|
||||
};
|
||||
if (s3Bucket != null)
|
||||
RabbitMqManager.InformMiddleware(returnedStatus);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task SaveToLocalCompressedFallback(Byte[] compressedData, String fileNameWithoutExtension)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue