Apply code formatting cleanup across monitor projects

- Reindent appsettings.json and the MSBuild project files
- Collapse single-statement guard blocks and tidy using and member order
- Normalize XML doc indentation and file endings
- Reorder BatteryMonitor test-data helpers and move the exclusion tests into
  their own region
- Carry the same formatting through the boiler config, control, entity and
  test files
This commit is contained in:
2026-11-30 11:52:06 +02:00
parent cf8c9434c8
commit 24729ee267
165 changed files with 2513 additions and 2470 deletions
+32 -54
View File
@@ -9,7 +9,8 @@ using NordPoolManager.Models.Consts;
namespace NordPoolManager;
public class NordPoolPriceService(Services services, IMapper mapper, ILogger<NordPoolPriceService> logger) : INordPoolPriceService
public class NordPoolPriceService(Services services, IMapper mapper, ILogger<NordPoolPriceService> logger)
: INordPoolPriceService
{
private readonly NordpoolServices _nordPoolServices = services.Nordpool;
@@ -29,19 +30,16 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
if ((TodayNordPoolPrice?.Prices == null || TodayNordPoolPrice.Prices.Count == 0) && ShouldFetchNewPrices(today))
{
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Fetching today's prices from API for CET date: {Today}", today);
}
TodayNordPoolPrice = await FetchPricesForDateWithRetryAsync(today, "today");
}
if ((TomorrowNordPoolPrice?.Prices == null || TomorrowNordPoolPrice.Prices.Count == 0) && ShouldFetchNewPrices(today.AddDays(1)))
if ((TomorrowNordPoolPrice?.Prices == null || TomorrowNordPoolPrice.Prices.Count == 0) &&
ShouldFetchNewPrices(today.AddDays(1)))
{
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Fetching tomorrow's prices from API for CET date: {Tomorrow}", today.AddDays(1));
}
TomorrowNordPoolPrice = await FetchPricesForDateWithRetryAsync(today.AddDays(1), "tomorrow");
}
@@ -55,31 +53,24 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
var index = GetTimeQuarterIndex(DateTime.UtcNow);
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Current time quarter index: {Index}, Total prices available: {Count}", index, TodayNordPoolPrice?.Prices?.Count ?? 0);
}
logger.LogDebug("Current time quarter index: {Index}, Total prices available: {Count}", index,
TodayNordPoolPrice?.Prices?.Count ?? 0);
if (DayQuartersIndex == index)
{
return;
}
if (DayQuartersIndex == index) return;
if (TodayNordPoolPrice?.Prices != null && TodayNordPoolPrice.Prices.Count > index)
{
var price = TodayNordPoolPrice.Prices[index].Price;
if (price.HasValue)
{
CurrentPrice = price.Value;
}
else
{
logger.LogWarning("Price at index {Index} is null", index);
}
}
else
{
logger.LogWarning("Cannot get price for index {Index}. Prices is null: {IsNull}, Prices count: {Count}", index, TodayNordPoolPrice?.Prices == null, TodayNordPoolPrice?.Prices?.Count ?? 0);
logger.LogWarning("Cannot get price for index {Index}. Prices is null: {IsNull}, Prices count: {Count}",
index, TodayNordPoolPrice?.Prices == null, TodayNordPoolPrice?.Prices?.Count ?? 0);
}
DayQuartersIndex = index;
@@ -92,25 +83,13 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
public bool ShouldFetchNewPrices(DateOnly today)
{
if (!LastFetchedDate.HasValue)
{
return true;
}
if (!LastFetchedDate.HasValue) return true;
if (LastFetchedDate.Value < today)
{
return true;
}
if (LastFetchedDate.Value < today) return true;
if (TodayNordPoolPrice?.Prices == null || TodayNordPoolPrice.Prices.Count == 0)
{
return true;
}
if (TodayNordPoolPrice?.Prices == null || TodayNordPoolPrice.Prices.Count == 0) return true;
if (TomorrowNordPoolPrice?.Prices is { Count: > 0 })
{
return false;
}
if (TomorrowNordPoolPrice?.Prices is { Count: > 0 }) return false;
var currentHour = DateTime.Now.Hour;
@@ -119,7 +98,9 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
public void RollOverPrices(DateOnly today)
{
TodayNordPoolPrice = TomorrowNordPoolPrice?.Prices is { Count: > 0 } ? TomorrowNordPoolPrice : new NordPoolPrice();
TodayNordPoolPrice = TomorrowNordPoolPrice?.Prices is { Count: > 0 }
? TomorrowNordPoolPrice
: new NordPoolPrice();
TomorrowNordPoolPrice = null;
@@ -130,7 +111,6 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
private async Task<NordPoolPrice> FetchPricesForDateWithRetryAsync(DateOnly date, string label)
{
for (var attempt = 1; attempt <= NordPoolConsts.MaxFetchRetryAttempts; attempt++)
{
try
{
return await GetNordPoolPriceAsync(date);
@@ -138,18 +118,23 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
catch (InvalidOperationException ex) when (attempt < NordPoolConsts.MaxFetchRetryAttempts)
{
var delay = TimeSpan.FromSeconds(NordPoolConsts.RetryBaseDelaySeconds * Math.Pow(2, attempt - 1));
logger.LogWarning(ex, "Attempt {Attempt}/{MaxAttempts} to fetch {Label} prices for {Date} failed. Retrying in {Delay}", attempt, NordPoolConsts.MaxFetchRetryAttempts, label, date, delay);
logger.LogWarning(ex,
"Attempt {Attempt}/{MaxAttempts} to fetch {Label} prices for {Date} failed. Retrying in {Delay}",
attempt, NordPoolConsts.MaxFetchRetryAttempts, label, date, delay);
await Task.Delay(delay);
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to fetch {Label} prices for {Date} on attempt {Attempt} with unexpected error", label, date, attempt);
logger.LogError(ex,
"Failed to fetch {Label} prices for {Date} on attempt {Attempt} with unexpected error", label, date,
attempt);
break;
}
}
logger.LogWarning("All {MaxAttempts} attempts to fetch {Label} prices for {Date} exhausted; returning empty prices", NordPoolConsts.MaxFetchRetryAttempts, label, date);
logger.LogWarning(
"All {MaxAttempts} attempts to fetch {Label} prices for {Date} exhausted; returning empty prices",
NordPoolConsts.MaxFetchRetryAttempts, label, date);
return new NordPoolPrice();
}
@@ -172,14 +157,13 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
internal NordPoolPrice ParseNordPoolResult(JsonElement? element)
{
if (element == null)
{
return new NordPoolPrice();
}
if (element == null) return new NordPoolPrice();
var priceResult = element.Value.Deserialize<NordPoolPriceResultDto>();
return priceResult != null ? mapper.Map<NordPoolPriceResultDto, NordPoolPrice>(priceResult) : new NordPoolPrice();
return priceResult != null
? mapper.Map<NordPoolPriceResultDto, NordPoolPrice>(priceResult)
: new NordPoolPrice();
}
internal static NordPoolPrice AdjustedNordPoolPrice(NordPoolPrice todayNordPoolPrice)
@@ -189,17 +173,11 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
Prices = new List<NordPoolDayPrice>()
};
if (todayNordPoolPrice.Prices is null)
{
return recalculatedPrice;
}
if (todayNordPoolPrice.Prices is null) return recalculatedPrice;
foreach (var price in todayNordPoolPrice.Prices)
{
if (price.Price is null)
{
continue;
}
if (price.Price is null) continue;
recalculatedPrice.Prices.Add(new NordPoolDayPrice
{
@@ -229,4 +207,4 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
return totalMinutes / NordPoolConsts.MinutesPerInterval;
}
}
}