aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.IDE/Notifications/ProgressNotificationHandler.cs
blob: b364194008d5b93070b6a8fc9211afe4a01664e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
{
    /// <summary>
    /// Represents the Machine Studio connection dialog, view model.
    /// </summary>
    /// <seealso cref="Tango.MachineStudio.Common.Notifications.DialogViewVM" />
    public class MachineConnectionViewVM : DialogViewVM
    {
        private ExternalBridgeScanner _scanner;
        /// <summary>
        /// Gets or sets the machine scanner.
        /// </summary>
        public ExternalBridgeScanner Scanner
        {
            get { return _scanner; }
            set { _scanner = value; RaisePropertyChangedAuto(); }
        }

        private IExternalBridgeClient _selectedMachine;
        /// <summary>
        /// Gets or sets the selected machine.
        /// </summary>
        public IExternalBridgeClient SelectedMachine
        {
            get { return _selectedMachine; }
            set { _selectedMachine = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
        }

        /// <summary>
        /// Gets or sets the connect command.
        /// </summary>
        public RelayCommand ConnectCommand { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="MachineConnectionViewVM"/> class.
        /// </summary>
        /// <param name="scanner">The scanner.</param>
        public MachineConnectionViewVM(ExternalBridgeScanner scanner)
        {
            Scanner = scanner;
            ConnectCommand = new RelayCommand(Connect,(x) => SelectedMachine != null);
            Scanner.Start();
        }

        /// <summary>
        /// Connect to the currently selected machine.
        /// </summary>
        private void Connect()
        {
            if (SelectedMachine != null)
            {
                Accept();
            }
        }

        /// <summary>
        /// Called when the dialog has been shown.
        /// </summary>
        public override void OnShow()
        {
            base.OnShow();
            Scanner.AvailableMachines.Clear();
        }
    }
}