diff --git a/MP.Data/Conf/RecipeConfig.cs b/MP.Data/Conf/RecipeConfig.cs
index 0e19ea21..0e0a9e2a 100644
--- a/MP.Data/Conf/RecipeConfig.cs
+++ b/MP.Data/Conf/RecipeConfig.cs
@@ -8,6 +8,9 @@ namespace MP.Data.Conf
{
public class RecipeConfig
{
+ ///
+ /// File di configurazione template ricetta
+ ///
public string TemplateFile { get; set; } = "";
///
/// Configurazione ricetta x header
diff --git a/MP.Data/Controllers/MpMongoController.cs b/MP.Data/Controllers/MpMongoController.cs
new file mode 100644
index 00000000..785dec09
--- /dev/null
+++ b/MP.Data/Controllers/MpMongoController.cs
@@ -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;
+ }
+
+ ///
+ /// Ricerca ricetta su MongoDB dato PODL
+ ///
+ ///
+ ///
+ public async Task RecipeGetByPODL(int idxPODL)
+ {
+ await Task.Delay(1);
+ RecipeModel answ = new RecipeModel();
+ return answ;
+ }
+ public async Task RecipeSetByPODL(RecipeModel currRecord)
+ {
+ await Task.Delay(1);
+ bool answ = false;
+ return answ;
+ }
+
+ ///
+ /// Init ricetta dato PODL + conf
+ ///
+ ///
+ ///
+ 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(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}");
+ }
+
+ }
+}
diff --git a/MP.Data/MP.Data.csproj b/MP.Data/MP.Data.csproj
index 806b55f7..38c11edc 100644
--- a/MP.Data/MP.Data.csproj
+++ b/MP.Data/MP.Data.csproj
@@ -26,6 +26,7 @@
+
\ No newline at end of file
diff --git a/MP.Data/MgModels/RecipeModel.cs b/MP.Data/MgModels/RecipeModel.cs
index 63f53ab1..0595e5fb 100644
--- a/MP.Data/MgModels/RecipeModel.cs
+++ b/MP.Data/MgModels/RecipeModel.cs
@@ -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; } = "";
}
}
diff --git a/MP.SPEC/Components/ListPODL.razor b/MP.SPEC/Components/ListPODL.razor
index eaf09467..ada1a2d1 100644
--- a/MP.SPEC/Components/ListPODL.razor
+++ b/MP.SPEC/Components/ListPODL.razor
@@ -149,7 +149,7 @@ else
@if (showRecipe && currRecord != null)
{
-
+
}
diff --git a/MP.SPEC/Components/ListPODL.razor.cs b/MP.SPEC/Components/ListPODL.razor.cs
index 1bb09f32..80719ed0 100644
--- a/MP.SPEC/Components/ListPODL.razor.cs
+++ b/MP.SPEC/Components/ListPODL.razor.cs
@@ -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();
+ ///
+ /// Percorso ricetta corrente
+ ///
+ private string currRecipePath = "";
+
private PODLExpModel? currRecord = null;
private List? ListRecords;
@@ -421,7 +428,7 @@ namespace MP.SPEC.Components
///
private async Task machineHasRecipe(string idxMacchina)
{
- string recipePath = await MDService.MacchineRecipe(idxMacchina);
+ var recipePath = await MDService.MacchineRecipe(idxMacchina);
return !string.IsNullOrEmpty(recipePath);
}
diff --git a/MP.SPEC/Components/RecipeMan.razor b/MP.SPEC/Components/RecipeMan.razor
index 53c84bc8..c472bdbf 100644
--- a/MP.SPEC/Components/RecipeMan.razor
+++ b/MP.SPEC/Components/RecipeMan.razor
@@ -1,2 +1,11 @@
RecipeMan
+
+@if(CurrRecipe==null)
+{
+
+}
+else
+{
+ dati ricetta
+}
diff --git a/MP.SPEC/Components/RecipeMan.razor.cs b/MP.SPEC/Components/RecipeMan.razor.cs
index a16156d4..928517b5 100644
--- a/MP.SPEC/Components/RecipeMan.razor.cs
+++ b/MP.SPEC/Components/RecipeMan.razor.cs
@@ -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);
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs
index c583d9c8..f52df1b3 100644
--- a/MP.SPEC/Data/MpDataService.cs
+++ b/MP.SPEC/Data/MpDataService.cs
@@ -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
+ ///
+ /// Init ricetta
+ ///
+ ///
+ ///
+ ///
+ public RecipeModel InitRecipe(int idxPODL, string confPath)
+ {
+ return mongoController.InitRecipe(idxPODL, confPath);
+ }
+ ///
+ /// Ricerca ricetta su MongoDB dato PODL
+ ///
+ ///
+ ///
+ public async Task 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($"{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
///
@@ -379,10 +443,14 @@ namespace MP.SPEC.Data
return await Task.FromResult(dbController.ConfigUpdate(updRec));
}
+ ///
+ /// Dispose del connettore ai dati
+ ///
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 _logger = null!;
diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj
index ddbbd88b..6ba24e47 100644
--- a/MP.SPEC/MP.SPEC.csproj
+++ b/MP.SPEC/MP.SPEC.csproj
@@ -5,7 +5,7 @@
enable
enable
MP.SPEC
- 6.16.2302.717
+ 6.16.2302.809
diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html
index bb9f2529..37087c9c 100644
--- a/MP.SPEC/Resources/ChangeLog.html
+++ b/MP.SPEC/Resources/ChangeLog.html
@@ -1,6 +1,6 @@
Modulo MAPOSPEC
- Versione: 6.16.2302.717
+ Versione: 6.16.2302.809
Note di rilascio:
-
diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt
index 47dea22b..860c0968 100644
--- a/MP.SPEC/Resources/VersNum.txt
+++ b/MP.SPEC/Resources/VersNum.txt
@@ -1 +1 @@
-6.16.2302.717
+6.16.2302.809
diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml
index ee6a7450..6a63bc72 100644
--- a/MP.SPEC/Resources/manifest.xml
+++ b/MP.SPEC/Resources/manifest.xml
@@ -1,6 +1,6 @@
-
- 6.16.2302.717
+ 6.16.2302.809
https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip
https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html
false
diff --git a/MP.SPEC/appsettings.json b/MP.SPEC/appsettings.json
index 0bf7e81d..9c178563 100644
--- a/MP.SPEC/appsettings.json
+++ b/MP.SPEC/appsettings.json
@@ -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",