Riorganizzazione classe con CodeMaid

This commit is contained in:
Samuele E. Locatelli
2022-06-04 17:44:37 +02:00
parent 533f3f4f8f
commit aaeae6e99e
5 changed files with 78 additions and 74 deletions
+74 -70
View File
@@ -1,16 +1,20 @@
using MP.Data.DatabaseModels;
using System.Text;
using StackExchange.Redis;
using NLog;
using MP.Data.DTO;
using MP.Data.Conf;
using MP.Data.DatabaseModels;
using Newtonsoft.Json;
using MP.Data;
using MP.Data.Conf;
using NLog;
using StackExchange.Redis;
using System.Text;
namespace MP.Mon.Data
{
public class MpDataService : IDisposable
{
#region Public Fields
public static MP.Data.Controllers.MpMonController dbController;
#endregion Public Fields
#region Private Fields
private static IConfiguration _configuration;
@@ -18,11 +22,6 @@ namespace MP.Mon.Data
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
/// <summary>
/// Dizionario dei tag configurati per IOB
/// </summary>
protected Dictionary<string, List<TagData>> currTagConf { get; set; } = new Dictionary<string, List<TagData>>();
/// <summary>
/// Oggetto per connessione a REDIS
/// </summary>
@@ -36,63 +35,6 @@ namespace MP.Mon.Data
#endregion Private Fields
#region Public Fields
public static MP.Data.Controllers.MpMonController dbController;
#endregion Public Fields
/// <summary>
/// restituisce il valore da REDIS associato al tag richeisto
/// </summary>
/// <param name="redKey">Chiave in cui cercare il valore</param>
/// <returns></returns>
public async Task<string> getTagConf(string redKey)
{
string outVal = "";
// cerco in REDIS la conf x l'IOB
string rawData = await redisDb.StringGetAsync(redKey);
if (!string.IsNullOrEmpty(rawData))
{
outVal = rawData;
}
return await Task.FromResult(outVal);
}
/// <summary>
/// Prova a caricare da file la conf degli IOB se presente
/// </summary>
private void tryLoadIobTags()
{
Dictionary<string, List<TagData>> currConf = new Dictionary<string, List<TagData>>();
string strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
if (!string.IsNullOrEmpty(strExeFilePath))
{
string? strWorkPath = Path.GetDirectoryName(strExeFilePath);
if (!string.IsNullOrEmpty(strWorkPath))
{
string filePath = $"{strWorkPath}/Conf/iobTagsConf.json";
if (File.Exists(filePath))
{
string rawData = File.ReadAllText(filePath);
if (!string.IsNullOrEmpty(rawData))
{
var fileConfData = JsonConvert.DeserializeObject<IobTags>(rawData);
if (fileConfData != null)
{
currConf = fileConfData.IobSetup;
}
}
}
if (currConf != null)
{
currTagConf = currConf;
}
}
}
}
#region Public Constructors
public MpDataService(IConfiguration configuration, ILogger<MpDataService> logger)
@@ -127,6 +69,15 @@ namespace MP.Mon.Data
#endregion Public Constructors
#region Protected Properties
/// <summary>
/// Dizionario dei tag configurati per IOB
/// </summary>
protected Dictionary<string, List<TagData>> currTagConf { get; set; } = new Dictionary<string, List<TagData>>();
#endregion Protected Properties
#region Public Methods
public Task<List<ConfigModel>> ConfigGetAll()
@@ -140,6 +91,23 @@ namespace MP.Mon.Data
dbController.Dispose();
}
/// <summary>
/// restituisce il valore da REDIS associato al tag richeisto
/// </summary>
/// <param name="redKey">Chiave in cui cercare il valore</param>
/// <returns></returns>
public async Task<string> getTagConf(string redKey)
{
string outVal = "";
// cerco in REDIS la conf x l'IOB
string rawData = await redisDb.StringGetAsync(redKey);
if (!string.IsNullOrEmpty(rawData))
{
outVal = rawData;
}
return await Task.FromResult(outVal);
}
public Task<List<Macchine>> MacchineGetAll()
{
return Task.FromResult(dbController.MacchineGetAll().ToList());
@@ -155,7 +123,43 @@ namespace MP.Mon.Data
return Task.FromResult(dbResult);
}
#endregion Public Methods
#region Private Methods
/// <summary>
/// Prova a caricare da file la conf degli IOB se presente
/// </summary>
private void tryLoadIobTags()
{
Dictionary<string, List<TagData>> currConf = new Dictionary<string, List<TagData>>();
string strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
if (!string.IsNullOrEmpty(strExeFilePath))
{
string? strWorkPath = Path.GetDirectoryName(strExeFilePath);
if (!string.IsNullOrEmpty(strWorkPath))
{
string filePath = $"{strWorkPath}/Conf/iobTagsConf.json";
if (File.Exists(filePath))
{
string rawData = File.ReadAllText(filePath);
if (!string.IsNullOrEmpty(rawData))
{
var fileConfData = JsonConvert.DeserializeObject<IobTags>(rawData);
if (fileConfData != null)
{
currConf = fileConfData.IobSetup;
}
}
}
if (currConf != null)
{
currTagConf = currConf;
}
}
}
}
#endregion Private Methods
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>6.15.2206.319</Version>
<Version>6.15.2206.417</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MON MAPO</i>
<h4>Versione: 6.15.2206.319</h4>
<h4>Versione: 6.15.2206.417</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
6.15.2206.319
6.15.2206.417
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.15.2206.319</version>
<version>6.15.2206.417</version>
<url>https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/MP.Mon.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>