123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Event;
- 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.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Threading;
- using Venus_MainPages.Unity;
- namespace Venus_MainPages.ViewModels
- {
- internal class TopViewModel : BindableBase
- {
- #region 私有字段
- private string m_Title;
- private string m_SoftwareVersion;
- 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 int logMaxCount = 50;//log在ui最多显示数量
- private AITSignalTowerData m_SignalTowerData;
- #endregion
- #region 属性
- 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 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); }
- }
- #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));
-
- #endregion
- #region 构造函数
- public TopViewModel()
- {
- Title = "Venus";
- m_SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- ModuleName = "PMA";
- addDataKeys();
- DispatcherTimer timer = new DispatcherTimer();
- timer.Interval = TimeSpan.FromSeconds(1);
- timer.Tick += timer_Tick;
- timer.Start();
- EventClient.Instance.OnEvent += Instance_OnEvent;
- EventClient.Instance.Start();
- }
- #endregion
- #region 方法
- void timer_Tick(object sender, EventArgs e)
- {
- RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
- SignalTowerData = (AITSignalTowerData)RtDataValues[$"{ModuleName}.SignalTower.DeviceData"];
- }
- 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()
- {
- m_RtDataKeys.Add("PMA.FsmState");
- m_RtDataKeys.Add("PMB.FsmState");
- m_RtDataKeys.Add("PMC.FsmState");
- m_RtDataKeys.Add("PMD.FsmState");
- m_RtDataKeys.Add("TM.FsmState");
- m_RtDataKeys.Add("LLA.FsmState");
- m_RtDataKeys.Add("LLB.FsmState");
- m_RtDataKeys.Add("PMA.IsSlitDoorClosed");
- m_RtDataKeys.Add($"{ModuleName}.SignalTower.DeviceData");
- }
- private void Instance_OnEvent(EventItem eventItem)
- {
- 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 (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");
- }
- #endregion
- }
- }
|