aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/MachineConnectionIcon.cs
blob: d739ac6e56071f1e46ac786c8debc4eb127e1c4e (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
81
82
83
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.BL.Enumerations;
using Tango.Emulations.ExternalBridge;
using Tango.FSE.Common.Connection;
using Tango.Integration.ExternalBridge;

namespace Tango.FSE.Common.Controls
{
    public class MachineConnectionIcon : Control
    {
        public MachineTypes MachineType
        {
            get { return (MachineTypes)GetValue(MachineTypeProperty); }
            set { SetValue(MachineTypeProperty, value); }
        }
        public static readonly DependencyProperty MachineTypeProperty =
            DependencyProperty.Register("MachineType", typeof(MachineTypes), typeof(MachineConnectionIcon), new PropertyMetadata(MachineTypes.TS1800));

        public IExternalBridgeClient ExternalBridgeClient
        {
            get { return (IExternalBridgeClient)GetValue(ExternalBridgeClientProperty); }
            set { SetValue(ExternalBridgeClientProperty, value); }
        }
        public static readonly DependencyProperty ExternalBridgeClientProperty =
            DependencyProperty.Register("ExternalBridgeClient", typeof(IExternalBridgeClient), typeof(MachineConnectionIcon), new PropertyMetadata((d, e) => (d as MachineConnectionIcon).OnExternalBridgeClientChanged()));

        public MachineConnectionTypes ExternalBridgeClientType
        {
            get { return (MachineConnectionTypes)GetValue(ExternalBridgeClientTypeProperty); }
            set { SetValue(ExternalBridgeClientTypeProperty, value); }
        }
        public static readonly DependencyProperty ExternalBridgeClientTypeProperty =
            DependencyProperty.Register("ExternalBridgeClientType", typeof(MachineConnectionTypes), typeof(MachineConnectionIcon), new PropertyMetadata(MachineConnectionTypes.USB));

        private void OnExternalBridgeClientChanged()
        {
            if (ExternalBridgeClient != null)
            {
                if (ExternalBridgeClient.GetType() == typeof(ExternalBridgeUsbClient))
                {
                    ExternalBridgeClientType = MachineConnectionTypes.USB;
                }
                else if (ExternalBridgeClient.GetType() == typeof(ExternalBridgeTcpFirmwareClient))
                {
                    ExternalBridgeClientType = MachineConnectionTypes.TCP;
                    MachineType = MachineTypes.Eureka;
                }
                else if (ExternalBridgeClient.GetType() == typeof(ExternalBridgeTcpClient))
                {
                    ExternalBridgeClientType = MachineConnectionTypes.Wifi;
                    MachineType = ExternalBridgeClient.MachineType;
                }
                else if (ExternalBridgeClient.GetType() == typeof(ExternalBridgeSignalRClient))
                {
                    ExternalBridgeClientType = MachineConnectionTypes.SignalR;
                    MachineType = ExternalBridgeClient.MachineType;
                }
                else if (ExternalBridgeClient.GetType() == typeof(EmulatorExternalBridge))
                {
                    ExternalBridgeClientType = MachineConnectionTypes.Emulator;
                }
            }
        }

        static MachineConnectionIcon()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MachineConnectionIcon), new FrameworkPropertyMetadata(typeof(MachineConnectionIcon)));
        }
    }
}