SPEC:
- OK salvataggio ricetta in MongoDB
This commit is contained in:
@@ -13,13 +13,14 @@ namespace MP.Data.Conf
|
||||
{
|
||||
/// <summary>
|
||||
/// Dizionario delle chiavi, differenziate dai primi caratteri:
|
||||
/// [C] --> Calcolato
|
||||
/// [F] --> Fixed (NON modificabile)
|
||||
/// [E] --> Enum: modificabile ma da dizionario valori seguente
|
||||
/// C: --> Calcolato
|
||||
/// E: --> Enum: modificabile ma da dizionario valori seguente
|
||||
/// F: --> Fixed (NON modificabile)
|
||||
/// "" --> editabile
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ListKeys { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario degli enum permessi
|
||||
/// </summary>
|
||||
@@ -31,9 +32,9 @@ namespace MP.Data.Conf
|
||||
|
||||
public class CalcDetail
|
||||
{
|
||||
public string Description { get; set; } = null!;
|
||||
public string Type { get; set; } = null!;
|
||||
public string Format { get; set; } = null!;
|
||||
public string Description { get; set; } = "";
|
||||
public string Type { get; set; } = "";
|
||||
public string Format { get; set; } = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using MP.Data.MgModels;
|
||||
using System.IO;
|
||||
using MP.Data.Conf;
|
||||
using Newtonsoft.Json;
|
||||
using static MP.Data.MgModels.RecipeModel;
|
||||
|
||||
namespace MP.Data.Controllers
|
||||
{
|
||||
@@ -23,8 +24,13 @@ namespace MP.Data.Controllers
|
||||
_configuration = configuration;
|
||||
string mongoConf = _configuration.GetConnectionString("MongoConnect");
|
||||
client = new MongoClient(mongoConf);
|
||||
mongoDb = client.GetDatabase("MAPO");
|
||||
Log.Info("Avviata classe MpMongoController");
|
||||
}
|
||||
/// <summary>
|
||||
/// Database corrente MongoDB
|
||||
/// </summary>
|
||||
private IMongoDatabase mongoDb;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -41,12 +47,45 @@ namespace MP.Data.Controllers
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RecipeModel answ = new RecipeModel();
|
||||
try
|
||||
{
|
||||
// definisco filtro
|
||||
var filtBuilder = Builders<RecipeModel>.Filter;
|
||||
var filter = filtBuilder.Eq<int>("IdxPODL", idxPODL);
|
||||
var collectionData = mongoDb.GetCollection<RecipeModel>("RecipeArchive");
|
||||
// recupero
|
||||
answ = collectionData.Find(filter).Project<RecipeModel>("{_id: 0}").FirstOrDefault<RecipeModel>();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Salva ricetta su MongoDB
|
||||
/// </summary>
|
||||
/// <param name="currRecord"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RecipeSetByPODL(RecipeModel currRecord)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
// definisco filtro
|
||||
var filtBuilder = Builders<RecipeModel>.Filter;
|
||||
var filter = filtBuilder.Eq<int>("IdxPODL", currRecord.IdxPODL);
|
||||
var collectionData = mongoDb.GetCollection<RecipeModel>("RecipeArchive");
|
||||
// elimino old
|
||||
collectionData.DeleteMany(filter);
|
||||
// aggiungo
|
||||
collectionData.InsertOne(currRecord);
|
||||
answ = true;
|
||||
}
|
||||
catch(Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in RecipeSetByPODL{Environment.NewLine}{exc}");
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -65,6 +104,8 @@ namespace MP.Data.Controllers
|
||||
{
|
||||
string rawData = File.ReadAllText(fullPath);
|
||||
var currRecipe = JsonConvert.DeserializeObject<RecipeConfig>(rawData);
|
||||
//// calcolo obj riga base (ne aggiungo1...)
|
||||
//var rigaBase = RecipeModel.ConvertToObj(currRecipe.RowsConf.ListKeys);
|
||||
// copio la mia ricetta come conf...
|
||||
answ = new RecipeModel()
|
||||
{
|
||||
@@ -72,14 +113,16 @@ namespace MP.Data.Controllers
|
||||
TemplateFile = currRecipe.TemplateFile,
|
||||
HeadConf = currRecipe.HeadConf,
|
||||
RowsConf = currRecipe.RowsConf,
|
||||
HeadVal = currRecipe.HeadConf.ListKeys,
|
||||
//HeadVal = currRecipe.HeadConf.ListKeys,
|
||||
HeadVal = RecipeModel.ConvertToObj(currRecipe.HeadConf.ListKeys),
|
||||
// aggiungo 1 riga...
|
||||
RowsVal = new Dictionary<int, Dictionary<string, string>>()
|
||||
RowsVal = new Dictionary<string, Dictionary<string, KeyConfig>>()
|
||||
{
|
||||
{ 1, currRecipe.RowsConf.ListKeys}
|
||||
//{ "1", rigaBase }
|
||||
{ "1", RecipeModel.ConvertToObj(currRecipe.RowsConf.ListKeys)}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
return answ;
|
||||
|
||||
@@ -6,9 +6,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MP.Data.Conf;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace MP.Data.MgModels
|
||||
{
|
||||
[BsonIgnoreExtraElements]
|
||||
public class RecipeModel : RecipeConfig
|
||||
{
|
||||
[BsonId]
|
||||
@@ -19,15 +21,93 @@ namespace MP.Data.MgModels
|
||||
public int IdxODL { get; set; } = 0;
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// Dizionario chiavi/valori campi header
|
||||
///// </summary>
|
||||
//public Dictionary<string, string> HeadVal { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
///// <summary>
|
||||
///// Elenco righe ricetta (ogni riga dizionario chiavi/valori)
|
||||
///// </summary>
|
||||
//public Dictionary<int, Dictionary<string, string>> RowsVal { get; set; } = new Dictionary<int, Dictionary<string, string>>();
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario chiavi/valori campi header
|
||||
/// Dizionario chiavi/valori estesi campi header
|
||||
/// </summary>
|
||||
public Dictionary<string, string> HeadVal { get; set; } = new Dictionary<string, string>();
|
||||
public Dictionary<string, KeyConfig> HeadVal { get; set; } = new Dictionary<string, KeyConfig>();
|
||||
|
||||
/// <summary>
|
||||
/// Elenco righe ricetta (ogni riga dizionario chiavi/valori)
|
||||
/// </summary>
|
||||
public Dictionary<int, Dictionary<string, string>> RowsVal { get; set; } = new Dictionary<int, Dictionary<string, string>>();
|
||||
public Dictionary<string, Dictionary<string, KeyConfig>> RowsVal { get; set; } = new Dictionary<string, Dictionary<string, KeyConfig>>();
|
||||
|
||||
/// <summary>
|
||||
/// Inizializza la ListObj da ListKeys
|
||||
/// </summary>
|
||||
public static Dictionary<string, KeyConfig> ConvertToObj(Dictionary<string,string> ListKeys)
|
||||
{
|
||||
Dictionary<string, KeyConfig> ListObj = ListKeys.ToDictionary(x => x.Key, x => new KeyConfig(x.Value));
|
||||
return ListObj;
|
||||
}
|
||||
|
||||
public class KeyConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Init classe da valore raw
|
||||
/// </summary>
|
||||
/// <param name="rawValue"></param>
|
||||
public KeyConfig(string rawValue)
|
||||
{
|
||||
this.OrigVal = rawValue;
|
||||
this.Value = rawValue;
|
||||
// cerco se ho uno dei 3 caratteri (C/E/F):
|
||||
if (rawValue.Length >= 2 && rawValue.Substring(1, 1) == ":")
|
||||
{
|
||||
string selTipo = rawValue.Substring(0, 2);
|
||||
switch (selTipo)
|
||||
{
|
||||
case "C:":
|
||||
this.Type = KeyType.Calc;
|
||||
this.Value = rawValue.Substring(2);
|
||||
break;
|
||||
case "E:":
|
||||
this.Type = KeyType.Enum;
|
||||
this.Value = "";
|
||||
this.EnumType = rawValue.Substring(2);
|
||||
break;
|
||||
case "F:":
|
||||
this.Type = KeyType.Fixed;
|
||||
this.Value = rawValue.Substring(2);
|
||||
break;
|
||||
default:
|
||||
this.Type = KeyType.None;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Type = KeyType.Free;
|
||||
}
|
||||
}
|
||||
[NotMapped]
|
||||
public KeyType Type { get; set; } = KeyType.None;
|
||||
[NotMapped]
|
||||
public string Value { get; set; } = "";
|
||||
[NotMapped]
|
||||
public string EnumType { get; set; } = "";
|
||||
public string OrigVal { get; set; } = "";
|
||||
}
|
||||
|
||||
public enum KeyType
|
||||
{
|
||||
None = 0,
|
||||
Calc,
|
||||
Enum,
|
||||
Fixed,
|
||||
Free
|
||||
}
|
||||
|
||||
public string RawRecipe { get; set; } = "";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user