update Program.cs

This commit is contained in:
atef 2024-06-27 14:21:13 +02:00
parent 29c6217990
commit d7b91d4dec
1 changed files with 26 additions and 22 deletions

View File

@ -58,7 +58,6 @@ internal static class Program
private static Boolean _subscribedToQueue = false;
private static Boolean _subscribeToQueueForTheFirstTime = false;
private static SalimaxAlarmState _prevSalimaxState = SalimaxAlarmState.Green;
//private static Int32 _heartBitInterval = 0;
private const UInt16 NbrOfFileToConcatenate = 30;
private static UInt16 _counterOfFile = 0;
private static SalimaxAlarmState _salimaxAlarmState = SalimaxAlarmState.Green;
@ -704,12 +703,12 @@ internal static class Program
_counterOfFile = 0;
var logFileConcatenator = new LogFileConcatenator();
var csvToSend = logFileConcatenator.ConcatenateFiles(NbrOfFileToConcatenate);
var s3Path = timeStamp.ToUnixTime() + ".csv";
var request = s3Config.CreatePutRequest(s3Path);
s3Path.WriteLine("");
var csvToSend = logFileConcatenator.ConcatenateFiles(NbrOfFileToConcatenate);
"Sending to S3".WriteLine();
var request = s3Config.CreatePutRequest(s3Path);
//Use this for no compression
//var response = await request.PutAsync(new StringContent(csv));
@ -729,34 +728,39 @@ internal static class Program
Console.WriteLine("ERROR: PUT");
var error = await response.GetStringAsync();
Console.WriteLine(error);
Heartbit(0);
return false;
}
Console.WriteLine("----------------------------------------Sending Heartbit----------------------------------------");
var s3Bucket = Config.Load().S3?.Bucket;
int.TryParse(s3Bucket?.Split("-")[0], out var installationId);
int.TryParse(timeStamp.ToUnixTime().ToString(), out var nameOfCsvFile);
var returnedStatus = new StatusMessage
{
InstallationId = installationId,
Product = 0,
Status = _salimaxAlarmState,
Type = MessageType.Heartbit,
Timestamp = nameOfCsvFile
};
if (s3Bucket != null)
RabbitMqManager.InformMiddleware(returnedStatus);
Heartbit(timeStamp);
}
_counterOfFile++;
return true;
}
private static void Heartbit(DateTime timeStamp)
{
var s3Bucket = Config.Load().S3?.Bucket;
int.TryParse(s3Bucket?.Split("-")[0], out var installationId);
int.TryParse(timeStamp.ToUnixTime().ToString(), out var nameOfCsvFile);
var returnedStatus = new StatusMessage
{
InstallationId = installationId,
Product = 0,
Status = _salimaxAlarmState,
Type = MessageType.Heartbit,
Timestamp = nameOfCsvFile
};
if (s3Bucket != null)
RabbitMqManager.InformMiddleware(returnedStatus);
}
private static Byte[] CompresseBytes(String csvToSend)
{
//Compress CSV data to a byte array