dde39d52dd
- OK salvataggio ricetta in MongoDB
116 lines
3.8 KiB
C#
116 lines
3.8 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 : RecipeConfig
|
|
{
|
|
[BsonId]
|
|
[BsonRepresentation(BsonType.ObjectId)]
|
|
public string? Id { get; set; }
|
|
|
|
public int IdxPODL { get; set; } = 0;
|
|
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 estesi campi header
|
|
/// </summary>
|
|
public Dictionary<string, KeyConfig> HeadVal { get; set; } = new Dictionary<string, KeyConfig>();
|
|
|
|
/// <summary>
|
|
/// Elenco righe ricetta (ogni riga dizionario chiavi/valori)
|
|
/// </summary>
|
|
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; } = "";
|
|
|
|
}
|
|
}
|