コード例 #1
0
        public static async Task <string> Format(IEnumerable <MetricFamily> metrics, NewLineFormat newLine)
        {
            await using var memoryStream = new MemoryStream();
            await Write(memoryStream, metrics, newLine);

            return(Encoding.GetString(memoryStream.ToArray()));
        }
コード例 #2
0
 private string GetNewLineChar(NewLineFormat newLine)
 {
     return(newLine switch
     {
         NewLineFormat.Auto => Environment.NewLine,
         NewLineFormat.Windows => "\r\n",
         NewLineFormat.Unix or NewLineFormat.Default => "\n",
         _ => throw new ArgumentOutOfRangeException(nameof(newLine), newLine, null),
     });
コード例 #3
0
        internal static string Format(IEnumerable <MetricFamily> metrics, NewLineFormat newLine)
        {
            var newLineChar   = GetNewLineChar(newLine);
            var metricFamilys = metrics.ToArray();
            var s             = new StringBuilder();

            foreach (var metricFamily in metricFamilys)
            {
                s.Append(WriteFamily(metricFamily, newLineChar));
            }

            return(s.ToString());
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.FormatOptions"/> class.
        /// </summary>
        /// <remarks>
        /// Creates a new set of formatting options for use with methods such as
        /// <see cref="MimeMessage.WriteTo(System.IO.Stream,System.Threading.CancellationToken)"/>.
        /// </remarks>
        public FormatOptions()
        {
            HiddenHeaders = new HashSet <HeaderId> ();
            //maxLineLength = DefaultMaxLineLength;
            WriteHeaders = true;

            if (Environment.NewLine.Length == 1)
            {
                newLineFormat = NewLineFormat.Unix;
            }
            else
            {
                newLineFormat = NewLineFormat.Dos;
            }
        }
コード例 #5
0
 public static string FormatNewLine(string text, NewLineFormat newLineFormat = NewLineFormat.WindowsDefault)
 {
     try
     {
         string[] sa = Enum.GetValues(typeof(NewLineFormat)).Cast <NewLineFormat>().Select(c => (int)c == -1 ? null : $"{(char)c.GetHashCode()}").ToArray();
         string   f  = (int)newLineFormat == -1 ? Environment.NewLine : $"{(char)newLineFormat.GetHashCode()}";
         string   s  = text.Replace(Environment.NewLine, $"{(char)NewLineFormat.LineFeed}");
         return(string.Join(f, s.Split(sa, StringSplitOptions.None)));
     }
     catch (Exception ex)
     {
         Log.Debug(ex);
         return(text);
     }
 }
コード例 #6
0
ファイル: FormatOptions.cs プロジェクト: youprofit/MimeKit
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.FormatOptions"/> class.
        /// </summary>
        /// <remarks>
        /// Creates a new set of formatting options for use with methods such as
        /// <see cref="MimeMessage.WriteTo(System.IO.Stream,System.Threading.CancellationToken)"/>.
        /// </remarks>
        public FormatOptions()
        {
            HiddenHeaders = new HashSet <HeaderId> ();
            //maxLineLength = DefaultMaxLineLength;
            allowMixedHeaderCharsets = true;
            international            = false;

            if (Environment.NewLine.Length == 1)
            {
                newLineFormat = NewLineFormat.Unix;
            }
            else
            {
                newLineFormat = NewLineFormat.Dos;
            }
        }
コード例 #7
0
ファイル: FormatOptions.cs プロジェクト: vnmcosta/MimeKit
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.FormatOptions"/> class.
        /// </summary>
        /// <remarks>
        /// Creates a new set of formatting options for use with methods such as
        /// <see cref="MimeMessage.WriteTo(System.IO.Stream,System.Threading.CancellationToken)"/>.
        /// </remarks>
        public FormatOptions()
        {
            HiddenHeaders           = new HashSet <HeaderId> ();
            parameterEncodingMethod = ParameterEncodingMethod.Rfc2231;
            //maxLineLength = DefaultMaxLineLength;
            allowMixedHeaderCharsets = false;
            international            = false;

            if (Environment.NewLine.Length == 1)
            {
                newLineFormat = NewLineFormat.Unix;
            }
            else
            {
                newLineFormat = NewLineFormat.Dos;
            }
        }
コード例 #8
0
        private static string GetNewLineChar(NewLineFormat newLine)
        {
            switch (newLine)
            {
            case NewLineFormat.Auto:
                return(Environment.NewLine);

            case NewLineFormat.Windows:
                return("\r\n");

            case NewLineFormat.Unix:
            case NewLineFormat.Default:
                return("\n");

            default:
                throw new ArgumentOutOfRangeException(nameof(newLine), newLine, null);
            }
        }
コード例 #9
0
 public PrometheusFormatter(
     Encoding encoding,
     NewLineFormat newLineFormat,
     IApdexFormatter apdexFormatter,
     ICounterFormatter counterFormatter,
     IGaugeFormatter gaugeFormatter,
     IHistogramFormatter histogramFormatter,
     IMeterFormatter meterFormatter,
     ITimerFormatter timerFormatter)
 {
     _encoding           = encoding;
     _newLineFormat      = newLineFormat;
     _apdexFormatter     = apdexFormatter;
     _counterFormatter   = counterFormatter;
     _gaugeFormatter     = gaugeFormatter;
     _histogramFormatter = histogramFormatter;
     _meterFormatter     = meterFormatter;
     _timerFormatter     = timerFormatter;
 }
コード例 #10
0
        public static async Task Write(Stream destination, IEnumerable <MetricFamily> metrics, NewLineFormat newLine)
        {
            var metricFamilies = metrics.ToArray();

#if NETSTANDARD2_1
            await using var streamWriter = new StreamWriter(destination, Encoding, bufferSize: 1024, leaveOpen: true)
                        {
                            NewLine = GetNewLineChar(newLine)
                        };
#else
            using var streamWriter = new StreamWriter(destination, Encoding, bufferSize: 1024, leaveOpen: true)
                  {
                      NewLine = GetNewLineChar(newLine)
                  };
#endif
            foreach (var metricFamily in metricFamilies)
            {
                await WriteFamily(streamWriter, metricFamily);
            }

            await streamWriter.FlushAsync();
        }
コード例 #11
0
ファイル: FormatOptions.cs プロジェクト: gphummer/MimeKit
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.FormatOptions"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new set of formatting options for use with methods such as
		/// <see cref="MimeMessage.WriteTo(System.IO.Stream,System.Threading.CancellationToken)"/>.
		/// </remarks>
		public FormatOptions ()
		{
			HiddenHeaders = new HashSet<HeaderId> ();
			//maxLineLength = DefaultMaxLineLength;
			WriteHeaders = true;

			if (Environment.NewLine.Length == 1)
				newLineFormat = NewLineFormat.Unix;
			else
				newLineFormat = NewLineFormat.Dos;
		}
コード例 #12
0
ファイル: FormatOptions.cs プロジェクト: surekqomi/MimeKit
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.FormatOptions"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new set of formatting options for use with methods such as
		/// <see cref="MimeMessage.WriteTo(System.IO.Stream,System.Threading.CancellationToken)"/>.
		/// </remarks>
		public FormatOptions ()
		{
			HiddenHeaders = new HashSet<HeaderId> ();
			parameterEncodingMethod = ParameterEncodingMethod.Rfc2231;
			//maxLineLength = DefaultMaxLineLength;
			allowMixedHeaderCharsets = false;
			international = false;

			if (Environment.NewLine.Length == 1)
				newLineFormat = NewLineFormat.Unix;
			else
				newLineFormat = NewLineFormat.Dos;
		}
コード例 #13
0
        static void AssertMboxResults(string baseName, string actual, Stream output, List <MimeParserOffset> offsets, NewLineFormat newLineFormat)
        {
            // WORKAROUND: Mono's iso-2022-jp decoder breaks on this input in versions <= 3.2.3 but is fixed in 3.2.4+
            string iso2022jp = Encoding.GetEncoding("iso-2022-jp").GetString(Convert.FromBase64String("GyRAOjRGI0stGyhK"));

            if (iso2022jp != "佐藤豊")
            {
                actual = actual.Replace(iso2022jp, "佐藤豊");
            }

            var path = Path.Combine(MboxDataDir, baseName + "-summary.txt");

            if (!File.Exists(path))
            {
                File.WriteAllText(path, actual);
            }

            var summary = File.ReadAllText(path).Replace("\r\n", "\n");
            var expected = new byte[4096];
            var buffer = new byte[4096];
            int nx, n;

            Assert.AreEqual(summary, actual, "Summaries do not match for {0}.mbox", baseName);

            using (var original = File.OpenRead(Path.Combine(MboxDataDir, baseName + ".mbox.txt"))) {
                output.Position = 0;

                Assert.AreEqual(original.Length, output.Length, "The length of the mbox did not match.");

                do
                {
                    var position = original.Position;

                    nx = original.Read(expected, 0, expected.Length);
                    n  = output.Read(buffer, 0, nx);

                    if (nx == 0)
                    {
                        break;
                    }

                    for (int i = 0; i < nx; i++)
                    {
                        if (buffer[i] == expected[i])
                        {
                            continue;
                        }

                        var strExpected = CharsetUtils.Latin1.GetString(expected, 0, nx);
                        var strActual   = CharsetUtils.Latin1.GetString(buffer, 0, n);

                        Assert.AreEqual(strExpected, strActual, "The mbox differs at position {0}", position + i);
                    }
                } while (true);
            }

            path = Path.Combine(MboxDataDir, baseName + "." + newLineFormat.ToString().ToLowerInvariant() + "-offsets.txt");
            if (!File.Exists(path))
            {
                using (var writer = new StreamWriter(path)) {
                    foreach (var offset in offsets)
                    {
                        writer.WriteLine($"{offset.Location} {offset.Offset}");
                    }
                }
            }

            n = 0;
            foreach (var offset in EnumerateMimeParserOffsets(path))
            {
                Assert.AreEqual(offset.Location, offsets[n].Location, $"Offset Location #{n}");
                Assert.AreEqual(offset.Offset, offsets[n].Offset, $"Stream Offset #{n} ({offset.Location})");
                n++;
            }
        }
コード例 #14
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.FormatOptions"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new set of formatting options for use with methods such as
		/// <see cref="MimeMessage.WriteTo(System.IO.Stream,System.Threading.CancellationToken)"/>.
		/// </remarks>
		public FormatOptions ()
		{
			HiddenHeaders = new HashSet<HeaderId> ();
			//maxLineLength = DefaultMaxLineLength;
			allowMixedHeaderCharsets = true;
			international = false;

			if (Environment.NewLine.Length == 1)
				newLineFormat = NewLineFormat.Unix;
			else
				newLineFormat = NewLineFormat.Dos;
		}
コード例 #15
0
ファイル: AsciiFormatter.cs プロジェクト: y2ket/Prometheus
        public static async Task Write(Stream destination, IEnumerable <MetricFamily> metrics, NewLineFormat newLine)
        {
            var metricFamilies = metrics.ToArray();

            using (var streamWriter = new StreamWriter(destination, Encoding)
            {
                NewLine = GetNewLineChar(newLine)
            })
            {
                foreach (var metricFamily in metricFamilies)
                {
                    WriteFamily(streamWriter, metricFamily);
                }

                await streamWriter.FlushAsync();
            }
        }