// /************************************************************************ // * @file ExchangeDataBase.cs // * @author Su Liang // * @date 2023/02/26 // * // * @copyright © Sicentury Inc. // * // * @brief // * // * @details // * // * // * *****************************************************************************/ using System; using System.Linq; using System.Reflection; using System.Runtime.Serialization; using System.Threading.Tasks; using DocumentFormat.OpenXml.Drawing.Charts; using MECF.Framework.Common.CommonData; namespace Aitex.Core.Common.DeviceData.IoDevice { [Serializable] [DataContract] public class ExchangeDataBase : NotifiableItem, IDeviceData { [DataMember] public string Status { get; set; } [DataMember] public bool IsBusy { get; set; } [DataMember] public bool IsAlarm { get; set; } public void Update(IDeviceData data) { if (data == null) return; var targetProps = GetType().GetProperties() .Where(prop => Attribute.IsDefined((MemberInfo)prop, typeof(DataMemberAttribute))); var sourceProps = data.GetType().GetProperties() .Where(prop => Attribute.IsDefined((MemberInfo)prop, typeof(DataMemberAttribute))); Parallel.ForEach(targetProps, pi => { var srcPi = sourceProps.FirstOrDefault(x => x.Name == pi.Name); if(srcPi == null) return; pi.SetValue(this, srcPi.GetValue(data)); }); } } }