using System; using System.Collections.Generic; using System.Windows.Forms.VisualStyles; using Aitex.Core.RT.SCCore; using Aitex.Core.UI.MVVM; using Aitex.Core.Utilities; using Aitex.Triton160.Common; using Aitex.Triton160.UI.Config; namespace Aitex.Triton160.UI.ViewModel { public class UIViewModelBase : SubscriptionViewModelBase { protected const string SystemDeviceModule = "Device.System"; protected const string SystemStateModule = "System"; [IgnorePropertyChange] protected SCValue SCLocal { get; set; } [IgnorePropertyChange] private List> _allDataItems = new List>(); public UIViewModelBase(string vmName) : base(vmName) { SCLocal = new SCValue(); PollDataFunction = (IEnumerable keys) => { return Triton160UiSystem.Instance.WCF.Query.PollData(keys); }; InvokeFunction = (string[] param) => { if (param.Length == 1) Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(param[0]); else if (param.Length == 2) Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(param[0], param[1]); else if (param.Length == 3) Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(param[0], param[1], param[2]); }; DeviceFunction = (string deviceName, string operationName) => { Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.DeviceOperation.ToString(), deviceName, operationName); }; DeviceControlFunction = (object[] args) => { if (args.Length == 2) Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.DeviceOperation.ToString(), args[0], args[1]); else if (args.Length == 3) Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.DeviceOperation.ToString(), args[0], args[1], args[2]); else if (args.Length == 4) Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.DeviceOperation.ToString(), args[0], args[1], args[2], args[3]); }; _allDataItems = SystemConfigManager.Instance.GetMonitorDataList(); } public void UpdateAllConfig() { SCLocal.Update(Triton160UiSystem.Instance.WCF.Query.PollConfig(SCLocal.GetKeys())); } public Dictionary> GetDataElements(string culture) { Dictionary> result = new Dictionary>(); Dictionary> all = GetDataElements(); foreach (var tuple in all) { result.Add(tuple.Key, Tuple.Create(tuple.Value.Item1, culture==CultureSupported.Chinese ? tuple.Value.Item3 : tuple.Value.Item2, tuple.Value.Item4)); } return result; } public Dictionary> GetDataElements() { UpdateAllConfig(); Dictionary> dicItems = new Dictionary>(); foreach (var dataItem in _allDataItems) { dicItems[dataItem.Item1] = dataItem; } //更新Gas UpdateGasItem(SCLocal.GasLineConfig.Gas1Enable, SCLocal.GasLineConfig.Gas1Name, "Gas1", "System.IoMfc.MfcGas1.FeedBack", dicItems); UpdateGasItem(SCLocal.GasLineConfig.Gas1Enable, SCLocal.GasLineConfig.Gas1Name, "Gas1", "System.IoMfc.MfcGas1.SetPoint", dicItems); UpdateGasItem(SCLocal.GasLineConfig.Gas2Enable, SCLocal.GasLineConfig.Gas2Name, "Gas2", "System.IoMfc.MfcGas2.FeedBack", dicItems); UpdateGasItem(SCLocal.GasLineConfig.Gas2Enable, SCLocal.GasLineConfig.Gas2Name, "Gas2", "System.IoMfc.MfcGas2.SetPoint", dicItems); UpdateGasItem(SCLocal.GasLineConfig.Gas3Enable, SCLocal.GasLineConfig.Gas3Name, "Gas3", "System.IoMfc.MfcGas3.FeedBack", dicItems); UpdateGasItem(SCLocal.GasLineConfig.Gas3Enable, SCLocal.GasLineConfig.Gas3Name, "Gas3", "System.IoMfc.MfcGas3.SetPoint", dicItems); UpdateGasItem(SCLocal.GasLineConfig.Gas4Enable, SCLocal.GasLineConfig.Gas4Name, "Gas4", "System.IoMfc.MfcGas4.FeedBack", dicItems); UpdateGasItem(SCLocal.GasLineConfig.Gas4Enable, SCLocal.GasLineConfig.Gas4Name, "Gas4", "System.IoMfc.MfcGas4.SetPoint", dicItems); UpdateGasItem(SCLocal.GasLineConfig.Gas5Enable, SCLocal.GasLineConfig.Gas5Name, "Gas5", "System.IoMfc.MfcGas5.FeedBack", dicItems); UpdateGasItem(SCLocal.GasLineConfig.Gas5Enable, SCLocal.GasLineConfig.Gas5Name, "Gas5", "System.IoMfc.MfcGas5.SetPoint", dicItems); //更新TV if (!SCLocal.PressureControlConfig.EnableThrottleValve) { dicItems.Remove("System.IoThrottleValve.ThrottleValve.TVPosition"); dicItems.Remove("System.IoThrottleValve.ThrottleValve.TVPositionSetPoint"); dicItems.Remove("System.IoThrottleValve.ThrottleValve.TVPressure"); dicItems.Remove("System.IoThrottleValve.ThrottleValve.TVPressureSetPoint"); } if (!SCLocal.PressureControlConfig.PumpEnableN2Pressure) { dicItems.Remove("System.IoPump.MainPump.N2PressureValue"); } if (!SCLocal.PressureControlConfig.PumpEnableWaterFlow) { dicItems.Remove("System.IoPump.MainPump.WaterFlowValue"); } return dicItems; } void UpdateGasItem(bool enable, string display, string id, string key, Dictionary> dicItems) { if (enable && dicItems.ContainsKey(key)) { dicItems[key] = Tuple.Create(key, dicItems[key].Item2.Replace(id, display), dicItems[key].Item3.Replace(id, display), dicItems[key].Item4); } else { dicItems.Remove(key); } } } }