From 1ae3be380c96d47f5c1591165279a9ef364f10aa Mon Sep 17 00:00:00 2001 From: Mohammad Aljaber Date: Tue, 21 Sep 2021 10:01:41 +0300 Subject: [PATCH 1/2] Fixing RightToLeft Culture .net5 issue --- .../Dashboard/ConsoleRenderer.cs | 35 ++++++++++++++++--- src/Hangfire.Console/Hangfire.Console.csproj | 2 +- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Hangfire.Console/Dashboard/ConsoleRenderer.cs b/src/Hangfire.Console/Dashboard/ConsoleRenderer.cs index 7ab2e5d..65ad920 100644 --- a/src/Hangfire.Console/Dashboard/ConsoleRenderer.cs +++ b/src/Hangfire.Console/Dashboard/ConsoleRenderer.cs @@ -8,6 +8,7 @@ using System.Globalization; using System.Text; using System.Text.RegularExpressions; +using System.Threading; namespace Hangfire.Console.Dashboard { @@ -23,7 +24,7 @@ internal static class ConsoleRenderer private static readonly Regex LinkDetector = new Regex(@" \b(?:(?(?:f|ht)tps?://)|www\.|ftp\.) (?:\([-\w+&@#/%=~|$?!:,.]*\)|[-\w+&@#/%=~|$?!:,.])* - (?:\([-\w+&@#/%=~|$?!:,.]*\)|[\w+&@#/%=~|$])", + (?:\([-\w+&@#/%=~|$?!:,.]*\)|[\w+&@#/%=~|$])", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled); private class DummyPage : RazorPage @@ -41,7 +42,7 @@ public override void Execute() public static void RenderText(StringBuilder buffer, string text) { if (string.IsNullOrEmpty(text)) return; - + var start = 0; foreach (Match m in LinkDetector.Matches(text)) @@ -136,7 +137,7 @@ public static void RenderLines(StringBuilder builder, IEnumerable l RenderLine(builder, line, timestamp); } } - + /// /// Fetches and renders console line buffer. /// @@ -155,11 +156,37 @@ public static void RenderLineBuffer(StringBuilder builder, IConsoleStorage stora var items = ReadLines(storage, consoleId, ref start); +#if NETSTANDARD2_0 + FixRightToLeftNumberFormat(); +#endif + builder.AppendFormat("
", consoleId, start); RenderLines(builder, items, consoleId.DateValue); builder.Append("
"); } +#if NETSTANDARD2_0 + /// + /// Making sure that -1 will not be sent to UI 1-, this issue appears in net5 and above. + /// + private static void FixRightToLeftNumberFormat() + { + if (CultureInfo.CurrentCulture.TextInfo.IsRightToLeft) + { + if (CultureInfo.CurrentCulture.IsReadOnly) + { + var clone = CultureInfo.CurrentCulture.Clone() as CultureInfo; + clone.NumberFormat = NumberFormatInfo.InvariantInfo; + CultureInfo.CurrentCulture = clone; + } + else + { + CultureInfo.CurrentCulture.NumberFormat = NumberFormatInfo.InvariantInfo; + } + } + } +#endif + /// /// Fetches console lines from storage. /// @@ -182,7 +209,7 @@ private static IEnumerable ReadLines(IConsoleStorage storage, Conso // has some new items to fetch Dictionary progressBars = null; - + foreach (var entry in storage.GetLines(consoleId, start, count - 1)) { if (entry.ProgressValue.HasValue) diff --git a/src/Hangfire.Console/Hangfire.Console.csproj b/src/Hangfire.Console/Hangfire.Console.csproj index 2f413a4..a45c1ce 100644 --- a/src/Hangfire.Console/Hangfire.Console.csproj +++ b/src/Hangfire.Console/Hangfire.Console.csproj @@ -4,7 +4,7 @@ Hangfire.Console 1.4.2 Alexey Skalozub - netstandard1.3;net45 + netstandard2.0;netstandard1.3;net45 true true Hangfire.Console From c1f56a954a6cf29930a35bba776675448ed4c057 Mon Sep 17 00:00:00 2001 From: Mohammad Aljaber Date: Tue, 21 Sep 2021 10:10:20 +0300 Subject: [PATCH 2/2] Trying toavoid extra changes caused by Indentation fixer --- src/Hangfire.Console/Dashboard/ConsoleRenderer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Hangfire.Console/Dashboard/ConsoleRenderer.cs b/src/Hangfire.Console/Dashboard/ConsoleRenderer.cs index 65ad920..29b543e 100644 --- a/src/Hangfire.Console/Dashboard/ConsoleRenderer.cs +++ b/src/Hangfire.Console/Dashboard/ConsoleRenderer.cs @@ -8,7 +8,6 @@ using System.Globalization; using System.Text; using System.Text.RegularExpressions; -using System.Threading; namespace Hangfire.Console.Dashboard {