| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 | using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;namespace MECF.Framework.Common.CommonData{    public class EndPointConfigItem : INotifyPropertyChanged    {        public event PropertyChangedEventHandler PropertyChanged;        public void InvokePropertyChanged(string propertyName)        {            if (PropertyChanged != null)            {                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));            }        }        public void InvokePropertyChanged()        {            Type t = this.GetType();            var ps = t.GetProperties();            foreach (var p in ps)            {                InvokePropertyChanged(p.Name);            }        }        public string ExposureTime { get; set; }        public string WaveLengthA { get; set; }        public string BinningA { get; set; }        public string WaveLengthB { get; set; }        public string BinningB { get; set; }        public string WaveLengthC { get; set; }        public string BinningC { get; set; }        public string WaveLengthD { get; set; }        public string BinningD { get; set; }        public string Fd { get; set; }        public string PrefilterTime { get; set; }        public string PostfilterTime { get; set; }        public string AlgorithmType { get; set; }        public string Criteria { get; set; }        public string DelayTime { get; set; }        public string ValidationTime { get; set; }        public string ValidationValue { get; set; }        public string TimeWindow { get; set; }        public string MinimalTime { get; set; }        public string PostponeTime { get; set; }        public bool Control { get; set; }        public bool Normalization { get; set; }        public bool EnablePostponePercent { get; set; }        public bool EnableCriterialPercent { get; set; }        public bool EnableEventTrigger { get; set; }        public bool IsFaultIfNoTrigger { get; set; }        public string ToValue()        {            return                $@"ExposureTime={ExposureTime};WaveLengthA={WaveLengthA};BinningA={BinningA};WaveLengthB={WaveLengthB};" +                $@"BinningB={BinningB};WaveLengthC={WaveLengthC};BinningC={BinningC};WaveLengthD={WaveLengthD};BinningD={BinningD};Fd={Fd};" +                $@"PrefilterTime={PrefilterTime};PostfilterTime={PostfilterTime};AlgorithmType={AlgorithmType};Criteria={Criteria};DelayTime={DelayTime};ValidationTime={ValidationTime};" +                $@"ValidationValue={ValidationValue};TimeWindow={TimeWindow};MinimalTime={MinimalTime};PostponeTime={PostponeTime};Control={Control};Normalization={Normalization};" +                $@"EnablePostponePercent={EnablePostponePercent};EnableCriterialPercent={EnableCriterialPercent};EnableEventTrigger={EnableEventTrigger};IsFaultIfNoTrigger={IsFaultIfNoTrigger};";        }        public void SetValue(string config)        {            string[] items = config.Split(';');            foreach (var item in items)            {                if (string.IsNullOrEmpty(item))                    continue;                string[] pairs = item.Split('=');                if (pairs.Length != 2)                    continue;                Parallel.ForEach(this.GetType().GetProperties(),                    property => {                        PropertyInfo pi = (PropertyInfo)property;                        if (pi.Name == pairs[0])                        {                            try                            {                                var convertedValue = Convert.ChangeType(pairs[1], pi.PropertyType);                                var originValue = Convert.ChangeType(pi.GetValue(this, null), pi.PropertyType);                                if (originValue != convertedValue)                                {                                    pi.SetValue(this, convertedValue, null);                                }                            }                            catch (Exception)                            {                            }                        }                    });            }        }    }}
 |