770420ee37
- fig gestione dati <-> Mongo - fix grafico
176 lines
5.7 KiB
C#
176 lines
5.7 KiB
C#
using MongoDB.Bson.Serialization.Attributes;
|
|
using MongoDB.Bson;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
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
|
|
{
|
|
[BsonId]
|
|
[BsonRepresentation(BsonType.ObjectId)]
|
|
public string? Id { get; set; }
|
|
|
|
/// <summary>
|
|
/// Idx PODL di riferimento
|
|
/// </summary>
|
|
public int IdxPODL { get; set; } = 0;
|
|
/// <summary>
|
|
/// idx ODL di riferimento
|
|
/// </summary>
|
|
public int IdxODL { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// File di configurazione template ricetta
|
|
/// </summary>
|
|
public string TemplateFile { get; set; } = "";
|
|
/// <summary>
|
|
/// Configurazione ricetta x header
|
|
/// </summary>
|
|
public RecipeBlockConfig HeadConf { get; set; } = new RecipeBlockConfig();
|
|
/// <summary>
|
|
/// Configurazione ricetta x rows
|
|
/// </summary>
|
|
public RecipeBlockConfig RowsConf { get; set; } = new RecipeBlockConfig();
|
|
|
|
/// <summary>
|
|
/// Lista element x testata ricetta
|
|
/// </summary>
|
|
public List<Element> HeadVal { get; set; } = new List<Element>();
|
|
|
|
/// <summary>
|
|
/// Dizionario di righe, ognuna come Lista element
|
|
/// </summary>
|
|
public Dictionary<string, List<Element>> RowsVal { get; set; } = new Dictionary<string, List<Element>>();
|
|
|
|
/// <summary>
|
|
/// Init vuoto
|
|
/// </summary>
|
|
public RecipeModel()
|
|
{ }
|
|
|
|
/// <summary>
|
|
/// Init da configurazione di base
|
|
/// </summary>
|
|
/// <param name="origConfig"></param>
|
|
public RecipeModel(int IdxPODL, RecipeConfig origConfig)
|
|
{
|
|
this.IdxPODL = IdxPODL;
|
|
this.TemplateFile = origConfig.TemplateFile;
|
|
this.HeadConf = origConfig.HeadConf;
|
|
this.RowsConf = origConfig.RowsConf;
|
|
// init oggetti tipizzati da valori conf ricevuti
|
|
this.HeadVal = ElementConverter(origConfig.HeadConf.ListKeys);
|
|
// aggiungo righe elementi..
|
|
for (int i = 1; i <= origConfig.NumRow; i++)
|
|
{
|
|
this.RowsVal.Add($"{i}", ElementConverter(origConfig.RowsConf.ListKeys));
|
|
}
|
|
}
|
|
|
|
public static Element getToConfig(string rawKey, string rawVal)
|
|
{
|
|
return new Element(rawKey, rawVal);
|
|
}
|
|
/// <summary>
|
|
/// Converte il dizionario in List Element
|
|
/// </summary>
|
|
public static List<Element> ElementConverter(Dictionary<string, string> ListKeys)
|
|
{
|
|
List<Element> ListObj = ListKeys
|
|
.Select(x => new Element(x.Key, x.Value))
|
|
.ToList();
|
|
return ListObj;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricetta in formato calcolato (string)
|
|
/// </summary>
|
|
public string CalcRecipe { get; set; } = "";
|
|
|
|
///// <summary>
|
|
///// Inizializza la ListObj da ListKeys
|
|
///// </summary>
|
|
//public static Dictionary<string, Element> ConvertToObj(Dictionary<string,string> ListKeys)
|
|
//{
|
|
// Dictionary<string, Element> ListObj = ListKeys.ToDictionary(x => x.Key, x => new Element(x.Value));
|
|
// return ListObj;
|
|
//}
|
|
|
|
/// <summary>
|
|
/// Elemento unitario con cui costruire la ricetta
|
|
/// </summary>
|
|
public class Element
|
|
{
|
|
/// <summary>
|
|
/// Init classe da valore kvp
|
|
/// </summary>
|
|
/// <param name="rawKey"></param>
|
|
/// <param name="rawVal"></param>
|
|
public Element(string rawKey, string rawVal)
|
|
{
|
|
this.Key = rawKey;
|
|
this.OrigVal = rawVal;
|
|
this.Value = rawVal;
|
|
// cerco se ho uno dei 3 caratteri (C/E/F):
|
|
if (rawVal.Length >= 2 && rawVal.Substring(1, 1) == ":")
|
|
{
|
|
string selTipo = rawVal.Substring(0, 2);
|
|
switch (selTipo)
|
|
{
|
|
case "C:":
|
|
this.Type = KeyType.Calc;
|
|
this.Value = rawVal.Substring(2);
|
|
break;
|
|
case "E:":
|
|
this.Type = KeyType.Enum;
|
|
this.Value = "";
|
|
this.EnumType = rawVal.Substring(2);
|
|
break;
|
|
case "F:":
|
|
this.Type = KeyType.Fixed;
|
|
this.Value = rawVal.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 Key { get; set; } = "";
|
|
[NotMapped]
|
|
public string Value { get; set; } = "";
|
|
[NotMapped]
|
|
public string EnumType { get; set; } = "";
|
|
public string OrigVal { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Tipi di valore ammessi
|
|
/// </summary>
|
|
public enum KeyType
|
|
{
|
|
None = 0,
|
|
Calc,
|
|
Enum,
|
|
Fixed,
|
|
Free
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|