EndPointConfigItem.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace MECF.Framework.Common.CommonData
  9. {
  10. public class EndPointConfigItem : INotifyPropertyChanged
  11. {
  12. public event PropertyChangedEventHandler PropertyChanged;
  13. public void InvokePropertyChanged(string propertyName)
  14. {
  15. if (PropertyChanged != null)
  16. {
  17. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  18. }
  19. }
  20. public void InvokePropertyChanged()
  21. {
  22. Type t = this.GetType();
  23. var ps = t.GetProperties();
  24. foreach (var p in ps)
  25. {
  26. InvokePropertyChanged(p.Name);
  27. }
  28. }
  29. public string ExposureTime { get; set; }
  30. public string WaveLengthA { get; set; }
  31. public string BinningA { get; set; }
  32. public string WaveLengthB { get; set; }
  33. public string BinningB { get; set; }
  34. public string WaveLengthC { get; set; }
  35. public string BinningC { get; set; }
  36. public string WaveLengthD { get; set; }
  37. public string BinningD { get; set; }
  38. public string Fd { get; set; }
  39. public string PrefilterTime { get; set; }
  40. public string PostfilterTime { get; set; }
  41. public string AlgorithmType { get; set; }
  42. public string Criteria { get; set; }
  43. public string DelayTime { get; set; }
  44. public string ValidationTime { get; set; }
  45. public string ValidationValue { get; set; }
  46. public string TimeWindow { get; set; }
  47. public string MinimalTime { get; set; }
  48. public string PostponeTime { get; set; }
  49. public bool Control { get; set; }
  50. public bool Normalization { get; set; }
  51. public bool EnablePostponePercent { get; set; }
  52. public bool EnableCriterialPercent { get; set; }
  53. public bool EnableEventTrigger { get; set; }
  54. public bool IsFaultIfNoTrigger { get; set; }
  55. public string ToValue()
  56. {
  57. return
  58. $@"ExposureTime={ExposureTime};WaveLengthA={WaveLengthA};BinningA={BinningA};WaveLengthB={WaveLengthB};" +
  59. $@"BinningB={BinningB};WaveLengthC={WaveLengthC};BinningC={BinningC};WaveLengthD={WaveLengthD};BinningD={BinningD};Fd={Fd};" +
  60. $@"PrefilterTime={PrefilterTime};PostfilterTime={PostfilterTime};AlgorithmType={AlgorithmType};Criteria={Criteria};DelayTime={DelayTime};ValidationTime={ValidationTime};" +
  61. $@"ValidationValue={ValidationValue};TimeWindow={TimeWindow};MinimalTime={MinimalTime};PostponeTime={PostponeTime};Control={Control};Normalization={Normalization};" +
  62. $@"EnablePostponePercent={EnablePostponePercent};EnableCriterialPercent={EnableCriterialPercent};EnableEventTrigger={EnableEventTrigger};IsFaultIfNoTrigger={IsFaultIfNoTrigger};"
  63. ;
  64. }
  65. public void SetValue(string config)
  66. {
  67. string[] items = config.Split(';');
  68. foreach (var item in items)
  69. {
  70. if (string.IsNullOrEmpty(item))
  71. continue;
  72. string[] pairs = item.Split('=');
  73. if (pairs.Length != 2)
  74. continue;
  75. Parallel.ForEach(this.GetType().GetProperties(),
  76. property => {
  77. PropertyInfo pi = (PropertyInfo)property;
  78. if (pi.Name == pairs[0])
  79. {
  80. try
  81. {
  82. var convertedValue = Convert.ChangeType(pairs[1], pi.PropertyType);
  83. var originValue = Convert.ChangeType(pi.GetValue(this, null), pi.PropertyType);
  84. if (originValue != convertedValue)
  85. {
  86. pi.SetValue(this, convertedValue, null);
  87. }
  88. }
  89. catch (Exception)
  90. {
  91. }
  92. }
  93. });
  94. }
  95. }
  96. }
  97. }