From 764e45ace805650925e4788cd98f4034df840f96 Mon Sep 17 00:00:00 2001 From: "SSILHR\\iaftab" Date: Fri, 10 Nov 2017 12:50:42 +0500 Subject: [PATCH] -Point2 class added to support nano and micro seconds insert/get -Its responsilbility of client program to calculate the timestamp --- InfluxData.Net.Common/Constants/TimeUnit.cs | 12 ++++++++---- .../Formatters/PointFormatter.cs | 11 +++++++++-- InfluxData.Net.InfluxDb/Models/Point2.cs | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 InfluxData.Net.InfluxDb/Models/Point2.cs diff --git a/InfluxData.Net.Common/Constants/TimeUnit.cs b/InfluxData.Net.Common/Constants/TimeUnit.cs index e6a00fa..46ee941 100644 --- a/InfluxData.Net.Common/Constants/TimeUnit.cs +++ b/InfluxData.Net.Common/Constants/TimeUnit.cs @@ -5,11 +5,15 @@ namespace InfluxData.Net.Common.Constants /// public static class TimeUnit { - // NOTE: currently not supported - //public const string Nanoseconds = "n"; + /// + /// Use this value only with + /// + public const string Nanoseconds = "ns"; - // NOTE: currently not supported - //public const string Microseconds = "u"; + /// + /// Use this value only with + /// + public const string Microseconds = "u"; public const string Milliseconds = "ms"; diff --git a/InfluxData.Net.InfluxDb/Formatters/PointFormatter.cs b/InfluxData.Net.InfluxDb/Formatters/PointFormatter.cs index e71929c..810ee3e 100644 --- a/InfluxData.Net.InfluxDb/Formatters/PointFormatter.cs +++ b/InfluxData.Net.InfluxDb/Formatters/PointFormatter.cs @@ -141,9 +141,16 @@ protected virtual string FormatPointField(string key, object value) protected virtual string FormatPointTimestamp(Point point, string precision = TimeUnit.Milliseconds) { - return point.Timestamp.HasValue ? point.Timestamp.Value.ToUnixTime(precision).ToString() : string.Empty; + if(point is Point2) + { + return ((Point2)point).UnixTimeStamp.HasValue ? ((Point2)point).UnixTimeStamp.ToString() : string.Empty; + } + else + { + return point.Timestamp.HasValue ? point.Timestamp.Value.ToUnixTime(precision).ToString() : string.Empty; + } } - + protected virtual string ToInt(string result) { return $"{result}i"; diff --git a/InfluxData.Net.InfluxDb/Models/Point2.cs b/InfluxData.Net.InfluxDb/Models/Point2.cs new file mode 100644 index 0000000..3295175 --- /dev/null +++ b/InfluxData.Net.InfluxDb/Models/Point2.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace InfluxData.Net.InfluxDb.Models +{ + /// + /// Special case designed to handle UnixTimeStamp and nano seconds + /// Use this class to provide time in micro or nano seconds + /// + public class Point2 : Point + { + /// + /// Unix timestamp. Could be in nano seconds + /// If you are using Point2, then UnixTimeStamp will be used and TimeStamp will be ignored + /// + public long? UnixTimeStamp { get; set; } + } +}