private static string SerializeWriteData(ISeriesPoint data) { if (data.Fields.Count != data.Values.Count) { throw new Exception("Invalid field series point - number of fields does not match number of values."); } var result = data.Name.Replace(",", "\\,").Replace(" ", "\\ "); if (data.Tags != null && data.Tags.Count > 0) { foreach (var kvp in data.Tags) { result += "," + kvp.Key + "=" + kvp.Value; } } result += " "; var separatorNeeded = false; for (int i = 0; i < data.Fields.Count; ++i) { string strRep; var value = data.Values[i]; if (value == null) { continue; } else if (value is double) { strRep = ((double)value).ToString(".0##############"); } else if (value is float) { strRep = ((float)value).ToString(".0######"); } else if (value is decimal || value is Int16 || value is Int32 || value is Int64 || value is UInt16 || value is UInt32 || value is UInt64) { strRep = string.Format("{0}", value); } else if (value is bool) { strRep = ((bool)value) ? "t" : "f"; } else { strRep = string.Format("\"{0}\"", string.Format("{0}", value).Replace("\"", "\\\"")); } if (separatorNeeded) { result += ","; } else { separatorNeeded = true; } result += data.Fields[i] + "=" + strRep; } if (data.Timestamp.HasValue) { result += string.Format(" {0}", ToUnixTimeNanoseconds(data.Timestamp.Value)); } return result; }
public async Task WriteAsync(ISeriesPoint data) { await WriteAsync(SerializeWriteData(data)); }