Apply code formatting cleanup across the monitor projects
- Wrap using directives in `#region` blocks across the Battery, Boiler and NordPool sources and tests - Expand single-statement guards and loops into braced blocks - Realign wrapped method arguments, chained calls and continuations - Replace target-typed `new()` with explicit generic construction and empty string literals with `string.Empty` - Flatten the boiler config expression and reindent the remaining touched files
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#region
|
||||
|
||||
using System.Text.Json;
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -6,6 +8,8 @@ using NordPool.Models.Dtos;
|
||||
using NordPoolManager.Interface;
|
||||
using NordPoolManager.Models.Consts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NordPoolManager;
|
||||
|
||||
/// <summary>
|
||||
@@ -61,7 +65,10 @@ public class NordPoolPriceService(IMapper mapper, ILogger<NordPoolPriceService>
|
||||
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)
|
||||
{
|
||||
@@ -91,13 +98,25 @@ public class NordPoolPriceService(IMapper mapper, ILogger<NordPoolPriceService>
|
||||
|
||||
public bool ShouldFetchNewPrices(DateOnly date)
|
||||
{
|
||||
if (!LastFetchedDate.HasValue) return true;
|
||||
if (!LastFetchedDate.HasValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (LastFetchedDate.Value < date) return true;
|
||||
if (LastFetchedDate.Value < date)
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -107,8 +126,8 @@ public class NordPoolPriceService(IMapper mapper, ILogger<NordPoolPriceService>
|
||||
public void RollOverPrices(DateOnly date)
|
||||
{
|
||||
TodayNordPoolPrice = TomorrowNordPoolPrice?.Prices is { Count: > 0 }
|
||||
? TomorrowNordPoolPrice
|
||||
: new NordPoolPrice();
|
||||
? TomorrowNordPoolPrice
|
||||
: new NordPoolPrice();
|
||||
|
||||
TomorrowNordPoolPrice = null;
|
||||
|
||||
@@ -125,13 +144,16 @@ public class NordPoolPriceService(IMapper mapper, ILogger<NordPoolPriceService>
|
||||
|
||||
internal NordPoolPrice ParseNordPoolResult(JsonElement? element)
|
||||
{
|
||||
if (!element.HasValue) return new NordPoolPrice();
|
||||
if (!element.HasValue)
|
||||
{
|
||||
return new NordPoolPrice();
|
||||
}
|
||||
|
||||
var priceResult = element.Value.Deserialize<NordPoolPriceResultDto>();
|
||||
|
||||
return priceResult != null
|
||||
? mapper.Map<NordPoolPriceResultDto, NordPoolPrice>(priceResult)
|
||||
: new NordPoolPrice();
|
||||
? mapper.Map<NordPoolPriceResultDto, NordPoolPrice>(priceResult)
|
||||
: new NordPoolPrice();
|
||||
}
|
||||
|
||||
internal static NordPoolPrice AdjustedNordPoolPrice(NordPoolPrice todayNordPoolPrice)
|
||||
@@ -141,11 +163,17 @@ public class NordPoolPriceService(IMapper mapper, ILogger<NordPoolPriceService>
|
||||
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
|
||||
{
|
||||
@@ -179,6 +207,7 @@ public class NordPoolPriceService(IMapper mapper, ILogger<NordPoolPriceService>
|
||||
private async Task<NordPoolPrice> FetchPricesForDateWithRetryAsync(DateOnly date, Func<DateOnly, Task<NordPoolPrice>> fetchPricesForDate)
|
||||
{
|
||||
for (var attempt = 1; attempt <= NordPoolConsts.MaxFetchRetryAttempts; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await fetchPricesForDate(date);
|
||||
@@ -193,8 +222,10 @@ public class NordPoolPriceService(IMapper mapper, ILogger<NordPoolPriceService>
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to fetch prices for {Date} on attempt {Attempt} with unexpected error", date, attempt);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogWarning("All {MaxAttempts} attempts to fetch prices for {Date} exhausted; returning empty prices", NordPoolConsts.MaxFetchRetryAttempts, date);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user