/// <summary> /// 刷新配置类的值 /// </summary> public void RefreshConfigObject() { if (ConfigClassMapper == null) { return; } try { if (ConfigClassMapper.ConfigPropertyInfo == null) { IDataConverter dataConverter = DataConverterManager.GetDataConverter(ConfigClassMapper.ConfigClassType); object value = dataConverter.Parse(ConfigClassMapper.ConfigClassType, Data); ConfigClassMapper.SetConfigClassInstance(ConfigClassMapper.ConfigClassType, value); } else { IDataConverter dataConverter = DataConverterManager.GetDataConverter(ConfigClassMapper.ConfigPropertyInfo.PropertyType); object propertyValue = dataConverter.Parse(ConfigClassMapper.ConfigPropertyInfo.PropertyType, Data); object obj = null; object oldObject = ConfigClassMapper.GetConfigClassInstance(ConfigClassMapper.ConfigClassType); if (oldObject == null) { obj = Activator.CreateInstance(ConfigClassMapper.ConfigClassType, true); } else { obj = oldObject; try { string json = JsonConvert.SerializeObject(oldObject); object newObject = JsonConvert.DeserializeObject(json, ConfigClassMapper.ConfigClassType); obj = newObject; } catch (Exception ex) { LogManager.GetLogger().Error(string.Format("RefreshConfigObject.Clone,Exception:{0}", ex)); } } ConfigClassMapper.ConfigPropertyInfo.SetValue(obj, propertyValue, null); ConfigClassMapper.SetConfigClassInstance(ConfigClassMapper.ConfigClassType, obj); } } catch (Exception ex) { LogManager.GetLogger().Error(string.Format("RefreshConfigObject,Exception:{0}", ex)); } }
/// <summary> /// This method creates a byte-Array of all received raw data /// and passes this byte-Array to the "Parse"-Method. /// </summary> public void Parse() { if (_queueReceiveRawData.Count == 0) { return; } try { byte[] newRawData = _queueReceiveRawData.ToArray(); _queueReceiveRawData.Clear(); var items = _converter.Parse(newRawData); foreach (var item in items) { _queueReceive.Enqueue(item); } } catch (Exception ex) { _logger.Error("Parse failed", ex); } }