aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/WasteReplacementViewVM.cs
blob: 0e2f4bb567de3c77730ae49471bbc888cde7b3ad (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.Core.DI;
using Tango.PMR.Diagnostics;
using Tango.PPC.Common.Connection;
using Tango.SharedUI;

namespace Tango.PPC.UI.Dialogs
{
    public class WasteReplacementViewVM : DialogViewVM
    {
        private bool _doorClosed;
        private bool _doorOpened;

        [TangoInject]
        private IMachineProvider MachineProvider { get; set; }

        public WasteReplacementViewVM()
        {
            TangoIOC.Default.Inject(this);
            MachineProvider.MachineOperator.EventsNotification += MachineOperator_EventsNotification;
        }

        private void MachineOperator_EventsNotification(object sender, StartEventsNotificationResponse e)
        {
            if (!_doorOpened)
            {
                if (e.Events.Select(x => x.Type).Contains(PMR.Diagnostics.EventType.CartridgesCoverOpen))
                {
                    _doorOpened = true;
                }
            }
            else
            {
                if (!e.Events.Select(x => x.Type).Contains(PMR.Diagnostics.EventType.CartridgesCoverOpen))
                {
                    _doorClosed = true;
                    InvalidateRelayCommands();
                }
            }
        }

        protected override void Accept()
        {
            DisposeEvents();
            base.Accept();
        }

        protected override void Cancel()
        {
            DisposeEvents();
            base.Cancel();
        }

        protected override bool CanOK()
        {
            return base.CanOK() && _doorClosed && _doorOpened;
        }

        private void DisposeEvents()
        {
            MachineProvider.MachineOperator.EventsNotification -= MachineOperator_EventsNotification;
        }
    }
}