aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs
blob: b8b888e86b6aa8a74a29b1f84fe38291c7c39300 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
using Tango.Integration.Services;
using Tango.MachineStudio.Common.Notifications;
using Tango.SharedUI;

namespace Tango.MachineStudio.UI.ViewModels
{
    public class MachineConnectionViewVM : DialogViewVM
    {
        private ExternalBridgeScanner _scanner;

        public ExternalBridgeScanner Scanner
        {
            get { return _scanner; }
            set { _scanner = value; RaisePropertyChangedAuto(); }
        }

        private IExternalBridgeClient _selectedMachine;

        public IExternalBridgeClient SelectedMachine
        {
            get { return _selectedMachine; }
            set { _selectedMachine = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
        }

        public RelayCommand ConnectCommand { get; set; }

        public MachineConnectionViewVM(ExternalBridgeScanner scanner)
        {
            Scanner = scanner;
            ConnectCommand = new RelayCommand(Connect,(x) => SelectedMachine != null);
            Scanner.Start();
        }

        private void Connect()
        {
            if (SelectedMachine != null)
            {
                Accept();
            }
        }

        public override void OnShow()
        {
            base.OnShow();

            Scanner.AvailableMachines.Clear();
        }
    }
}