diff --git a/src/Hangfire.Core/Common/StringExtensions.cs b/src/Hangfire.Core/Common/StringExtensions.cs new file mode 100644 index 000000000..07c8c4463 --- /dev/null +++ b/src/Hangfire.Core/Common/StringExtensions.cs @@ -0,0 +1,29 @@ +using System; + +namespace Hangfire.Common +{ + internal static class StringExtensions + { + /// + /// Returns the deserialized JSON if the text is a serialized JSON string, + /// or the specified text without any transformation if the text is not a serialized JSON string. + /// + /// The text to prettify. + public static string PrettyJsonString(this string text) + { + if (text.StartsWith("\"", StringComparison.Ordinal)) + { + try + { + return SerializationHelper.Deserialize(text, SerializationOption.User); + } + catch + { + // Ignore + } + } + + return text; + } + } +} \ No newline at end of file diff --git a/src/Hangfire.Core/Dashboard/JobHistoryRenderer.cs b/src/Hangfire.Core/Dashboard/JobHistoryRenderer.cs index a36d0a330..0176aa391 100644 --- a/src/Hangfire.Core/Dashboard/JobHistoryRenderer.cs +++ b/src/Hangfire.Core/Dashboard/JobHistoryRenderer.cs @@ -195,8 +195,8 @@ public static NonEscapedString SucceededRenderer(HtmlHelper html, IDictionaryResult:
{html.HtmlEncode(result)}
"); + var result = stateData["Result"].PrettyJsonString(); + builder.Append($"
Result:
{html.HtmlEncode(result).Replace("\n", "
")}
"); itemsAdded = true; } diff --git a/src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml b/src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml index 0137693a4..8e98278d6 100644 --- a/src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml +++ b/src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml @@ -118,7 +118,7 @@ { @parameter.Key -
@parameter.Value
+
@parameter.Value.PrettyJsonString()
} diff --git a/src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml.cs b/src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml.cs index f5e2afa7d..7b6ef6fcf 100644 --- a/src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml.cs +++ b/src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml.cs @@ -473,7 +473,7 @@ public override void Execute() #line 121 "..\..\Dashboard\Pages\JobDetailsPage.cshtml" - Write(parameter.Value); + Write(parameter.Value.PrettyJsonString()); #line default