Errore tipo async/await da debuggare..

This commit is contained in:
Samuele Locatelli
2021-05-20 12:40:46 +02:00
parent 70369312b3
commit ce77f20b68
3 changed files with 40 additions and 8 deletions
+29 -3
View File
@@ -7,6 +7,9 @@ using System.Text;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using MP.Data;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
namespace MP.Stats.Data
{
@@ -18,6 +21,8 @@ namespace MP.Stats.Data
private static ILogger<MpStatsService> _logger;
private static List<MP.Data.DatabaseModels.AzioniUL> ActionsList = new List<MP.Data.DatabaseModels.AzioniUL>();
private readonly IDistributedCache distributedCache;
private readonly IMemoryCache memoryCache;
#endregion Private Fields
@@ -36,10 +41,12 @@ namespace MP.Stats.Data
#region Public Constructors
public MpStatsService(IConfiguration configuration, ILogger<MpStatsService> logger)
public MpStatsService(IConfiguration configuration, ILogger<MpStatsService> logger, IMemoryCache memoryCache, IDistributedCache distributedCache)
{
_logger = logger;
_configuration = configuration;
this.memoryCache = memoryCache;
this.distributedCache = distributedCache;
string connStr = _configuration.GetConnectionString("Mp.Stats");
if (string.IsNullOrEmpty(connStr))
{
@@ -100,9 +107,28 @@ namespace MP.Stats.Data
return Task.FromResult(dbController.StatScartiGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo).ToArray());
}
public Task<MP.Data.DatabaseModels.TurniOee[]> StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, string searchVal = "")
public async Task<MP.Data.DatabaseModels.TurniOee[]> StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, string searchVal = "")
{
return Task.FromResult(dbController.StatTurniOeeGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo).ToArray());
List<MP.Data.DatabaseModels.TurniOee> answ = new List<MP.Data.DatabaseModels.TurniOee>();
var cacheKey = "oeeData";
string serializedCustomerList;
var redisCustomerList = await distributedCache.GetAsync(cacheKey);
if (redisCustomerList != null)
{
serializedCustomerList = Encoding.UTF8.GetString(redisCustomerList);
answ = JsonConvert.DeserializeObject<List<MP.Data.DatabaseModels.TurniOee>>(serializedCustomerList);
}
else
{
answ = dbController.StatTurniOeeGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo);
serializedCustomerList = JsonConvert.SerializeObject(answ);
redisCustomerList = Encoding.UTF8.GetBytes(serializedCustomerList);
var options = new DistributedCacheEntryOptions()
.SetAbsoluteExpiration(DateTime.Now.AddMinutes(10))
.SetSlidingExpiration(TimeSpan.FromMinutes(2));
await distributedCache.SetAsync(cacheKey, redisCustomerList, options);
}
return answ.ToArray();
}
public Task<MP.Data.DatabaseModels.TurniPareto[]> StatTurniParetoGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, string searchVal = "")
+1
View File
@@ -34,6 +34,7 @@
<PackageReference Include="Blazorise.Bootstrap" Version="0.9.3.6" />
<PackageReference Include="Blazorise.Charts" Version="0.9.3.6" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="0.9.3.6" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
+10 -5
View File
@@ -79,11 +79,16 @@ namespace MP.Stats
public void ConfigureServices(IServiceCollection services)
{
services.AddBlazorise(options =>
{
options.ChangeTextOnKeyPress = true; // optional
})
.AddBootstrapProviders()
.AddFontAwesomeIcons();
{
options.ChangeTextOnKeyPress = true; // optional
})
.AddBootstrapProviders()
.AddFontAwesomeIcons();
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = "localhost:6379";
});
services.AddLocalization();