using var , keep carriage order and use Uppeercase Type

This commit is contained in:
atef 2025-04-24 11:37:09 +02:00
parent ee8aa47a8e
commit c255c9cecb
1 changed files with 14 additions and 14 deletions

View File

@ -819,22 +819,22 @@ internal static class Program
sc.ResetAlarmsAndWarnings = true;
}
private static void InsertIntoJson(Dictionary<string, object> jsonDict, String[] keys, string value)
private static void InsertIntoJson(Dictionary<String, Object> jsonDict, String[] keys, String value)
{
Dictionary<string, object> currentDict = jsonDict;
for (int i = 1; i < keys.Length; i++) // Start at 1 to skip empty root
var currentDict = jsonDict;
for (Int16 i = 1; i < keys.Length; i++) // Start at 1 to skip empty root
{
string key = keys[i];
var key = keys[i];
if (!currentDict.ContainsKey(key))
{
currentDict[key] = new Dictionary<string, object>();
currentDict[key] = new Dictionary<String, Object>();
}
if (i == keys.Length - 1) // Last key, store the value
{
if (!value.Contains(",") && double.TryParse(value, out double doubleValue)) // Try to parse value as a number
if (!value.Contains(",") && double.TryParse(value, out Double doubleValue)) // Try to parse value as a number
{
currentDict[key] = Math.Round(doubleValue, 2); // Round to 2 decimal places
@ -846,7 +846,7 @@ internal static class Program
}
else
{
currentDict = (Dictionary<string, object>)currentDict[key];
currentDict = (Dictionary<String, Object>)currentDict[key];
}
}
@ -862,16 +862,16 @@ internal static class Program
{
if (string.IsNullOrWhiteSpace(line)) continue;
string[] parts = line.Split(';');
string keyPath = parts[0];
string value = parts[1];
string unit = parts.Length > 2 ? parts[2].Trim() : "";
var parts = line.Split(';');
var keyPath = parts[0];
var value = parts[1];
var unit = parts.Length > 2 ? parts[2].Trim() : "";
//Console.WriteLine(line);
// Console.WriteLine($"Key: {keyPath}, Value: {value}, Unit: {unit}");
InsertIntoJson(jsonData, keyPath.Split('/'), value);
}
string jsonOutput = JsonConvert.SerializeObject(jsonData, Formatting.None);
var jsonOutput = JsonConvert.SerializeObject(jsonData, Formatting.None);
jsonOutput.LogInfo();
await RestApiSavingFile(csv);
@ -903,7 +903,7 @@ internal static class Program
var compressedBytes = CompresseBytes(jsonToSend);
// Encode the compressed byte array as a Base64 string
string base64String = Convert.ToBase64String(compressedBytes);
var base64String = Convert.ToBase64String(compressedBytes);
// Create StringContent from Base64 string
var stringContent = new StringContent(base64String, Encoding.UTF8, "application/base64");
@ -984,7 +984,7 @@ internal static class Program
Directory.CreateDirectory(directoryPath);
}
string filePath = Path.Combine(directoryPath, "status.csv");
var filePath = Path.Combine(directoryPath, "status.csv");
await File.WriteAllTextAsync(filePath, csv.SplitLines().Where(l => !l.Contains("Secret")).JoinLines());
}