AdysTech.InfluxDB.Client.Net.InfluxDBClient.PostPointAsync C# (CSharp) Метод

PostPointAsync() публичный Метод

Posts an InfluxDataPoint to given measurement
When Influx needs authentication, and no user name password is supplied or auth fails all other HTTP exceptions
public PostPointAsync ( string dbName, IInfluxDatapoint point ) : Task
dbName string InfluxDB database name
point IInfluxDatapoint Influx data point to be written
Результат Task
        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;
            }
        }

Usage Example

        public async Task TestPostPointAsync_InvalidReq()
        {
            var client = new InfluxDBClient (influxUrl, dbUName, dbpwd);
            var time = DateTime.Now;
            var today = DateTime.Now.ToShortDateString ();
            var now = DateTime.Now.ToShortTimeString ();

            var valDouble = new InfluxDatapoint<double> ();
            valDouble.UtcTimestamp = DateTime.UtcNow;
            valDouble.Tags.Add ("TestDate", today);
            valDouble.Tags.Add ("TestTime", now);
            valDouble.Fields.Add ("Doublefield", DataGen.RandomDouble ());
            valDouble.Fields.Add ("Doublefield2", Double.NaN);
            valDouble.MeasurementName = measurementName;
            valDouble.Precision = TimePrecision.Seconds;

            var r = await client.PostPointAsync (dbName, valDouble);
            Assert.IsTrue (r, "PostPointsAsync retunred false");

        }
All Usage Examples Of AdysTech.InfluxDB.Client.Net.InfluxDBClient::PostPointAsync