aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs
blob: 1d49a535a4d090378330071a175d3a064c5e7bb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Transport.Web;

namespace Tango.PPC.Common.Web
{
    public class CheckForUpdateResponse : WebResponseMessage
    {
        public bool IsUpdateAvailable { get; set; }
        public String Version { get; set; }
    }
}
#fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.Core.DI;
using Tango.FSE.BL;
using Tango.FSE.Common;
using Tango.FSE.Common.AutoComplete;

namespace Tango.FSE.UI.Dialogs
{
    /// <summary>
    /// Represents a machine USB connection view model.
    /// </summary>
    /// <seealso cref="Tango.FSE.UI.Dialogs.MachineConnectionBaseViewVM" />
    public class MachineConnectionUsbViewVM : MachineConnectionBaseViewVM
    {
        [TangoInject]
        protected FSEServicesContainer Services { get; set; }

        /// <summary>
        /// Gets or sets the machines completion source.
        /// </summary>
        public AutoCompleteSource<Machine> Machines { get; set; }

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

        /// <summary>
        /// Initializes a new instance of the <see cref="MachineConnectionUsbViewVM"/> class.
        /// </summary>
        public MachineConnectionUsbViewVM() : base()
        {
            TangoIOC.Default.Inject(this);
            Machines = new AutoCompleteSource<Machine>(AutoCompleteMachines);
        }

        /// <summary>
        /// Gets the machine serial number.
        /// </summary>
        /// <returns></returns>
        public override string GetMachineSerialNumber()
        {
            return SelectedMachine?.SerialNumber;
        }

        /// <summary>
        /// Determines whether this instance can invoke the OK command.
        /// </summary>
        /// <returns></returns>
        protected override bool CanOK()
        {
            return SelectedMachine != null;
        }

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

            try
            {
                if (Settings.LastVirtualizedMachineSerialNumber != null)
                {
                    var machine = await Services.MachinesService.GetMachine(Settings.LastVirtualizedMachineSerialNumber);

                    if (SelectedMachine == null)
                    {
                        SelectedMachine = machine;
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.Log(ex, "Error retrieving last virtualized machine.");
            }

            if (SelectedMachine == null)
            {
                this.SetFocus(() => SelectedMachine);
            }
        }

        /// <summary>
        /// Invokes the <see cref="E:Tango.SharedUI.DialogViewVM.Accepted" /> event.
        /// </summary>
        protected override void Accept()
        {
            Settings.LastVirtualizedMachineSerialNumber = SelectedMachine.SerialNumber;
            Settings.Save();

            base.Accept();
        }

        private List<Machine> AutoCompleteMachines(string key)
        {
            key = key ?? String.Empty;

            try
            {
                return Services.MachinesService.GetAllMachines().Result.Where(x => x.SerialNumber.ToLower().StartsWith(key)).Take(4).ToList();
            }
            catch (Exception ex)
            {
                LogManager.Log(ex, "Error on auto complete virtualized machine filter.");
                return new List<Machine>();
            }
        }
    }
}