コード例 #1
0
        public void Render(TextWriter textWriter)
        {
            if (textWriter == null)
            {
                throw new ArgumentNullException(nameof(textWriter));
            }

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

            if (_tags != null)
            {
                foreach (KeyValuePair <string, string> tag in _tags.OrderBy(t => t.Key))
                {
                    if (string.IsNullOrEmpty(tag.Value))
                    {
                        continue;
                    }

                    textWriter.Write(',');
                    textWriter.Write(LineProtocolSyntax.EscapeName(tag.Key));
                    textWriter.Write('=');
                    textWriter.Write(LineProtocolSyntax.EscapeName(tag.Value));
                }
            }

            char fieldDelim = ' ';

            foreach (KeyValuePair <string, object> field in _fields)
            {
                textWriter.Write(fieldDelim);
                fieldDelim = ',';
                textWriter.Write(LineProtocolSyntax.EscapeName(field.Key));
                textWriter.Write('=');
                textWriter.Write(LineProtocolSyntax.FormatValue(field.Value));
            }

            if (_utcTimestamp != null)
            {
                textWriter.Write(' ');
                textWriter.Write(LineProtocolSyntax.FormatTimestamp(_utcTimestamp.Value));
            }
        }
コード例 #2
0
        public void Can_format_timestamp()
        {
            var dateTime = new DateTime(2017, 01, 01, 1, 1, 1, DateTimeKind.Utc);

            LineProtocolSyntax.FormatTimestamp(dateTime).Should().Be("1483232461000000000");
        }