AdysTech.InfluxDB.Client.Net.InfluxDBException.ProcessInfluxDBError C# (CSharp) Метод

ProcessInfluxDBError() публичный статический Метод

public static ProcessInfluxDBError ( string InfluxError ) : InfluxDBException
InfluxError string
Результат InfluxDBException
        public static InfluxDBException ProcessInfluxDBError (string InfluxError)
        {
            var parts = _errorLinePattern.Match (InfluxError)?.Groups;
            //incase of points writes, Influx Error contains whole line protocol string. This needs to be removed to make error message readable.
            var reason = parts?[1]?.ToString ();
            if (reason.Contains ("'"))
            {
                var n = reason.IndexOf ("'");
                reason = reason.Substring (n, reason.LastIndexOf ("'") - n);
            }
            var message = (parts?[2]?.ToString ());
            if (message.Contains ("\\\""))
                message = message.Replace ("\\\"", "'");
            return new InfluxDBException (reason, message);
        }
    }

Usage Example

Пример #1
0
        /// <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);
            }
        }
All Usage Examples Of AdysTech.InfluxDB.Client.Net.InfluxDBException::ProcessInfluxDBError