using System; using System.Collections.Generic; using System.Linq; using System.Text; using Prism.Commands; using Prism.Mvvm; using Venus_MainPages.Unity; using Venus_MainPages.Views; using System.Threading.Tasks; using Aitex.Core.Util; using FabConnect.SecsGemInterface.GemModel; using MECF.Framework.Common.OperationCenter; using Aitex.Core.RT.OperationCenter; using System.Windows.Threading; using Aitex.Core.Common.DeviceData; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Equipment; using Aitex.Core.RT.Log; namespace Venus_MainPages.ViewModels { public class FaViewModel:BindableBase { private readonly GEMController _gem = new GEMController(); private List m_RtDataKeys = new List(); private Dictionary m_RtDataValues; private string m_HostCommunicationStatus; private string m_HostControlStatus; private int m_SpoolingState; private string m_SpoolingActual; private string m_SpoolingTotal; private string m_SpoolingFullTime; private string m_SpoolingStartTime; private bool m_IsSpoolingEnable; #region 私有变量 public enum ConmmunicationState { Disabled, Enabled, EnabledNotCommunicating, EnabledCommunicating, WaitCRA, WaitDelay, WaitCRFromHost, } public enum ControlState { Unknown, EquipmentOffline, AttemptOnline, HostOffline, OnlineLocal, OnlineRemote, } #endregion #region 命令 private DelegateCommand _FaEnableCommand; public DelegateCommand FaEnableCommand => _FaEnableCommand ?? (_FaEnableCommand = new DelegateCommand(FaEnable)); private DelegateCommand _FaDisableCommand; public DelegateCommand FaDisableCommand => _FaDisableCommand ?? (_FaDisableCommand = new DelegateCommand(FaDisable)); private DelegateCommand _FaOnlineCommand; public DelegateCommand FaOnlineCommand => _FaOnlineCommand ?? (_FaOnlineCommand = new DelegateCommand(FaOnline)); private DelegateCommand _FaOfflineCommand; public DelegateCommand FaOfflineCommand => _FaOfflineCommand ?? (_FaOfflineCommand = new DelegateCommand(FaOffline)); private DelegateCommand _FaLocalCommand; public DelegateCommand FaLocalCommand => _FaLocalCommand ?? (_FaLocalCommand = new DelegateCommand(FaLocal)); private DelegateCommand _FaRemoteCommand; public DelegateCommand FaRemoteCommand => _FaRemoteCommand ?? (_FaRemoteCommand = new DelegateCommand(FaRemote)); private DelegateCommand _FaEnableSpoolingCommand; public DelegateCommand FaEnableSpoolingCommand => _FaEnableSpoolingCommand ?? (_FaEnableSpoolingCommand = new DelegateCommand(FaEnableSpooling)); private DelegateCommand _FaDisableSpoolingCommand; public DelegateCommand FaDisableSpoolingCommand => _FaDisableSpoolingCommand ?? (_FaDisableSpoolingCommand = new DelegateCommand(FaDisableSpooling)); #endregion #region 属性 public string HostCommunicationStatus { get { return m_HostCommunicationStatus; } set { SetProperty(ref m_HostCommunicationStatus, value); } } public string HostControlStatus { get { return m_HostControlStatus; } set { SetProperty(ref m_HostControlStatus, value); } } public int SpoolingState { get { return m_SpoolingState; } set { SetProperty(ref m_SpoolingState, value); } } public string SpoolingActual { get { return m_SpoolingActual; } set { SetProperty(ref m_SpoolingActual, value); } } public string SpoolingTotal { get { return m_SpoolingTotal; } set { SetProperty(ref m_SpoolingTotal, value); } } public string SpoolingFullTime { get { return m_SpoolingFullTime; } set { SetProperty(ref m_SpoolingFullTime, value); } } public string SpoolingStartTime { get { return m_SpoolingStartTime; } set { SetProperty(ref m_SpoolingStartTime, value); } } public bool IsSpoolingEnable { get { return m_IsSpoolingEnable; } set { SetProperty(ref m_IsSpoolingEnable, value); } } public Dictionary RtDataValues { get { return m_RtDataValues; } set { SetProperty(ref m_RtDataValues, value); } } public CommunicationState FACommunicationState { get { return string.IsNullOrEmpty(HostCommunicationStatus) ? CommunicationState.Disabled : (CommunicationState)Enum.Parse(typeof(CommunicationState), HostCommunicationStatus); } } public ControlState FAControlState { get { return string.IsNullOrEmpty(HostControlStatus) ? ControlState.Unknown : (ControlState)Enum.Parse(typeof(ControlState), HostControlStatus); } } public bool _IsDisableEnable; public bool IsEnableEnable { get { return _IsDisableEnable; } set { SetProperty(ref _IsDisableEnable, value);} } public bool _IsEnableDisable; public bool IsEnableDisable { get { return _IsEnableDisable; } set { SetProperty(ref _IsEnableDisable, value); } } public bool _IsEnableOnline; public bool IsEnableOnline { get { return _IsEnableOnline; } set { SetProperty(ref _IsEnableOnline, value); } } public bool _IsEnableOffline; public bool IsEnableOffline { get { return _IsEnableOffline; } set { SetProperty(ref _IsEnableOffline, value); } } public bool _IsEnableLocal; public bool IsEnableLocal { get { return _IsEnableLocal; } set { SetProperty(ref _IsEnableLocal, value); } } public bool _IsEnableRemote; public bool IsEnableRemote { get { return _IsEnableRemote; } set { SetProperty(ref _IsEnableRemote, value); } } public bool _IsEnableEnableSpooling; public bool IsEnableEnableSpooling { get { return _IsEnableEnableSpooling; } set { SetProperty(ref _IsEnableEnableSpooling, value); } } public bool IsEnableDisableSpooling { get { return IsSpoolingEnable; } } #endregion #region 构造函数 public FaViewModel() { addDataKeys(); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(0.5); timer.Tick += timer_Tick; timer.Start(); } #endregion #region void timer_Tick(object sender, EventArgs e) { IsEnableEnable = FACommunicationState == CommunicationState.Disabled; IsEnableDisable= FACommunicationState != CommunicationState.Disabled; IsEnableOnline = FAControlState == ControlState.Unknown || FAControlState == ControlState.EquipmentOffline; IsEnableOffline = FAControlState == ControlState.Unknown || FAControlState != ControlState.EquipmentOffline; IsEnableRemote = FAControlState == ControlState.OnlineLocal; IsEnableLocal = FAControlState == ControlState.OnlineRemote; IsEnableEnableSpooling = !IsSpoolingEnable; RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys); HostCommunicationStatus = CommonFunction.GetValue(RtDataValues, "System.CommunicationStatus"); HostControlStatus = CommonFunction.GetValue(RtDataValues, "System.ControlStatus"); SpoolingState = CommonFunction.GetValue(RtDataValues, "System.SpoolingState"); SpoolingActual = CommonFunction.GetValue(RtDataValues, "System.SpoolingActual"); SpoolingTotal= CommonFunction.GetValue(RtDataValues, "System.SpoolingTotal"); SpoolingFullTime = CommonFunction.GetValue(RtDataValues, "System.SpoolingFullTime"); SpoolingStartTime = CommonFunction.GetValue(RtDataValues, "System.SpoolingStartTime"); IsSpoolingEnable = CommonFunction.GetValue(RtDataValues, "System.IsSpoolingEnable"); } private void addDataKeys() { m_RtDataKeys.Add("System.CommunicationStatus"); m_RtDataKeys.Add("System.ControlStatus"); m_RtDataKeys.Add("System.SpoolingState"); m_RtDataKeys.Add("System.SpoolingActual"); m_RtDataKeys.Add("System.SpoolingTotal"); m_RtDataKeys.Add("System.SpoolingFullTime"); m_RtDataKeys.Add("System.SpoolingStartTime"); m_RtDataKeys.Add("System.IsSpoolingEnable"); } public void FaEnable() { InvokeClient.Instance.Service.DoOperation("System.FACommand", "FAEnable"); } public void FaDisable() { InvokeClient.Instance.Service.DoOperation("System.FACommand", "FADisable"); } public void FaOnline() { InvokeClient.Instance.Service.DoOperation("System.FACommand", "FAOnline"); } public void FaOffline() { InvokeClient.Instance.Service.DoOperation("System.FACommand", "FAOffline"); } public void FaLocal() { InvokeClient.Instance.Service.DoOperation("System.FACommand", "FALocal"); } public void FaRemote() { InvokeClient.Instance.Service.DoOperation("System.FACommand", "FARemote"); } public void FaEnableSpooling() { InvokeClient.Instance.Service.DoOperation("System.FACommand", "FAEnableSpooling"); } public void FaDisableSpooling() { InvokeClient.Instance.Service.DoOperation("System.FACommand", "FADisableSpooling"); } #endregion } }