Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Right To Left Culture .net5 issue #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/Hangfire.Console/Dashboard/ConsoleRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static class ConsoleRenderer
private static readonly Regex LinkDetector = new Regex(@"
\b(?:(?<schema>(?:f|ht)tps?://)|www\.|ftp\.)
(?:\([-\w+&@#/%=~|$?!:,.]*\)|[-\w+&@#/%=~|$?!:,.])*
(?:\([-\w+&@#/%=~|$?!:,.]*\)|[\w+&@#/%=~|$])",
(?:\([-\w+&@#/%=~|$?!:,.]*\)|[\w+&@#/%=~|$])",
RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Compiled);

private class DummyPage : RazorPage
Expand All @@ -41,7 +41,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))
Expand Down Expand Up @@ -136,7 +136,7 @@ public static void RenderLines(StringBuilder builder, IEnumerable<ConsoleLine> l
RenderLine(builder, line, timestamp);
}
}

/// <summary>
/// Fetches and renders console line buffer.
/// </summary>
Expand All @@ -155,11 +155,37 @@ public static void RenderLineBuffer(StringBuilder builder, IConsoleStorage stora

var items = ReadLines(storage, consoleId, ref start);

#if NETSTANDARD2_0
FixRightToLeftNumberFormat();
#endif

builder.AppendFormat("<div class=\"line-buffer\" data-n=\"{1}\">", consoleId, start);
RenderLines(builder, items, consoleId.DateValue);
builder.Append("</div>");
}

#if NETSTANDARD2_0
/// <summary>
/// Making sure that -1 will not be sent to UI 1-, this issue appears in net5 and above.
/// </summary>
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

/// <summary>
/// Fetches console lines from storage.
/// </summary>
Expand All @@ -182,7 +208,7 @@ private static IEnumerable<ConsoleLine> ReadLines(IConsoleStorage storage, Conso
// has some new items to fetch

Dictionary<string, ConsoleLine> progressBars = null;

foreach (var entry in storage.GetLines(consoleId, start, count - 1))
{
if (entry.ProgressValue.HasValue)
Expand Down
2 changes: 1 addition & 1 deletion src/Hangfire.Console/Hangfire.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyTitle>Hangfire.Console</AssemblyTitle>
<VersionPrefix>1.4.2</VersionPrefix>
<Authors>Alexey Skalozub</Authors>
<TargetFrameworks>netstandard1.3;net45</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard1.3;net45</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Hangfire.Console</AssemblyName>
Expand Down