using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Serialization; using Tango.BL.Serialization; using Tango.BL.ValueObjects; namespace Tango.BL.Entities { public partial class Configuration : ConfigurationBase { /// /// Gets a collection of this configuration IDS packs where is 'true'. /// [NotMapped] [XmlIgnore] [JsonIgnore] public IEnumerable NoneEmptyIdsPacks { get { return IdsPacks.Where(x => !x.IsEmpty); } } [NotMapped] [XmlIgnore] [JsonIgnore] public List IdsPacksOrderedByPackIndex { get { return IdsPacks.OrderBy(x => x.PackIndex).ToList(); } } public IdsPack GetIdsPackByColorMatch(String name) { return NoneEmptyIdsPacks.Where(x => x.LiquidType.AvailableForStandardUser).FirstOrDefault(x => x.LiquidType.Type.ToString().ToLower().Contains(name.ToLower())); } /// /// Gets a collection of this configuration IDS packs where packs are not 'empty' and are supported by the specified . /// /// The RML. /// /// The specified RML cannot be null. public IEnumerable GetSupportedIdsPacks(Rml rml) { if (rml == null) { throw new NullReferenceException("The specified RML cannot be null."); } //return NoneEmptyIdsPacks.Where(x => rml.LiquidTypesRmls.ToList().Exists(y => x.LiquidType != null && y.LiquidType.Guid == x.LiquidType.Guid)).OrderBy(x => x.PackIndex).ToList(); return NoneEmptyIdsPacks.OrderBy(x => x.PackIndex).ToList(); } /// /// Clones configuration and its IDS packs (excluding the dispenser). /// /// public override Configuration Clone() { Configuration cloned = base.Clone(); foreach (var idsPack in this.IdsPacks) { IdsPack clonedPack = idsPack.Clone(); clonedPack.Configuration = cloned; clonedPack.CartridgeType = idsPack.CartridgeType; clonedPack.MidTankType = idsPack.MidTankType; clonedPack.IdsPackFormula = idsPack.IdsPackFormula; clonedPack.IsEmpty = idsPack.IsEmpty; clonedPack.Dispenser = null; clonedPack.DispenserGuid = null; cloned.IdsPacks.Add(clonedPack); } cloned.HardwareConfigurationString = HardwareConfigurationString; return cloned; } /// /// Removes this entity and all dependent entities from the specified db context. /// /// The context. public override void Delete(ObservablesContext context) { base.Delete(context); context.IdsPacks.RemoveRange(IdsPacks); context.Configurations.Remove(this); } public HardwareConfiguration GetHardwareConfiguration() { return HardwareConfiguration.FromJson(HardwareConfigurationString); } public void SetHardwareConfiguration(HardwareConfiguration hwConfig) { HardwareConfigurationString = hwConfig.ToJson(); } /// /// Initializes a new instance of the class. /// public Configuration() : base() { } } }