Commit 5505ace5 authored by Nick Craver's avatar Nick Craver

Mono - simplify, change ordering

Let's see if this is a race...I'm still unable to run locally, though.
parent 4212ddeb
...@@ -194,7 +194,7 @@ internal void OnErrorMessage(EndPoint endpoint, string message) ...@@ -194,7 +194,7 @@ internal void OnErrorMessage(EndPoint endpoint, string message)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
private static void Write<T>(ZipArchive zip, string name, Task task, Action<T, StreamWriter> callback) private static void Write<T>(ZipArchive zip, string name, Task task, Action<T, StreamWriter> callback)
{ {
var entry = zip.CreateEntry(name, PlatformHelper.GetCompressionLevel(nameof(CompressionLevel.Optimal))); var entry = zip.CreateEntry(name, CompressionLevel.Optimal);
using (var stream = entry.Open()) using (var stream = entry.Open())
using (var writer = new StreamWriter(stream)) using (var writer = new StreamWriter(stream))
{ {
......
using System; using System;
using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Net.Security;
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
internal class PlatformHelper internal class PlatformHelper
{ {
public static SocketMode DefaultSocketMode = IsMono && IsUnix ? SocketMode.Async : SocketMode.Poll; public static SocketMode DefaultSocketMode => IsMono && IsUnix ? SocketMode.Async : SocketMode.Poll;
public static bool IsMono { get; } = Type.GetType("Mono.Runtime") != null; public static bool IsMono => Type.GetType("Mono.Runtime") != null;
public static bool IsUnix { get; } = (int)Environment.OSVersion.Platform == 4 public static bool IsUnix => (int)Environment.OSVersion.Platform == 4
|| (int)Environment.OSVersion.Platform == 6 || (int)Environment.OSVersion.Platform == 6
|| (int)Environment.OSVersion.Platform == 128; || (int)Environment.OSVersion.Platform == 128;
/// <summary>
/// Gets the compression level from a string, avoiding a naming bug inside ancient mono versions.
/// </summary>
/// <remarks>
/// See: https://github.com/mono/mono/commit/714efcf7d1f9c9017b370af16bb3117179dd60e5
/// </remarks>
/// <param name="level">The level.</param>
/// <returns></returns>
public static CompressionLevel GetCompressionLevel(string level)
{
try
{
return (CompressionLevel)Enum.Parse(typeof(CompressionLevel), level);
}
catch (ArgumentException)
{
// Oops, ancient mono here.. let's tray again.
return (CompressionLevel)Enum.Parse(typeof(CompressionLevel), level.Replace(nameof(CompressionLevel.Optimal), "Optional"));
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment