SATASetControl.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System.Reflection;
  2. using System.Windows.Forms;
  3. using Uestc.Auto6.Dso.Core;
  4. using Uestc.Auto6.Dso.Core.Decode;
  5. using Uestc.Auto6.Dso.ComModel;
  6. using Uni_Trend.MSO7000X.Language;
  7. using Uni_Trend.MSO7000X.Common.Helper;
  8. using Uni_Trend.MSO7000X.UserControls;
  9. using System;
  10. using System.Linq;
  11. namespace Uestc.Auto6.Dso.Protocol.SATA
  12. {
  13. public partial class SATASetControl : UserControl, IProtocolView
  14. {
  15. #region 属性定义
  16. protected new Boolean DesignMode
  17. {
  18. get
  19. {
  20. Boolean rtnflag = false;
  21. #if DEBUG
  22. rtnflag = DesignTimeHelper.InDesignMode(this);
  23. #endif
  24. return rtnflag;
  25. }
  26. }
  27. public SATADecodePrsnt DestinDecodePrsnt
  28. {
  29. get => _DestinDecodePrsnt;
  30. set
  31. {
  32. if (_DestinDecodePrsnt != value)
  33. {
  34. _DestinDecodePrsnt = value;
  35. ///当有新的同步目标时,应先将目标中参数同步到本地<see cref="I2CDecodePrsnt"/>属性中
  36. if (_SATADecodePrsnt != null && value != null)
  37. {
  38. typeof(SATADecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
  39. {
  40. x.SetValue(_SATADecodePrsnt, x.GetValue(value));
  41. });
  42. }
  43. }
  44. }
  45. }
  46. private SATADecodePrsnt _DestinDecodePrsnt;
  47. private SATADecodePrsnt _SATADecodePrsnt => Presenter as SATADecodePrsnt;
  48. public IProtocolPrsnt Presenter { get; set; }
  49. private FloatForm _FloatForm;
  50. #endregion 属性定义
  51. public SATASetControl()
  52. {
  53. InitializeComponent();
  54. }
  55. protected override void OnLoad(EventArgs e)
  56. {
  57. base.OnLoad(e);
  58. Init();
  59. }
  60. private void Init()
  61. {
  62. GetDestinPrsnt();
  63. }
  64. /// <summary>
  65. /// 获取需要同步的Prsnt
  66. /// 当<see cref="_SATADecodePrsnt"/>为<see cref="null"/>时表示不需要与其他Prsnt进行同步
  67. /// </summary>
  68. private void GetDestinPrsnt()
  69. {
  70. }
  71. /// <summary>
  72. /// 同步两个Prsnt
  73. /// </summary>
  74. /// <param name="propertyName">属性名称</param>
  75. private void DecodeSynchronization(String propertyName)
  76. {
  77. if (DestinDecodePrsnt == null)
  78. return;
  79. ///由于使用了<see cref="ISATADecodePrsnt.SDA"/>进行判断具体同步的目标
  80. ///因此<see cref="ISATADecodePrsnt.SDA"/>参数不进行同步
  81. if (propertyName == nameof(I2CDecodePrsnt.SDA))
  82. return;
  83. if (String.IsNullOrEmpty(propertyName))
  84. {
  85. typeof(I2CDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
  86. {
  87. x.SetValue(DestinDecodePrsnt, x.GetValue(_SATADecodePrsnt));
  88. });
  89. }
  90. else
  91. {
  92. PropertyInfo propertyInfo = typeof(SATADecodePrsnt).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
  93. if (propertyInfo != null)
  94. propertyInfo.SetValue(DestinDecodePrsnt, propertyInfo.GetValue(_SATADecodePrsnt));
  95. }
  96. }
  97. public void UpdateView(String propertyName)
  98. {
  99. DecodeSynchronization(propertyName);
  100. if (String.IsNullOrEmpty(propertyName))
  101. {
  102. UpdateView();
  103. return;
  104. }
  105. }
  106. private void UpdateView()
  107. {
  108. this.GetType().GetMethods().Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
  109. this.Refresh();
  110. }
  111. }
  112. }