using Caliburn.Micro; using Caliburn.Micro.Core; using Aitex.Core.Common.DeviceData; using Aitex.Core.UI.ControlDataContext; using Aitex.Core.Util; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using FurnaceUI.Models; using FurnaceUI.Views.Editors; using System.Collections.ObjectModel; using System.Collections.Generic; using System.Threading.Tasks; using System.Reflection; using System; using Aitex.Core.RT.Log; using System.Linq; using System.Windows; using Aitex.Core.RT.SCCore; namespace FurnaceUI.Views.Maintenances { public class LPSensorViewModel : FurnaceUIViewModelBase { public bool IsManagerPermission { get => this.Permission == 3; } [Subscription("Rt.Status")] public string RtStatus { get; set; } public bool IsEnableManualOperation => IsSystemStaus; public bool IsSystemStaus => (RtStatus != "AutoRunning"); #region stage sensors [Subscription("System.SensorStation17Presence.DeviceData")] public AITSensorData SensorStation17Presence { get; set; } [Subscription("System.SensorStation18Presence.DeviceData")] public AITSensorData SensorStation18Presence { get; set; } [Subscription("System.SensorStation17APresence.DeviceData")] public AITSensorData SensorStation17APresence { get; set; } [Subscription("System.SensorStation18APresence.DeviceData")] public AITSensorData SensorStation18APresence { get; set; } [Subscription("System.Valve1EX.DeviceData")] public AITSensorData Valve1EX { get; set; } [Subscription("System.Valve1RE.DeviceData")] public AITSensorData Valve1RE { get; set; } [Subscription("System.Valve2EX.DeviceData")] public AITSensorData Valve2EX { get; set; } [Subscription("System.Valve2RE.DeviceData")] public AITSensorData Valve2RE { get; set; } [Subscription("LP1.LoadportState")] public string LP1State { get; set; } [Subscription("LP2.LoadportState")] public string LP2State { get; set; } [Subscription("LP3.LoadportState")] public string LP3State { get; set; } [Subscription("LP4.LoadportState")] public string LP4State { get; set; } [Subscription("LP1.CarrierId")] public string LP1CarrierId { get; set; } [Subscription("LP2.CarrierId")] public string LP2CarrierId { get; set; } [Subscription("LP3.CarrierId")] public string LP3CarrierId { get; set; } [Subscription("LP4.CarrierId")] public string LP4CarrierId { get; set; } #endregion public ObservableCollection LPSensors { get; set; } = new ObservableCollection(); public LPSensorViewModel() { } protected override void InvokeBeforeUpdateProperty(Dictionary data) { base.InvokeBeforeUpdateProperty(data); } public override void UpdateSubscribe(Dictionary data, object target, string module = null) { Parallel.ForEach(target.GetType().GetProperties().Where(_hasSubscriptionAttribute), property => { PropertyInfo pi = (PropertyInfo)property; SubscriptionAttribute subscription = property.GetCustomAttributes(false).First(_isSubscriptionAttribute) as SubscriptionAttribute; string key = subscription.ModuleKey; key = module == null ? key : string.Format("{0}.{1}", module, key); if (_subscribedKeys.Contains(key) && data.ContainsKey(key)) { try { var convertedValue = Convert.ChangeType(data[key], pi.PropertyType); var originValue = Convert.ChangeType(pi.GetValue(target, null), pi.PropertyType); if ((convertedValue as AITSensorData) != null && originValue != convertedValue) { pi.SetValue(target, convertedValue, null); //if ((convertedValue as AITSensorData).DeviceName.ToLower().Contains(_para)) //{ Update(LPSensors, convertedValue as AITSensorData); //} } } catch (Exception ex) { LOG.Error("由RT返回的数据更新失败" + key, ex); } } }); base.UpdateSubscribe(data, target, module); } private void Update(ObservableCollection sensors, object obj) { AITSensorData data = obj as AITSensorData; if (data != null && sensors.Count > 0) { var item = sensors.SingleOrDefault(x => x.Name == data.DeviceName); if (item != null) { item.Value = data.Value; } } } public void Home(object para) { InvokeClient.Instance.Service.DoOperation($"{para}.Home", ""); } public void SetClamp(object para) { InvokeClient.Instance.Service.DoOperation($"{para}.Unload", ""); } public void SetRelease(object para) { InvokeClient.Instance.Service.DoOperation($"{para}.Load", ""); } public void ReadCarrierId(string moduleID) { InvokeClient.Instance.Service.DoOperation($"{moduleID}.ReadCarrierId"); } public void ClosedCmd() { (GetView() as Window).Close(); } } }