123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646 |
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using Aitex.Core.WCF;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using Prism.Commands;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Media;
- using System.Windows.Threading;
- using Venus_MainPages.Unity;
- using Venus_MainPages.Views;
- namespace Venus_MainPages.ViewModels
- {
- internal class TopViewModel : BindableBase
- {
- #region 私有字段
- private string m_Title;
- private string m_SoftwareVersion;
- //private DateTime m_DateTimeNow;
- private List<string> m_RtDataKeys = new List<string>();
- private Dictionary<string, object> m_RtDataValues;
- //private string ModuleName;
- private ObservableCollection<EventItem> m_EventLogList = new ObservableCollection<EventItem>();
- private EventItem m_CurrentEventItem = new EventItem();
- private string m_CurrentEventItemValue;
- //private object _lockObj = new object();
- private int m_EventLogListSelectedIndex;
- private Queue<EventItem> alarmQuery = new Queue<EventItem>();//控制alarm log 在 top UI显示
- private readonly int logMaxCount = 50;//log在ui最多显示数量
- private AITSignalTowerData m_SignalTowerData;
- private string m_HostCommunicationStatus;
- private string m_TimeTick;
- private string m_UserName;
- //private JetChamber m_SelectedJetChamber = JetChamber.None;
- private bool m_PMAIsInstalled;
- private bool m_PMBIsInstalled;
- private bool m_PMCIsInstalled;
- private bool m_PMDIsInstalled;
- private bool m_LLAIsInstalled;
- private bool m_LLBIsInstalled;
- private bool m_TMIsInstalled;
- private bool m_EFEMIsInstalled;
- //private List<eEvent> stopEntityId = new List<eEvent>()
- //{
- // eEvent.ERR_MATCH,
- // eEvent.ERR_RF,
- // eEvent.ERR_PENDULUM_VALVE,
- // eEvent.ERR_DEVICE_INFO,
- // eEvent.ERR_DRY_PUMP,
- // eEvent.ERR_HighTemperatureHeater
- // //eEvent.ERR_Sensor
- //};
- //private PressureType m_PressureType;
- //private ConfigType m_ConfigType;
- private bool m_IsExcludeInfoType;
- private TopView view;
- #endregion
- #region 属性
- public string UserName
- {
- get { return m_UserName; }
- set { SetProperty(ref m_UserName, value); }
- }
- //public DateTime DateTimeNow
- //{
- // get { return m_DateTimeNow; }
- // set { SetProperty(ref m_DateTimeNow, value); }
- //}
- public string Title
- {
- get { return m_Title; }
- set { SetProperty(ref m_Title, value); }
- }
- public string SoftwareVersion
- {
- get { return m_SoftwareVersion; }
- set { SetProperty(ref m_SoftwareVersion, value); }
- }
- public string TimeTick
- {
- get { return m_TimeTick; }
- set { SetProperty(ref m_TimeTick, value); }
- }
- public Dictionary<string, object> RtDataValues
- {
- get { return m_RtDataValues; }
- set { SetProperty(ref m_RtDataValues, value); }
- }
- public ObservableCollection<EventItem> EventLogList
- {
- get { return m_EventLogList; }
- set { SetProperty(ref m_EventLogList, value); }
- }
- public EventItem CurrentEventItem
- {
- get { return m_CurrentEventItem; }
- set { SetProperty(ref m_CurrentEventItem, value); }
- }
- public int EventLogListSelectedIndex
- {
- get { return m_EventLogListSelectedIndex; }
- set { SetProperty(ref m_EventLogListSelectedIndex, value); }
- }
- public string CurrentEventItemValue
- {
- get { return m_CurrentEventItemValue; }
- set { SetProperty(ref m_CurrentEventItemValue, value); }
- }
- public AITSignalTowerData SignalTowerData
- {
- get { return m_SignalTowerData; }
- set { SetProperty(ref m_SignalTowerData, value); }
- }
- public string HostCommunicationStatusBackground
- {
- get
- {
- switch (HostCommunicationStatus)
- {
- case "Disabled":
- return "#D79C11";
- case "Enabled":
- case "EnabledNotCommunicating":
- case "WaitCRA":
- case "WaitDelay":
- case "WaitCRFromHost":
- return "Transparent";
- case "EnabledCommunicating":
- return "LawnGreen";
- default:
- return "#D79C11";
- }
- }
- }
- public string m_HostBack;
- public string HostBack
- {
- get { return m_HostBack; }
- set { SetProperty(ref m_HostBack, value); }
- }
- [Subscription("System.CommunicationStatus")]
- public string HostCommunicationStatus
- {
- get { return m_HostCommunicationStatus; }
- set
- {
- SetProperty(ref m_HostCommunicationStatus, value);
- }
- }
- public bool IsEnableFAEnable
- {
- get
- {
- return HostCommunicationStatus == "Disabled";
- }
- }
- public bool _IsEnableEnable;
- public bool IsEnableEnable
- {
- get { return _IsEnableEnable; }
- set { SetProperty(ref _IsEnableEnable, value); }
- }
- public bool _IsEnableDisable;
- public bool IsEnableDisable
- {
- get { return _IsEnableDisable; }
- set { SetProperty(ref _IsEnableDisable, value); }
- }
- public bool IsExcludeInfoType
- {
- get { return m_IsExcludeInfoType; }
- set { SetProperty(ref m_IsExcludeInfoType, value); }
- }
- public FACommunicationState FACommunicationState
- {
- get
- {
- return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
- : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus);
- }
- }
- public bool PMAIsInstalled
- {
- get { return m_PMAIsInstalled; }
- set { SetProperty(ref m_PMAIsInstalled, value); }
- }
- public bool PMBIsInstalled
- {
- get { return m_PMBIsInstalled; }
- set { SetProperty(ref m_PMBIsInstalled, value); }
- }
- public bool PMCIsInstalled
- {
- get { return m_PMCIsInstalled; }
- set { SetProperty(ref m_PMCIsInstalled, value); }
- }
- public bool PMDIsInstalled
- {
- get { return m_PMDIsInstalled; }
- set { SetProperty(ref m_PMDIsInstalled, value); }
- }
- public bool LLAIsInstalled
- {
- get { return m_LLAIsInstalled; }
- set { SetProperty(ref m_LLAIsInstalled, value); }
- }
- public bool LLBIsInstalled
- {
- get { return m_LLBIsInstalled; }
- set { SetProperty(ref m_LLBIsInstalled, value); }
- }
- public bool TMIsInstalled
- {
- get { return m_TMIsInstalled; }
- set { SetProperty(ref m_TMIsInstalled, value); }
- }
- public SolidColorBrush DefaultBrush = new SolidColorBrush(Colors.LightCyan);
- public bool EFEMIsInstalled
- {
- get { return m_EFEMIsInstalled; }
- set { SetProperty(ref m_EFEMIsInstalled, value); }
- }
- private bool m_SETMIsInstalled;
- private bool m_DETMIsInstalled;
- private bool m_VCE1IsInstalled;
- private bool m_VCEAIsInstalled;
- private bool m_VCEBIsInstalled;
- public bool SETMIsInstalled
- {
- get { return m_SETMIsInstalled; }
- set { SetProperty(ref m_SETMIsInstalled, value); }
- }
- public bool DETMIsInstalled
- {
- get { return m_DETMIsInstalled; }
- set { SetProperty(ref m_DETMIsInstalled, value); }
- }
- public bool VCE1IsInstalled
- {
- get { return m_VCE1IsInstalled; }
- set { SetProperty(ref m_VCE1IsInstalled, value); }
- }
- public bool VCEAIsInstalled
- {
- get { return m_VCEAIsInstalled; }
- set { SetProperty(ref m_VCEAIsInstalled, value); }
- }
- public bool VCEBIsInstalled
- {
- get { return m_VCEBIsInstalled; }
- set { SetProperty(ref m_VCEBIsInstalled, value); }
- }
- #endregion
- #region 命令
- //private DelegateCommand _SwichLanguageCommand;
- //public DelegateCommand SwichLanguageCommand =>
- // _SwichLanguageCommand ?? (_SwichLanguageCommand = new DelegateCommand(OnSwitchLanguage));
- private DelegateCommand _ResetCommand;
- public DelegateCommand ResetCommand =>
- _ResetCommand ?? (_ResetCommand = new DelegateCommand(OnReset));
- private DelegateCommand _ClearCommand;
- public DelegateCommand ClearCommand =>
- _ClearCommand ?? (_ClearCommand = new DelegateCommand(OnClear));
- private DelegateCommand _SkipCommand;
- public DelegateCommand SkipCommand =>
- _SkipCommand ?? (_SkipCommand = new DelegateCommand(OnSkip));
- //private DelegateCommand _BuzzerOffCommand;
- //public DelegateCommand BuzzerOffCommand =>
- // _BuzzerOffCommand ?? (_BuzzerOffCommand = new DelegateCommand(OnBuzzerOff));
- private DelegateCommand _FADisableCommand;
- public DelegateCommand FADisableCommand =>
- _FADisableCommand ?? (_FADisableCommand = new DelegateCommand(FaDisable));
- private DelegateCommand _FAEnableCommand;
- public DelegateCommand FAEnableCommand =>
- _FAEnableCommand ?? (_FAEnableCommand = new DelegateCommand(FaEnable));
- private DelegateCommand _ExcludeInfoCommand;
- public DelegateCommand ExcludeInfoCommand =>
- _ExcludeInfoCommand ?? (_ExcludeInfoCommand = new DelegateCommand(OnExcludeInfo));
- private DelegateCommand _LogoutCommand;
- public DelegateCommand LogoutCommand =>
- _LogoutCommand ?? (_LogoutCommand = new DelegateCommand(OnLogout));
- private DelegateCommand _SwitchBuzzerCommand;
- public DelegateCommand SwitchBuzzerCommand =>
- _SwitchBuzzerCommand ?? (_SwitchBuzzerCommand = new DelegateCommand(OnSwitchBuzzer));
- private DelegateCommand<object> _LoadCommand;
- public DelegateCommand<object> LoadCommand =>
- _LoadCommand ?? (_LoadCommand = new DelegateCommand<object>(OnLoad));
- #endregion
- #region 构造函数
- public TopViewModel()
- {
- m_SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString();
- PMAIsInstalled = allModules.Contains("PMA");
- PMBIsInstalled = allModules.Contains("PMB");
- PMCIsInstalled = allModules.Contains("PMC");
- PMDIsInstalled = allModules.Contains("PMD");
- LLAIsInstalled = allModules.Contains("LLA");
- LLBIsInstalled = allModules.Contains("LLB");
- TMIsInstalled = allModules.Contains("TM");
- EFEMIsInstalled = allModules.Contains("EFEM");
- SETMIsInstalled = allModules.Contains("SETM");
- DETMIsInstalled = allModules.Contains("DETM");
- VCE1IsInstalled = allModules.Contains("VCE1");
- VCEAIsInstalled = allModules.Contains("VCEA");
- VCEBIsInstalled = allModules.Contains("VCEB");
- //ModuleName = "PMA";
- addDataKeys();
- RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
- DispatcherTimer timer = new DispatcherTimer();
- timer.Interval = TimeSpan.FromSeconds(1);
- timer.Tick += timer_Tick;
- timer.Start();
- EventClient.Instance.OnEvent += Instance_OnEvent;
- EventClient.Instance.Start();
- Title = QueryDataClient.Instance.Service.GetConfig($"System.Name").ToString();
- UserName = GlobalUser.Instance.User.Name;
- }
- #endregion
- #region 方法
- private void OnLoad(object obj)
- {
- view = obj as TopView;
- if (!VCE1IsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.vce1Title);
- this.view.vce1Title = null;
- }
- if (!VCEAIsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.vceATitle);
- this.view.vceATitle = null;
- }
- if (!VCEBIsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.vceBTitle);
- this.view.vceBTitle = null;
- }
- if (!PMAIsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.pmaTitle);
- this.view.pmaTitle = null;
- }
- if (!PMBIsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.pmbTitle);
- this.view.pmbTitle = null;
- }
- if (!PMCIsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.pmcTitle);
- this.view.pmcTitle = null;
- }
- if (!PMDIsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.pmdTitle);
- this.view.pmdTitle = null;
- }
- if (!SETMIsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.seTmTitle);
- this.view.seTmTitle = null;
- }
- if (!DETMIsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.deTmTitle);
- this.view.deTmTitle = null;
- }
- if (!TMIsInstalled)
- {
- this.view.moduleGrid.Children.Remove(this.view.tmTitle);
- this.view.tmTitle = null;
- }
- GC.Collect(); // This should pick up the control removed at a previous MouseDown
- GC.WaitForPendingFinalizers(); // Doesn't help either
- }
- void timer_Tick(object sender, EventArgs e)
- {
- TimeTick = DateTime.Now.ToString();
- RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
- SignalTowerData = CommonFunction.GetValue<AITSignalTowerData>(RtDataValues, $"System.SignalTower.DeviceData");
- HostCommunicationStatus = CommonFunction.GetValue<String>(RtDataValues, "System.CommunicationStatus");
- //IsEnableEnable = FACommunicationState == CommunicationState.Disabled;
- //IsEnableDisable = FACommunicationState != CommunicationState.Disabled;
- HostBack = HostCommunicationStatusBackground;
- IsEnableEnable = (HostCommunicationStatus == FACommunicationState.Disabled.ToString());
- IsEnableDisable = (HostCommunicationStatus != FACommunicationState.Disabled.ToString());
- }
- //private void OnSwitchLanguage()
- //{
- // List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
- // foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
- // {
- // if (dictionary.Source != null)
- // {
- // dictionaryList.Add(dictionary);
- // }
- // }
- // string requestedCulture1 = @"/Venus_Themes;component/Languages/StringResources.en-US.xaml";
- // string requestedCulture2 = @"/Venus_Themes;component/Languages/StringResources.zh-CN.xaml";
- // ResourceDictionary resourceDictionary1 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture1));
- // ResourceDictionary resourceDictionary2 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture2));
- // if (dictionaryList.IndexOf(resourceDictionary1) < dictionaryList.IndexOf(resourceDictionary2))
- // {
- // Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary1);
- // Application.Current.Resources.MergedDictionaries.Add(resourceDictionary1);
- // }
- // else
- // {
- // Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary2);
- // Application.Current.Resources.MergedDictionaries.Add(resourceDictionary2);
- // }
- //}
- private void OnReset()
- {
- InvokeClient.Instance.Service.DoOperation("System.Reset");
- }
- private void addDataKeys()
- {
- if (PMAIsInstalled)
- {
- m_RtDataKeys.Add("PMA.FsmState");
- m_RtDataKeys.Add("PMA.IsOnline");
- m_RtDataKeys.Add("PMA.IsInclude");
- }
- if (PMBIsInstalled)
- {
- m_RtDataKeys.Add("PMB.FsmState");
- m_RtDataKeys.Add("PMB.IsOnline");
- m_RtDataKeys.Add("PMB.IsInclude");
- }
- if (PMCIsInstalled)
- {
- m_RtDataKeys.Add("PMC.FsmState");
- m_RtDataKeys.Add("PMC.IsOnline");
- m_RtDataKeys.Add("PMC.IsInclude");
- }
- if (PMDIsInstalled)
- {
- m_RtDataKeys.Add("PMD.FsmState");
- m_RtDataKeys.Add("PMD.IsOnline");
- m_RtDataKeys.Add("PMD.IsInclude");
- }
- m_RtDataKeys.Add("TM.FsmState");
- m_RtDataKeys.Add("TM.IsOnline");
- if (VCE1IsInstalled)
- {
- m_RtDataKeys.Add("VCE1.IsOnline");
- m_RtDataKeys.Add("VCE1.FsmState");
- }
- if (VCEAIsInstalled)
- {
- m_RtDataKeys.Add("VCEA.IsOnline");
- m_RtDataKeys.Add("VCEA.FsmState");
- }
- if (VCEBIsInstalled)
- {
- m_RtDataKeys.Add("VCEB.IsOnline");
- m_RtDataKeys.Add("VCEB.FsmState");
- }
- if (EFEMIsInstalled)
- {
- m_RtDataKeys.Add("EFEM.FsmState");
- m_RtDataKeys.Add("EFEM.IsOnline");
- }
- m_RtDataKeys.Add("LLA.FsmState");
- m_RtDataKeys.Add("LLA.IsOnline");
- m_RtDataKeys.Add("LLA.IsInclude");
- m_RtDataKeys.Add("LLB.FsmState");
- m_RtDataKeys.Add("LLB.IsOnline");
- m_RtDataKeys.Add("LLB.IsInclude");
- m_RtDataKeys.Add("SYSTEM.FsmState");
- m_RtDataKeys.Add("System.IsAutoMode");
- m_RtDataKeys.Add($"System.SignalTower.DeviceData");
- m_RtDataKeys.Add("System.CommunicationStatus");
- }
- private void Instance_OnEvent(EventItem eventItem)
- {
- if (IsExcludeInfoType && eventItem.Level == EventLevel.Information)
- {
- return;
- }
- GlobalEvents.Instance.OnEventItemRaiseChanged(eventItem);
- switch (eventItem.Type)
- {
- case EventType.EventUI_Notify:
- Application.Current.Dispatcher.Invoke(delegate
- {
- EventLogList.Insert(0, eventItem);
- if (EventLogList.Count > logMaxCount)
- {
- EventLogList.RemoveAt(EventLogList.Count - 1);
- }
- if (eventItem.Level == EventLevel.Alarm)
- {
- alarmQuery.Enqueue(eventItem);
- //if (m_ConfigType == ConfigType.Kepler2200)
- //{
- // if (stopEntityId.Contains((eEvent)eventItem.Id) && eventItem.Source.Contains("PM"))
- // {
- // InvokeClient.Instance.Service.DoOperation($"{eventItem.Source}.PmError");
- // }
- //}
- }
- if (alarmQuery.Count > 0)
- {
- CurrentEventItem = alarmQuery.First();
- }
- else
- {
- CurrentEventItem = eventItem;
- }
- EventLogListSelectedIndex = 0;
- });
- break;
- case EventType.Dialog_Nofity:
- //PopDialog(obj);
- break;
- case EventType.KickOut_Notify:
- break;
- case EventType.Sound_Notify:
- break;
- case EventType.UIMessage_Notify:
- //PopUIMessage(obj);
- break;
- }
- }
- private void OnClear()
- {
- CurrentEventItem = null;
- alarmQuery.Clear();
- EventLogList.Clear();
- }
- private void OnSkip()
- {
- if (alarmQuery.Count > 0)
- {
- alarmQuery.Dequeue();
- if (alarmQuery.Count > 0)
- {
- CurrentEventItem = alarmQuery.First();
- }
- else
- {
- CurrentEventItem = null;
- }
- }
- }
- //private void OnBuzzerOff()
- //{
- // InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SignalTower.SwitchOffBuzzer");
- //}
- public void FaDisable()
- {
- InvokeClient.Instance.Service.DoOperation($"FACommand", "FADisable");
- }
- public void FaEnable()
- {
- InvokeClient.Instance.Service.DoOperation($"FACommand", "FAEnable");
- }
- public void OnExcludeInfo()
- {
- IsExcludeInfoType = !IsExcludeInfoType;
- }
- private void OnLogout()
- {
- var _mainWindow = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is Window) as Window;
- LogoutView heaterView = new LogoutView();
- heaterView.WindowStartupLocation = WindowStartupLocation.CenterScreen;
- heaterView.Owner = _mainWindow;
- heaterView.Show();
- }
- private void OnSwitchBuzzer()
- {
- InvokeClient.Instance.Service.DoOperation($"System.{AITSignalTowerOperation.SwitchOffBuzzer}");
- }
- #endregion
- }
- }
|