/// <summary>
/// Posts an InfluxDataPoint to given measurement
/// </summary>
/// <param name="dbName">InfluxDB database name</param>
/// <param name="point">Influx data point to be written</param>
/// <returns>True:Success, False:Failure</returns>
///<exception cref="UnauthorizedAccessException">When Influx needs authentication, and no user name password is supplied or auth fails</exception>
///<exception cref="HttpRequestException">all other HTTP exceptions</exception>
public async Task <bool> PostPointAsync(string dbName, IInfluxDatapoint point)
{
ByteArrayContent requestContent = new ByteArrayContent(Encoding.UTF8.GetBytes(point.ConvertToInfluxLineProtocol()));
var endPoint = new Dictionary <string, string>()
{
{ "db", dbName },
{ "precision", precisionLiterals[(int)point.Precision] }
};
if (!String.IsNullOrWhiteSpace(point.Retention?.Name))
{
endPoint.Add("rp", point.Retention?.Name);
}
HttpResponseMessage response = await PostAsync(endPoint, requestContent);
if (response.StatusCode == HttpStatusCode.BadRequest)
{
throw InfluxDBException.ProcessInfluxDBError(await response.Content.ReadAsStringAsync());
}
else if (response.StatusCode == HttpStatusCode.NoContent)
{
point.Saved = true;
return(true);
}
else
{
point.Saved = false;
return(false);
}
}