Sic.Framework/MECF.Framework.Common/Aitex/Core/Common/DeviceData/IoDevice/ExchangeDataBase.cs

59 lines
1.7 KiB
C#
Raw Normal View History

2023-04-13 11:51:03 +08:00
// /************************************************************************
// * @file ExchangeDataBase.cs
// * @author Su Liang
// * @date 2023/02/26
// *
// * @copyright &copy 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));
});
}
}
}