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())); }
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), });
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()); }
/// <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; } }
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); } }
/// <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; } }
/// <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; } }
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); } }
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; }
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(); }
/// <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; }
/// <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; }
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++; } }
/// <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; }
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(); } }