Beispiel #1
0
        public void Write(TextWriter textWriter, bool writeTimestamp = true)
        {
            if (textWriter == null)
            {
                throw new ArgumentNullException(nameof(textWriter));
            }

            WriteCommon(textWriter);

            var fieldDelim = ' ';

            using (var nameEnumerator = FieldsNames.GetEnumerator())
                using (var valueEnumerator = FieldsValues.GetEnumerator())
                {
                    while (nameEnumerator.MoveNext() && valueEnumerator.MoveNext())
                    {
                        var name  = nameEnumerator.Current;
                        var value = valueEnumerator.Current;

                        textWriter.Write(fieldDelim);
                        fieldDelim = ',';
                        textWriter.Write(LineProtocolSyntax.EscapeName(name));
                        textWriter.Write('=');
                        textWriter.Write(LineProtocolSyntax.FormatValue(value));
                    }
                }

            if (!writeTimestamp)
            {
                return;
            }

            WriteTimestamp(textWriter);
        }
Beispiel #2
0
        /// <summary>
        /// Writes the timestamp using the most precise unit.
        /// </summary>
        /// <param name="textWriter">Writer to write the values to.</param>
        protected void WriteTimestamp(TextWriter textWriter)
        {
            textWriter.Write(' ');

            if (UtcTimestamp == null)
            {
                textWriter.Write(LineProtocolSyntax.FormatTimestamp(DateTime.UtcNow));
                return;
            }

            textWriter.Write(LineProtocolSyntax.FormatTimestamp(UtcTimestamp.Value));
        }
Beispiel #3
0
        /// <summary>
        /// Writes the timestamp using the most precise unit.
        /// </summary>
        /// <param name="textWriter">Writer to write the values to.</param>
        protected async ValueTask WriteTimestampAsync(TextWriter textWriter)
        {
            await textWriter.WriteAsync(' ');

            if (UtcTimestamp == null)
            {
                await textWriter.WriteAsync(LineProtocolSyntax.FormatTimestamp(DateTime.UtcNow));

                return;
            }

            await textWriter.WriteAsync(LineProtocolSyntax.FormatTimestamp(UtcTimestamp.Value));
        }
Beispiel #4
0
        /// <summary>
        /// Writes the common properties of the line procol points, which includes writing the measurement name and the different tags.
        /// </summary>
        /// <param name="textWriter">Writer to write the values to.</param>
        protected void WriteCommon(TextWriter textWriter)
        {
            textWriter.Write(LineProtocolSyntax.EscapeName(Measurement));

            if (Tags.Count > 0)
            {
                for (var i = 0; i < Tags.Count; i++)
                {
                    textWriter.Write(',');
                    textWriter.Write(LineProtocolSyntax.EscapeName(Tags.Keys[i]));
                    textWriter.Write('=');
                    textWriter.Write(LineProtocolSyntax.EscapeName(Tags.Values[i]));
                }
            }
        }
        public void Write(TextWriter textWriter, bool writeTimestamp = true)
        {
            if (textWriter == null)
            {
                throw new ArgumentNullException(nameof(textWriter));
            }

            textWriter.Write(LineProtocolSyntax.EscapeName(Measurement));

            if (Tags.Count > 0)
            {
                for (var i = 0; i < Tags.Count; i++)
                {
                    textWriter.Write(',');
                    textWriter.Write(LineProtocolSyntax.EscapeName(Tags.Keys[i]));
                    textWriter.Write('=');
                    textWriter.Write(LineProtocolSyntax.EscapeName(Tags.Values[i]));
                }
            }

            var fieldDelim = ' ';

            foreach (var f in Fields)
            {
                textWriter.Write(fieldDelim);
                fieldDelim = ',';
                textWriter.Write(LineProtocolSyntax.EscapeName(f.Key));
                textWriter.Write('=');
                textWriter.Write(LineProtocolSyntax.FormatValue(f.Value));
            }

            if (!writeTimestamp)
            {
                return;
            }

            textWriter.Write(' ');

            if (UtcTimestamp == null)
            {
                textWriter.Write(LineProtocolSyntax.FormatTimestamp(DateTime.UtcNow));
                return;
            }

            textWriter.Write(LineProtocolSyntax.FormatTimestamp(UtcTimestamp.Value));
        }
Beispiel #6
0
        /// <summary>
        /// Writes the common properties of the line procol points, which includes writing the measurement name and the different tags.
        /// </summary>
        /// <param name="textWriter">Writer to write the values to.</param>
        protected async ValueTask WriteCommonAsync(TextWriter textWriter)
        {
            await textWriter.WriteAsync(LineProtocolSyntax.EscapeName(Measurement));

            if (Tags.Count > 0)
            {
                for (var i = 0; i < Tags.Count; i++)
                {
                    await textWriter.WriteAsync(',');

                    await textWriter.WriteAsync(LineProtocolSyntax.EscapeName(Tags.Keys[i]));

                    await textWriter.WriteAsync('=');

                    await textWriter.WriteAsync(LineProtocolSyntax.EscapeName(Tags.Values[i]));
                }
            }
        }
Beispiel #7
0
        public void Write(TextWriter textWriter, bool writeTimestamp = true)
        {
            if (textWriter == null)
            {
                throw new ArgumentNullException(nameof(textWriter));
            }

            WriteCommon(textWriter);

            textWriter.Write(' ');
            textWriter.Write(LineProtocolSyntax.EscapeName(FieldName));
            textWriter.Write('=');
            textWriter.Write(LineProtocolSyntax.FormatValue(FieldValue));

            if (!writeTimestamp)
            {
                return;
            }

            WriteTimestamp(textWriter);
        }
Beispiel #8
0
        public async ValueTask WriteAsync(TextWriter textWriter, bool writeTimestamp = true)
        {
            if (textWriter == null)
            {
                throw new ArgumentNullException(nameof(textWriter));
            }

            await WriteCommonAsync(textWriter);

            var fieldDelim = ' ';

            using (var nameEnumerator = FieldsNames.GetEnumerator())
            {
                using var valueEnumerator = FieldsValues.GetEnumerator();
                while (nameEnumerator.MoveNext() && valueEnumerator.MoveNext())
                {
                    var name  = nameEnumerator.Current;
                    var value = valueEnumerator.Current;

                    await textWriter.WriteAsync(fieldDelim);

                    fieldDelim = ',';
                    await textWriter.WriteAsync(LineProtocolSyntax.EscapeName(name));

                    await textWriter.WriteAsync('=');

                    await textWriter.WriteAsync(LineProtocolSyntax.FormatValue(value));
                }
            }

            if (!writeTimestamp)
            {
                return;
            }

            await WriteTimestampAsync(textWriter);
        }
        public async ValueTask WriteAsync(TextWriter textWriter, bool writeTimestamp = true)
        {
            if (textWriter == null)
            {
                throw new ArgumentNullException(nameof(textWriter));
            }

            await WriteCommonAsync(textWriter);

            await textWriter.WriteAsync(' ');

            await textWriter.WriteAsync(LineProtocolSyntax.EscapeName(FieldName));

            await textWriter.WriteAsync('=');

            await textWriter.WriteAsync(LineProtocolSyntax.FormatValue(FieldValue));

            if (!writeTimestamp)
            {
                return;
            }

            await WriteTimestampAsync(textWriter);
        }