Refactor project structure and add initial files
هذا الالتزام موجود في:
29
aspire-sample/aspire-sample.Web/WeatherApiClient.cs
Normal file
29
aspire-sample/aspire-sample.Web/WeatherApiClient.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace aspire_sample.Web;
|
||||
|
||||
public class WeatherApiClient(HttpClient httpClient)
|
||||
{
|
||||
public async Task<WeatherForecast[]> GetWeatherAsync(int maxItems = 10, CancellationToken cancellationToken = default)
|
||||
{
|
||||
List<WeatherForecast>? forecasts = null;
|
||||
|
||||
await foreach (var forecast in httpClient.GetFromJsonAsAsyncEnumerable<WeatherForecast>("/weatherforecast", cancellationToken))
|
||||
{
|
||||
if (forecasts?.Count >= maxItems)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (forecast is not null)
|
||||
{
|
||||
forecasts ??= [];
|
||||
forecasts.Add(forecast);
|
||||
}
|
||||
}
|
||||
|
||||
return forecasts?.ToArray() ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
public record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
||||
{
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
}
|
المرجع في مشكلة جديدة
حظر مستخدم