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; ///// ///// Dizionario chiavi/valori campi header ///// //public Dictionary HeadVal { get; set; } = new Dictionary(); ///// ///// Elenco righe ricetta (ogni riga dizionario chiavi/valori) ///// //public Dictionary> RowsVal { get; set; } = new Dictionary>(); /// /// Dizionario chiavi/valori estesi campi header /// public Dictionary HeadVal { get; set; } = new Dictionary(); /// /// Elenco righe ricetta (ogni riga dizionario chiavi/valori) /// public Dictionary> RowsVal { get; set; } = new Dictionary>(); /// /// Inizializza la ListObj da ListKeys /// public static Dictionary ConvertToObj(Dictionary ListKeys) { Dictionary ListObj = ListKeys.ToDictionary(x => x.Key, x => new KeyConfig(x.Value)); return ListObj; } public class KeyConfig { /// /// Init classe da valore raw /// /// 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; } = ""; } }