using System.Reflection;
using System.Windows.Forms;
using Uestc.Auto6.Dso.Core;
using Uestc.Auto6.Dso.Core.Decode;
using Uestc.Auto6.Dso.ComModel;
using Uni_Trend.MSO7000X.Language;
using Uni_Trend.MSO7000X.Common.Helper;
using Uni_Trend.MSO7000X.UserControls;
using System;
using System.Linq;
namespace Uestc.Auto6.Dso.Protocol.CANFD
{
public partial class CANFDSetControl : UserControl, IProtocolView
{
#region 属性定义
protected new Boolean DesignMode
{
get
{
Boolean rtnflag = false;
#if DEBUG
rtnflag = DesignTimeHelper.InDesignMode(this);
#endif
return rtnflag;
}
}
public CANFDDecodePrsnt DestinDecodePrsnt
{
get => _DestinDecodePrsnt;
set
{
if (_DestinDecodePrsnt != value)
{
_DestinDecodePrsnt = value;
///当有新的同步目标时,应先将目标中参数同步到本地属性中
if (_CANFDDecodePrsnt != null && value != null)
{
typeof(CANFDDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
{
x.SetValue(_CANFDDecodePrsnt, x.GetValue(value));
});
}
}
}
}
private CANFDDecodePrsnt _DestinDecodePrsnt;
private CANFDDecodePrsnt _CANFDDecodePrsnt => Presenter as CANFDDecodePrsnt;
public IProtocolPrsnt Presenter { get; set; }
private FloatForm _FloatForm;
#endregion 属性定义
public CANFDSetControl()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Init();
}
private void Init()
{
GetDestinPrsnt();
}
///
/// 获取需要同步的Prsnt
/// 当为时表示不需要与其他Prsnt进行同步
///
private void GetDestinPrsnt()
{
}
///
/// 同步两个Prsnt
///
/// 属性名称
private void DecodeSynchronization(String propertyName)
{
if (DestinDecodePrsnt == null)
return;
///由于使用了进行判断具体同步的目标
///因此参数不进行同步
if (propertyName == nameof(I2CDecodePrsnt.SDA))
return;
if (String.IsNullOrEmpty(propertyName))
{
typeof(I2CDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
{
x.SetValue(DestinDecodePrsnt, x.GetValue(_CANFDDecodePrsnt));
});
}
else
{
PropertyInfo propertyInfo = typeof(CANFDDecodePrsnt).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
if (propertyInfo != null)
propertyInfo.SetValue(DestinDecodePrsnt, propertyInfo.GetValue(_CANFDDecodePrsnt));
}
}
public void UpdateView(String propertyName)
{
DecodeSynchronization(propertyName);
if (String.IsNullOrEmpty(propertyName))
{
UpdateView();
return;
}
}
private void UpdateView()
{
this.GetType().GetMethods().Where(x => x.GetCustomAttribute() != null).ToList().ForEach(x => x?.Invoke(this, null));
this.Refresh();
}
}
}