using Aitex.Core.RT.ConfigCenter; using Aitex.Core.Util; using MECF.Framework.Common.CommonData.PowerSupplier; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Device.LinMot; using MECF.Framework.Common.Device.PowerSupplier; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Utilities; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Threading; namespace PunkHPX8_MainPages.ViewModels { public class PowerSupplierViewModel : BindableBase { #region 常量 private const string POWERSUPPLIER_DATA = "PowerSupplierData"; private const string CONNECTED = "Connected"; #endregion #region 内部变量 /// /// 模块名称 /// private string _module; /// /// 查询后台数据集合 /// private List _rtDataKeys = new List(); /// /// 查询后台的数据 /// private Dictionary _rtDataValues; /// /// 定时器 /// private DispatcherTimer _timer; #region powersupply /// /// PowerSupplier /// private string _powerSupplier; /// /// PowerSupplier数据 /// private PowerSupplierData _powerSupplierData; /// /// PowerSupplier连接状态 /// private bool _powerSupplierConnected; /// /// 步阶1数据 /// private PowerSupplierStepPeriodData _step1Data = new PowerSupplierStepPeriodData(); /// /// 步阶2数据 /// private PowerSupplierStepPeriodData _step2Data = new PowerSupplierStepPeriodData(); /// /// 步阶3数据 /// private PowerSupplierStepPeriodData _step3Data = new PowerSupplierStepPeriodData(); #endregion #endregion #region 属性 /// /// 模块名称 /// public string Module { get { return _module; } set { SetProperty(ref _module, value); } } #region powerSupply /// ///PowerSupplier /// public string PowerSupplier { get { return _powerSupplier; } set { SetProperty(ref _powerSupplier, value); } } /// /// PowerSupplier 数据 /// public PowerSupplierData PowerSupplierData { get { return _powerSupplierData; } set { SetProperty(ref _powerSupplierData, value);} } /// /// PowerSupplier连接状态 /// public bool PowerSupplierConnected { get { return _powerSupplierConnected; } set { SetProperty(ref _powerSupplierConnected, value); } } /// /// 步阶1数据 /// public PowerSupplierStepPeriodData Step1Data { get { return _step1Data; } set { SetProperty(ref _step1Data, value); } } /// /// 步阶2数据 /// public PowerSupplierStepPeriodData Step2Data { get { return _step2Data; } set { SetProperty(ref _step2Data, value); } } /// ///步阶3数据 /// public PowerSupplierStepPeriodData Step3Data { get { return _step3Data; } set { SetProperty(ref _step3Data, value); } } #endregion #endregion /// /// 构造函数 /// public PowerSupplierViewModel() { } /// /// 加载数据 /// public void LoadData(string systemName) { Module = systemName; List lst = new List(); lst.Add($"{Module}.PowerSupplier"); _rtDataValues = QueryDataClient.Instance.Service.PollData(lst); if (_rtDataValues != null) { PowerSupplier = CommonFunction.GetValue(_rtDataValues, $"{Module}.PowerSupplier"); } InitiRtDataKeys(); if(_timer==null) { _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(500); _timer.Tick += Timer_Tick; } _timer.Start(); } /// /// 定时器执行 /// /// /// private void Timer_Tick(object sender, EventArgs e) { if (_rtDataKeys.Count != 0) { _rtDataValues = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValues != null) { PowerSupplierData = CommonFunction.GetValue(_rtDataValues, $"{_powerSupplier}.{POWERSUPPLIER_DATA}"); PowerSupplierConnected = CommonFunction.GetValue(_rtDataValues, $"{_powerSupplier}.{CONNECTED}"); } } } /// /// 隐藏 /// public void Hide() { if (_timer != null) { _timer.Stop(); } } /// /// 初始化查询Key /// private void InitiRtDataKeys() { _rtDataKeys.Clear(); if(PowerSupplier!=null) { _rtDataKeys.Add($"{_powerSupplier}.{POWERSUPPLIER_DATA}"); _rtDataKeys.Add($"{_powerSupplier}.{CONNECTED}"); } } } }