/// <summary> /// Convert to DomainObject. /// </summary> public T ConvertToEntity <T>(FluxRecord fluxRecord) { if (typeof(T) != typeof(DomainEntity)) { throw new NotSupportedException($"This converter doesn't supports: {typeof(DomainEntity)}"); } var customEntity = new DomainEntity { SeriesId = Guid.Parse(Convert.ToString(fluxRecord.GetValueByKey("series_id")) !), Value = Convert.ToDouble(fluxRecord.GetValueByKey("data")), Timestamp = fluxRecord.GetTime().GetValueOrDefault().ToDateTimeUtc(), Properties = new List <DomainEntityAttribute>() }; foreach (var(key, value) in fluxRecord.Values) { if (key.StartsWith("property_")) { var attribute = new DomainEntityAttribute { Name = key.Replace("property_", string.Empty), Value = Convert.ToInt32(value) }; customEntity.Properties.Add(attribute); } } return((T)Convert.ChangeType(customEntity, typeof(T))); }
static public double GetData(FluxRecord record, string key) { if (record.GetField() == key) { return(Convert.ToDouble(record.GetValue())); } return(double.NaN); }
/// <summary> /// Maps FluxRecord into custom POCO class. /// </summary> /// <param name="record">the Flux record</param> /// <typeparam name="T">the POCO type</typeparam> /// <returns></returns> /// <exception cref="InfluxException"></exception> internal T ToPoco <T>(FluxRecord record) { Arguments.CheckNotNull(record, "Record is required"); try { var type = typeof(T); var poco = (T)Activator.CreateInstance(type); // copy record to case insensitive dictionary (do this once) var recordValues = new Dictionary <string, object>(record.Values, StringComparer.InvariantCultureIgnoreCase); var properties = _attributesCache.GetProperties(type); foreach (var property in properties) { var attribute = _attributesCache.GetAttribute(property); if (attribute != null && attribute.IsTimestamp) { SetFieldValue(poco, property, record.GetTime()); } else { var columnName = _attributesCache.GetColumnName(attribute, property); string col = null; if (recordValues.ContainsKey(columnName)) { col = columnName; } else if (recordValues.ContainsKey("_" + columnName)) { col = "_" + columnName; } if (!string.IsNullOrEmpty(col)) { // No need to set field value when column does not exist (default poco field value will be the same) if (recordValues.TryGetValue(col, out var value)) { SetFieldValue(poco, property, value); } } } } return(poco); } catch (Exception e) { throw new InfluxException(e); } }
public void MapByColumnName() { var fluxRecord = new FluxRecord(0); fluxRecord.Values["host"] = "aws.north.1"; fluxRecord.Values["region"] = "carolina"; var poco = _parser.ToPoco <PocoDifferentNameProperty>(fluxRecord); Assert.AreEqual("aws.north.1", poco.Host); Assert.AreEqual("carolina", poco.DifferentName); }
private TModel ParseRowToModel(FluxRecord record) { TModel model = new TModel { Time = record.GetTimeInDateTime().Value }; foreach (KeyValuePair <string, object> pair in record.Values) { this.SetPropertyOfModel(model, pair); } return(model); }
private FluxRecord ParseRecord(int tableIndex, FluxTable table, CsvReader csv) { var record = new FluxRecord(tableIndex); foreach (var fluxColumn in table.Columns) { var columnName = fluxColumn.Label; var strValue = csv[fluxColumn.Index + 1]; record.Values.Add(columnName, ToValue(strValue, fluxColumn)); } return(record); }
/// <summary> /// Convert to DomainObject. /// </summary> public T ConvertToEntity <T>(FluxRecord fluxRecord) { if (typeof(T) != typeof(Sensor)) { throw new NotSupportedException($"This converter doesn't supports: {typeof(T)}"); } var customEntity = new Sensor { Type = Convert.ToString(fluxRecord.GetValueByKey("type")), Version = Convert.ToString(fluxRecord.GetValueByKey("version")), Value = Convert.ToDouble(fluxRecord.GetValueByKey("data")), Timestamp = fluxRecord.GetTime().GetValueOrDefault().ToDateTimeUtc(), }; return((T)Convert.ChangeType(customEntity, typeof(T))); }
private List <TModel> ParseData(List <FluxTable> fluxTables) { List <TModel> models = new List <TModel>(); PropertyInfo[] listofProperties = typeof(TModel).GetProperties(); fluxTables.ForEach(fluxTable => { List <FluxRecord> fluxRecords = fluxTable.Records; for (int i = 0; i < fluxTable.Records.Count; i++) { FluxRecord record = fluxTable.Records[i]; TModel model = this.ParseRowToModel(record); models.Add(model); } }); return(models); }
public void MapTimestampDifferentName() { var now = DateTime.UtcNow; var fluxRecord = new FluxRecord(0); fluxRecord.Values["tag"] = "production"; fluxRecord.Values["min"] = 10.5; fluxRecord.Values["max"] = 20.0; fluxRecord.Values["avg"] = (Double)18; fluxRecord.Values["_time"] = Instant.FromDateTimeUtc(now); var poco = _parser.ToPoco <PointWithoutTimestampName>(fluxRecord); Assert.AreEqual("production", poco.Tag); Assert.AreEqual(10.5, poco.Minimum); Assert.AreEqual(20, poco.Maximum); Assert.AreEqual(18, poco.Average); Assert.AreEqual(now, poco.Timestamp); }
public void Accept(int index, ICancellable cancellable, FluxRecord record) { _onNext(cancellable, record); }
public void Accept(int index, ICancellable cancellable, FluxRecord record) { _onNext(cancellable, Mapper.ToPoco <T>(record)); }
/// <summary> /// Maps FluxRecord into custom POCO class. /// </summary> /// <param name="record">the Flux record</param> /// <typeparam name="T">the POCO type</typeparam> /// <returns></returns> /// <exception cref="InfluxException"></exception> internal T ToPoco <T>(FluxRecord record) { Arguments.CheckNotNull(record, "Record is required"); try { var type = typeof(T); var poco = (T)Activator.CreateInstance(type); var properties = type.GetProperties(); foreach (var property in properties) { var attributes = property.GetCustomAttributes(typeof(Column), false); Column attribute = null; if (attributes.Length > 0) { attribute = (Column)attributes.First(); } var columnName = property.Name; if (attribute != null && !string.IsNullOrEmpty(attribute.Name)) { columnName = attribute.Name; } // copy record to case insensitive dictionary var recordValues = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase); foreach (var entry in record.Values) { recordValues.Add(entry.Key, entry.Value); } string col = null; if (recordValues.ContainsKey(columnName)) { col = columnName; } else if (recordValues.ContainsKey("_" + columnName)) { col = "_" + columnName; } if (!string.IsNullOrEmpty(col)) { recordValues.TryGetValue(col, out var value); SetFieldValue(poco, property, value); } } return(poco); } catch (Exception e) { throw new InfluxException(e); } }
public T ConvertToEntity <T>(FluxRecord fluxRecord) { return(ToPoco <T>(fluxRecord)); }
public void Accept(int index, ICancellable cancellable, FluxRecord record) { _onNext(cancellable, _converter.ConvertToEntity <T>(record)); }
public QueryCompleteEventArgs(FluxRecord result) { Result = result; }
public void Accept(int index, ICancellable cancellable, FluxRecord record) { Tables[index].Records.Add(record); }
public void Accept(int index, ICancellable cancellable, FluxRecord record) { AcceptRecord(record); }
public T ConvertToEntity <T>(FluxRecord fluxRecord) { return(_resultMapper.ToPoco <T>(fluxRecord)); }