aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Configuration.cs
blob: 4e7ec72bd43616df24a04d0e3da78c1c0f9fd998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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;

namespace Tango.BL.Entities
{
    public partial class Configuration
    {
        [NotMapped]
        [XmlIgnore]
        [JsonIgnore]
        public IEnumerable<IdsPack> NoneEmptyIdsPacks
        {
            get { return IdsPacks.Where(x => !x.IsEmpty); }
        }

        public IEnumerable<IdsPack> GetSupportedIdsPacks(Rml rml)
        {
            if (rml == null)
            {
                throw new NullReferenceException("The specified RML cannot be null.");
            }

            return NoneEmptyIdsPacks.Where(x => rml.LiquidTypesRmls.ToList().Exists(y => y.LiquidType.Guid == x.LiquidType.Guid)).OrderBy(x => x.PackIndex).ToList();
        }

        public override void DefferedDelete(ObservablesContext context)
        {
            IdsPacks.ToList().ForEach(x => x.DefferedDelete(context));
            base.DefferedDelete(context);
            IdsPacks.Clear();
        }

        public override void Delete(ObservablesContext context)
        {
            IdsPacks.ToList().ForEach(x => x.DefferedDelete(context));
            base.Delete(context);
            IdsPacks.Clear();
        }

        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);
            }

            return cloned;
        }

        public override List<string> GetIgnoreProperties()
        {
            return base.GetIgnoreProperties().Concat(new List<String>()
            {
                 nameof(this.ApplicationDisplayPanelVersion),
                 nameof(this.ApplicationFirmwareVersion),
                 nameof(this.ApplicationOsVersion),
                 nameof(this.EmbeddedFirmwareVersion),
                 nameof(this.Machines),
                 nameof(this.NoneEmptyIdsPacks),
                 nameof(this.HardwareVersion),
            }).ToList();
        }
    }
}