aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs
blob: 24988ab4c0ee915143adb26b0efe2aaa0afc12d0 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Integration.Observables
{
    public partial class Machine
    {
        /// <summary>
        /// Deletes this entity from the database
        /// </summary>
        public override void Delete()
        {
            foreach (var machine_config in MachinesConfigurations)
            {
                machine_config.Delete();
                machine_config.Configuration.Delete();
            }

            base.Delete();
        }

        public override void Save()
        {
            foreach (var brushStop in Jobs.SelectMany(x => x.Segments).SelectMany(x => x.BrushStops))
            {
                foreach (var prop in typeof(BrushStop).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType == typeof(double)))
                {
                    double value = (double)prop.GetValue(brushStop);

                    if (double.IsInfinity(value))
                    {
                        prop.SetValue(brushStop, 0d);
                    }
                }
            }

            base.Save();
        }
    }
}