Inizio conf servizi accesso dati
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.MONO.Core
|
||||
{
|
||||
public class EvData
|
||||
{
|
||||
public DateTime DtRif { get; set; } = DateTime.Now;
|
||||
|
||||
public double Value { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DTO\" />
|
||||
<PackageReference Include="System.Collections" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.MONO.Data.Controllers
|
||||
{
|
||||
public class MpDbController : IDisposable
|
||||
{
|
||||
private static IConfiguration _configuration;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public MpDbController(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
//Log.Info("Dispose di GWMSController");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
namespace MP.MONO.Data.DbModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Tabella Codifica Tipi (valore min/max e css associati)
|
||||
/// </summary>
|
||||
[Table("TypeConf")]
|
||||
public class TypeConfModel
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// UID
|
||||
/// </summary>
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int TypeConfId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tipo
|
||||
/// </summary>
|
||||
public string Type { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Valore minimo x intervallo set
|
||||
/// </summary>
|
||||
public double MinVal { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// Valore minimo x intervallo set
|
||||
/// </summary>
|
||||
public double MaxVal { get; set; } = 999;
|
||||
|
||||
/// <summary>
|
||||
/// Classe css associata (default)
|
||||
/// </summary>
|
||||
[MaxLength(50)]
|
||||
public string CssClass { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Classe css associata (override): se non vuota usa questa
|
||||
/// </summary>
|
||||
[MaxLength(50)]
|
||||
public string CssClassOvr { get; set; } = "";
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,8 +1,78 @@
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using MP.MONO.Data.Controllers;
|
||||
using NLog;
|
||||
|
||||
namespace MP.MONO.UI.Data
|
||||
{
|
||||
public class CurrentDataService
|
||||
public class CurrentDataService : IDisposable
|
||||
{
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
private static ILogger<CurrentDataService> _logger;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private readonly IEmailSender _emailSender;
|
||||
private readonly IDistributedCache distributedCache;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
|
||||
public static MpDbController dbController;
|
||||
|
||||
/// <summary>
|
||||
/// Durata assoluta massima della cache IN SECONDI
|
||||
/// </summary>
|
||||
private int chAbsExp = 60 * 5;
|
||||
|
||||
/// <summary>
|
||||
/// Durata della cache IN SECONDI in modalità inattiva (non acceduta) prima di venire rimossa
|
||||
/// NON estende oltre il tempo massimo di validità della cache (chAbsExp)
|
||||
/// </summary>
|
||||
private int chSliExp = 60 * 1;
|
||||
|
||||
public CurrentDataService(IConfiguration configuration, ILogger<CurrentDataService> logger, IMemoryCache memoryCache, IDistributedCache distributedCache, IEmailSender emailSender)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_emailSender = emailSender;
|
||||
// conf cache
|
||||
this.memoryCache = memoryCache;
|
||||
this.distributedCache = distributedCache;
|
||||
// conf DB
|
||||
string connStr = _configuration.GetConnectionString("MP.MONO.Data");
|
||||
if (string.IsNullOrEmpty(connStr))
|
||||
{
|
||||
_logger.LogError("ConnString empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
dbController = new MpDbController(configuration);
|
||||
_logger.LogInformation("DbController OK");
|
||||
}
|
||||
}
|
||||
|
||||
private DistributedCacheEntryOptions cacheOpt(bool fastCache)
|
||||
{
|
||||
var numSecAbsExp = fastCache ? chAbsExp : chAbsExp * 10;
|
||||
var numSecSliExp = fastCache ? chSliExp : chSliExp * 10;
|
||||
return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp));
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database controller
|
||||
dbController.Dispose();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Hash Redis contenente i dati MP di una specifico TYPE (es StatusMacchina, StateMachineIngressi, ...)
|
||||
/// </summary>
|
||||
/// <param name="dataType"></param>
|
||||
/// <returns></returns>
|
||||
private static string mHash(string dataType)
|
||||
{
|
||||
return $"DATA:{dataType}";
|
||||
}
|
||||
|
||||
protected Dictionary<string, string> ParametersList { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
public async Task<Dictionary<string, string>> GetCurrentParameters()
|
||||
|
||||
@@ -8,14 +8,10 @@
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"Redis": "localhost:6379",
|
||||
//"AuthConnection": "Server=10.74.83.97;port=3306;database=GWMS;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;",
|
||||
//"DefaultConnection": "Server=10.74.83.97;port=3306;database=GWMS;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;",
|
||||
//"AdminConnection": "Server=10.74.83.97;port=3306;database=GWMS;user=root;pwd=Egalware_24068!;sslmode=None;",
|
||||
//"GWMS.Data": "Server=10.74.83.97;port=3306;database=GWMS;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;"
|
||||
"AuthConnection": "Server=localhost;port=3306;database=GWMS;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;",
|
||||
"DefaultConnection": "Server=localhost;port=3306;database=GWMS;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;",
|
||||
"AdminConnection": "Server=localhost;port=3306;database=GWMS;user=root;pwd=Egalware_24068!;sslmode=None;",
|
||||
"GWMS.Data": "Server=localhost;port=3306;database=GWMS;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;"
|
||||
"DefaultConnection": "Server=localhost;port=3306;database=MAPO.MONO;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;",
|
||||
"AdminConnection": "Server=localhost;port=3306;database=MAPO.MONO;user=root;pwd=Egalware_24068!;sslmode=None;",
|
||||
"MP.MONO.Data": "Server=localhost;port=3306;database=MAPO.MONO;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;"
|
||||
},
|
||||
"DbConfig": {
|
||||
"Server": "localhost",
|
||||
|
||||
Reference in New Issue
Block a user