Update gestione conf recipe

This commit is contained in:
Samuele Locatelli
2023-02-08 09:52:48 +01:00
parent cc753023ea
commit 13adc7b441
14 changed files with 227 additions and 17 deletions
+3
View File
@@ -8,6 +8,9 @@ namespace MP.Data.Conf
{
public class RecipeConfig
{
/// <summary>
/// File di configurazione template ricetta
/// </summary>
public string TemplateFile { get; set; } = "";
/// <summary>
/// Configurazione ricetta x header
+93
View File
@@ -0,0 +1,93 @@
using Microsoft.Extensions.Configuration;
using NLog;
using NLog.Fluent;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Bson;
using MP.Data.MgModels;
using System.IO;
using MP.Data.Conf;
using Newtonsoft.Json;
namespace MP.Data.Controllers
{
public class MpMongoController : IDisposable
{
public MpMongoController(IConfiguration configuration)
{
_configuration = configuration;
string mongoConf = _configuration.GetConnectionString("MongoConnect");
client = new MongoClient(mongoConf);
Log.Info("Avviata classe MpMongoController");
}
public void Dispose()
{
client = null;
_configuration = null;
}
/// <summary>
/// Ricerca ricetta su MongoDB dato PODL
/// </summary>
/// <param name="idxPODL"></param>
/// <returns></returns>
public async Task<RecipeModel> RecipeGetByPODL(int idxPODL)
{
await Task.Delay(1);
RecipeModel answ = new RecipeModel();
return answ;
}
public async Task<bool> RecipeSetByPODL(RecipeModel currRecord)
{
await Task.Delay(1);
bool answ = false;
return answ;
}
/// <summary>
/// Init ricetta dato PODL + conf
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public RecipeModel InitRecipe(int idxPODL, string confPath)
{
RecipeModel answ = new RecipeModel();
// per prima cosa leggo file di conf x inizializzare ricetta...
string fullPath = RecipePath(confPath);
bool fileOk = File.Exists(fullPath);
if (fileOk)
{
string rawData = File.ReadAllText(fullPath);
var currRecipe = JsonConvert.DeserializeObject<RecipeConfig>(rawData);
// copio la mia ricetta...
answ = new RecipeModel()
{
IdxPODL = idxPODL,
TemplateFile = currRecipe.TemplateFile,
HeadConf = currRecipe.HeadConf,
RowsConf = currRecipe.RowsConf
};
}
return answ;
}
private MongoClient client = new MongoClient("mongodb://localhost:27017");
private static IConfiguration _configuration;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
public static string RecipePath(string ruleName)
{
return string.Format($"Recipe/{ruleName}");
}
}
}
+1
View File
@@ -26,6 +26,7 @@
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.9" />
<PackageReference Include="MongoDB.Driver" Version="2.19.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="NLog" Version="5.1.1" />
</ItemGroup>
</Project>
+3 -3
View File
@@ -5,10 +5,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MP.Data.Conf;
namespace MP.Data.MgModels
{
public class RecipeModel
public class RecipeModel : RecipeConfig
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
@@ -16,9 +17,8 @@ namespace MP.Data.MgModels
public int IdxPODL { get; set; } = 0;
public int IdxODL { get; set; } = 0;
public string TemplatePath { get; set; } = null!;
public string RawRecipe { get; set; } = null!;
public string RawRecipe { get; set; } = "";
}
}
+1 -1
View File
@@ -149,7 +149,7 @@ else
@if (showRecipe && currRecord != null)
{
<div class="col-4">
<RecipeMan IdxOdl="@currRecord.IdxOdl"></RecipeMan>
<RecipeMan IdxPODL="@currRecord.IdxPromessa" RecipePath="@currRecipePath"></RecipeMan>
</div>
}
</div>
+14 -7
View File
@@ -108,6 +108,13 @@ namespace MP.SPEC.Components
await Task.Delay(1);
}
protected async Task doShowRecipe(PODLExpModel selRec)
{
currRecord = selRec;
currRecipePath = await MDService.MacchineRecipe(selRec.IdxMacchina);
showRecipe = true;
}
protected override async Task OnInitializedAsync()
{
ListStati = await MDService.AnagStatiComm();
@@ -143,6 +150,7 @@ namespace MP.SPEC.Components
protected async Task resetSel()
{
currRecord = null;
currRecipePath = "";
showRecipe = false;
await RecordSel.InvokeAsync(null);
}
@@ -204,12 +212,6 @@ namespace MP.SPEC.Components
}
}
protected void doShowRecipe(PODLExpModel selRec)
{
showRecipe = true;
currRecord = selRec;
}
protected async Task UpdateData()
{
currRecord = null;
@@ -222,6 +224,11 @@ namespace MP.SPEC.Components
private static Logger Log = LogManager.GetCurrentClassLogger();
/// <summary>
/// Percorso ricetta corrente
/// </summary>
private string currRecipePath = "";
private PODLExpModel? currRecord = null;
private List<PODLExpModel>? ListRecords;
@@ -421,7 +428,7 @@ namespace MP.SPEC.Components
/// <returns></returns>
private async Task<bool> machineHasRecipe(string idxMacchina)
{
string recipePath = await MDService.MacchineRecipe(idxMacchina);
var recipePath = await MDService.MacchineRecipe(idxMacchina);
return !string.IsNullOrEmpty(recipePath);
}
+9
View File
@@ -1,2 +1,11 @@
<h3>RecipeMan</h3>
@if(CurrRecipe==null)
{
<LoadingData></LoadingData>
}
else
{
<b>dati ricetta</b>
}
+24 -1
View File
@@ -15,6 +15,8 @@ using MP.SPEC;
using MP.SPEC.Shared;
using MP.SPEC.Components;
using EgwCoreLib.Razor;
using MP.Data.MgModels;
using MP.SPEC.Data;
namespace MP.SPEC.Components
{
@@ -22,8 +24,29 @@ namespace MP.SPEC.Components
{
[Parameter]
public int IdxOdl { get; set; } = 0;
public int IdxPODL { get; set; } = 0;
[Parameter]
public string RecipePath { get; set; } = "";
[Inject]
protected MpDataService MDService { get; set; } = null!;
protected RecipeModel? CurrRecipe { get; set; } = null;
protected override async Task OnParametersSetAsync()
{
await Task.Delay(1);
if (IdxPODL != 0 && !string.IsNullOrEmpty(RecipePath))
{
RecipeModel CurrRecipe = new RecipeModel();
// effettua ricerca ricetta su MongoDb
CurrRecipe = await MDService.RecipeGetByPODL(IdxPODL);
// se non trova crea nuova...
if (CurrRecipe == null || string.IsNullOrEmpty(CurrRecipe.Id))
{
CurrRecipe = MDService.InitRecipe(IdxPODL, RecipePath);
}
}
}
}
}
+73
View File
@@ -2,6 +2,7 @@
using MP.Data.Conf;
using MP.Data.DatabaseModels;
using MP.Data.DTO;
using MP.Data.MgModels;
using Newtonsoft.Json;
using NLog;
using StackExchange.Redis;
@@ -40,6 +41,18 @@ namespace MP.SPEC.Data
dbController = new MP.Data.Controllers.MpSpecController(configuration);
_logger.LogInformation("DbController OK");
}
// conf mongo...
connStr = _configuration.GetConnectionString("MongoConnect");
if (string.IsNullOrEmpty(connStr))
{
_logger.LogError("MongoController: ConnString empty!");
}
else
{
mongoController = new MP.Data.Controllers.MpMongoController(configuration);
_logger.LogInformation("MongoController OK");
}
}
#endregion Public Constructors
@@ -47,6 +60,7 @@ namespace MP.SPEC.Data
#region Public Properties
public static MP.Data.Controllers.MpSpecController dbController { get; set; } = null!;
public static MP.Data.Controllers.MpMongoController mongoController { get; set; } = null!;
public MessagePipe BroadastMsgPipe { get; set; } = null!;
@@ -57,6 +71,56 @@ namespace MP.SPEC.Data
#endregion Public Properties
/// <summary>
/// Init ricetta
/// </summary>
/// <param name="idxPODL"></param>
/// <param name="confPath"></param>
/// <returns></returns>
public RecipeModel InitRecipe(int idxPODL, string confPath)
{
return mongoController.InitRecipe(idxPODL, confPath);
}
/// <summary>
/// Ricerca ricetta su MongoDB dato PODL
/// </summary>
/// <param name="idxPODL"></param>
/// <returns></returns>
public async Task<RecipeModel> RecipeGetByPODL(int idxPODL)
{
RecipeModel result = new RecipeModel();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string readType = "DB";
string currKey = $"{redisRecipeData}:{idxPODL}";
// cerco in redis dato valore sel macchina...
RedisValue rawData = redisDb.StringGet(currKey);
if (rawData.HasValue)
{
var rawResult = JsonConvert.DeserializeObject<RecipeModel>($"{rawData}");
if (rawResult != null)
{
result = rawResult;
}
readType = "REDIS";
}
else
{
result = await mongoController.RecipeGetByPODL(idxPODL);
// serializzo e salvo...
rawData = JsonConvert.SerializeObject(result);
redisDb.StringSet(currKey, rawData, getRandTOut(redisShortTimeCache));
}
if (result == null)
{
result = new RecipeModel();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"RecipeGetByPODL | Read from {readType}: {ts.TotalMilliseconds}ms");
return result;
}
#region Public Methods
/// <summary>
@@ -379,10 +443,14 @@ namespace MP.SPEC.Data
return await Task.FromResult(dbController.ConfigUpdate(updRec));
}
/// <summary>
/// Dispose del connettore ai dati
/// </summary>
public void Dispose()
{
// Clear database controller
dbController.Dispose();
mongoController.Dispose();
redisConn.Dispose();
}
@@ -1484,6 +1552,11 @@ namespace MP.SPEC.Data
private const string redisTipoArt = redisBaseAddrSpec + "Cache:TipoArt";
private const string redisVocabolario = redisBaseAddrSpec + "Cache:Vocabolario";
private const string redisXdlData = redisBaseAddrSpec + "Cache:XDL:";
private const string redisRecipeConf = redisBaseAddrSpec + "Cache:Recipe:Conf";
private const string redisRecipeData = redisBaseAddrSpec + "Cache:Recipe:Data";
private static IConfiguration _configuration = null!;
private static ILogger<MpDataService> _logger = null!;
+1 -1
View File
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>MP.SPEC</RootNamespace>
<Version>6.16.2302.717</Version>
<Version>6.16.2302.809</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MAPOSPEC </i>
<h4>Versione: 6.16.2302.717</h4>
<h4>Versione: 6.16.2302.809</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
6.16.2302.717
6.16.2302.809
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.16.2302.717</version>
<version>6.16.2302.809</version>
<url>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+2 -1
View File
@@ -11,7 +11,8 @@
"Mp.Data": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;",
"Mp.Inve": "Server=SQL2016DEV;Database=MoonPro_MAG; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;",
"Redis": "localhost:6379,DefaultDatabase=1,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false",
"RedisAdmin": "localhost:6379,DefaultDatabase=1,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true"
"RedisAdmin": "localhost:6379,DefaultDatabase=1,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true",
"MongoConnect": "mongodb://W2019-MONGODB:27017"
},
"ServerConf": {
"maxAge": "2000",