/// <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)));
            }
Example #2
0
            /// <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)));
            }