-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve display of job result and properties
It's quite common that job properties and/or result are strings. Since everything is serialized as JSON in the database, a string becomes quoted and has escaped characters. For displaying in the dashboard, it's nicer without the quotes and escaped characters.
- Loading branch information
Showing
4 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
|
||
namespace Hangfire.Common | ||
{ | ||
internal static class StringExtensions | ||
{ | ||
/// <summary> | ||
/// Returns the deserialized JSON <paramref name="text"/> if the text is a serialized JSON string, | ||
/// or the specified text without any transformation if the text is not a serialized JSON string. | ||
/// </summary> | ||
/// <param name="text">The text to prettify.</param> | ||
public static string PrettyJsonString(this string text) | ||
{ | ||
if (text.StartsWith("\"", StringComparison.Ordinal)) | ||
{ | ||
try | ||
{ | ||
return SerializationHelper.Deserialize<string>(text, SerializationOption.User); | ||
} | ||
catch | ||
{ | ||
// Ignore | ||
} | ||
} | ||
|
||
return text; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters