TopViewModel.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using MECF.Framework.Common.DataCenter;
  2. using Prism.Commands;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Threading;
  11. namespace Venus_MainPages.ViewModels
  12. {
  13. internal class TopViewModel : BindableBase
  14. {
  15. #region 私有字段
  16. private string m_Title;
  17. private string m_SoftwareVersion;
  18. private List<string> m_RtDataKeys=new List<string> ();
  19. private Dictionary<string, object> m_RtDataValues;
  20. private string ModuleName;
  21. #endregion
  22. #region 属性
  23. public string Title
  24. {
  25. get { return m_Title; }
  26. set { SetProperty(ref m_Title, value); }
  27. }
  28. public string SoftwareVersion
  29. {
  30. get { return m_SoftwareVersion; }
  31. set { SetProperty(ref m_SoftwareVersion, value); }
  32. }
  33. public Dictionary<string, object> RtDataValues
  34. {
  35. get { return m_RtDataValues; }
  36. set { SetProperty(ref m_RtDataValues, value); }
  37. }
  38. #endregion
  39. #region 命令
  40. private DelegateCommand _SwichLanguageCommand;
  41. public DelegateCommand SwichLanguageCommand =>
  42. _SwichLanguageCommand ?? (_SwichLanguageCommand = new DelegateCommand(OnSwitchLanguage));
  43. #endregion
  44. #region 构造函数
  45. public TopViewModel()
  46. {
  47. Title = "Venus";
  48. m_SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  49. ModuleName = "PMA";
  50. addDataKeys();
  51. DispatcherTimer timer = new DispatcherTimer();
  52. timer.Interval = TimeSpan.FromSeconds(1);
  53. timer.Tick += timer_Tick;
  54. timer.Start();
  55. }
  56. #endregion
  57. #region 方法
  58. void timer_Tick(object sender, EventArgs e)
  59. {
  60. //RtConfigValues = QueryDataClient.Instance.Service.PollConfig(m_RtConfigKeys);
  61. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  62. }
  63. private void OnSwitchLanguage()
  64. {
  65. List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
  66. foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries)
  67. {
  68. if (dictionary.Source != null)
  69. {
  70. dictionaryList.Add(dictionary);
  71. }
  72. }
  73. string requestedCulture1 = @"/Venus_Themes;component/Languages/StringResources.en-US.xaml";
  74. string requestedCulture2 = @"/Venus_Themes;component/Languages/StringResources.zh-CN.xaml";
  75. ResourceDictionary resourceDictionary1 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture1));
  76. ResourceDictionary resourceDictionary2 = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture2));
  77. if (dictionaryList.IndexOf(resourceDictionary1) < dictionaryList.IndexOf(resourceDictionary2))
  78. {
  79. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary1);
  80. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary1);
  81. }
  82. else
  83. {
  84. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary2);
  85. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary2);
  86. }
  87. }
  88. private void addDataKeys()
  89. {
  90. m_RtDataKeys.Add($"{ModuleName}.FsmState");
  91. m_RtDataKeys.Add($"{ModuleName}.SignalTower.IsRedLightOn");
  92. m_RtDataKeys.Add($"{ModuleName}.SignalTower.IsYellowLightOn");
  93. m_RtDataKeys.Add($"{ModuleName}.SignalTower.IsGreenLightOn");
  94. m_RtDataKeys.Add($"{ModuleName}.SignalTower.IsBlueLightOn");
  95. m_RtDataKeys.Add($"{ModuleName}.SignalTower.IsBuzzerOn");
  96. }
  97. #endregion
  98. }
  99. }