using System; using System.CodeDom; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading; using System.Windows; using System.Windows.Media; using Aitex.Core.Account; using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.SCCore; using Aitex.Core.UI.MVVM; using System.Windows.Input; using Aitex.Core.Util; using Aitex.Triton160.Common; using Aitex.Triton160.UI; using Aitex.Triton160.UI.Config; using Aitex.Triton160.UI.ViewModel; using Aitex.Triton160.UI.Views; namespace Triton160.UI.ViewModel { class TopViewModel : UIViewModelBase { public string SoftwareVersion { get; set; } [Subscription(TritonDevice.EmoSystem, SystemDeviceModule)] public AITEmoData EmoState { get; set; } [Subscription(StateData.PMState, SystemStateModule)] public int PMState { get; set; } [Subscription(TritonDevice.SignalTower, SystemDeviceModule)] public AITSignalTowerData SignalTower { get; set; } public string SystemStatus { get { PMState status = (PMState)PMState; return status.ToString(); } } private bool _simulatorMode = false; public string TopViewBackground { get { return _simulatorMode ? "Goldenrod" : "Transparent"; } } public SolidColorBrush MainContactorColor { get { return EmoState != null && EmoState.MainContactorSignal ? Brushes.Lime : Brushes.Gray; } } public SolidColorBrush EmoStopColor { get { return EmoState != null && EmoState.StopButtonSignal ? Brushes.Lime : Brushes.Gray; } } public string User { get { return Globals.Session["CurrentUser"] == null ? "" : (Globals.Session["CurrentUser"] as Account).AccountId; } } public string Role { get { return Globals.Session["CurrentUser"] == null ? "" : (Globals.Session["CurrentUser"] as Account).Role; } } public int _language; //public string LanguageButtonDisplay //{ // get // { // //显示的文字,和实际的语言相反,用于切换 // return _language == 1 ? "中文" : "EN"; // } //} public bool EnableEnButton { get { return _language != 1; } } public bool EnableCnButton { get { return _language != 2; } } public string LogoSource { get { string file = SystemConfigManager.Instance.GetTopviewLogoFile(); if (string.IsNullOrEmpty(file)) file = "LogoEmpty.png"; return "/Core;component/Resources/Main/" + file; } } public ICommand SwitchOffBuzzerCommand { get; private set; } public ICommand SwitchLanguageCommand { get; private set; } public FACommunicationState FACommunicationState { get { return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus); } } public FAControlState FAControlState { get { return string.IsNullOrEmpty(HostControlStatus) ? FAControlState.Unknown : (FAControlState)Enum.Parse(typeof(FAControlState), HostControlStatus); } } //Disabled, //Enabled, //EnabledNotCommunicating, //EnabledCommunicating, //WaitCRA, //WaitDelay, //WaitCRFromHost, public bool IsEnableEnableButton { get { return FACommunicationState == FACommunicationState.Disabled; } } [Subscription("System.ControlStatus")] public string HostControlStatus { get; set; } [Subscription("System.CommunicationStatus")] public string HostCommunicationStatus { get; set; } public string HostControlStatusBackground { get { if (FACommunicationState == FACommunicationState.Disabled) return "Transparent"; if (FACommunicationState != FACommunicationState.EnabledCommunicating) return "Transparent"; switch (FAControlState) { case FAControlState.OnlineLocal: case FAControlState.OnlineRemote: return "Green"; case FAControlState.HostOffline: //case FAControlState.AttemptOnline: case FAControlState.EquipmentOffline: case FAControlState.Unknown: return "Transparent"; } return "Orange"; } } public string HostStatusBackground { get { switch (FACommunicationState) { case FACommunicationState.EnabledCommunicating: return "Green"; case FACommunicationState.Disabled: return "Transparent"; } return "Orange"; } } private bool _isFaEnable; public Visibility VisibleHostStatus { get { return _isFaEnable ? Visibility.Visible : Visibility.Hidden; } } public string SystemStatusBackground { get { return GetUnitStatusBackground(SystemStatus); } } public string GetUnitStatusBackground(string status) { if (status != null) status = status.Trim().ToLower(); switch (status) { case "error": return "red"; case "idle": return "Transparent"; case "init": return "Orange"; default: return "Green"; } } public TopViewModel() : base("TopViewModel") { SwitchOffBuzzerCommand = new DelegateCommand(OnSwitchOffBuzzer); SwitchLanguageCommand = new DelegateCommand(OnSwitchOffLanguage); SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); InvokePropertyChanged("SoftwareVersion"); } public void Reset() { Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.Reset.ToString()); } void OnSwitchOffBuzzer(object param) { Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.DeviceOperation.ToString(), new object[] { TritonDevice.SignalTower.ToString(), AITSignalTowerOperation.SwitchOffBuzzer.ToString() }); Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.BuzzerOFF.ToString()); } void OnSwitchOffLanguage(object param) { int language = param.ToString().ToLower() == "en" ? 1 : 2; Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.SetConfig.ToString(), SCName.System_Language, language); } protected override void InvokeBeforeUpdateProperty(Dictionary data) { Application.Current.Dispatcher.Invoke(new Action(() => { int language = (int)Triton160UiSystem.Instance.WCF.Query.GetConfig(SCName.System_Language); if (language != _language) { _language = language; Triton160UiSystem.Instance.SetCulture(_language == 2 ? "zh-CN" : "en-US"); } _simulatorMode = (bool) Triton160UiSystem.Instance.WCF.Query.GetConfig(SCName.System_IsSimulatorMode); _isFaEnable = (bool)Triton160UiSystem.Instance.WCF.Query.GetConfig(SCName.System_EnableFa); })); } } }