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

#7895: Hangfire Dashboard does not know job names of missing assemblies #1715

Open
wants to merge 2 commits into
base: main
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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# - Section names should be unique on each level.

# Don't edit manually! Use `build.bat version` command instead!
version: 1.7.11-build-0{build}
version: 1.7.12-build-0{build}

os: Visual Studio 2019

Expand Down
42 changes: 42 additions & 0 deletions src/Hangfire.Core/Common/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
Expand Down Expand Up @@ -228,5 +229,46 @@ private static Type TypeResolver(Assembly assembly, string typeName, bool ignore
assembly = assembly ?? typeof(int).GetTypeInfo().Assembly;
return assembly.GetType(typeName, true, ignoreCase);
}

#region Text

public const string AssemblySeparator = ", ";
public const char NamespaceSeparator = '.';
public const char GenericArgumentsEnd = ']';
public const string GenericArgumentSeparator = ", ";
public const char MemberSeparator = '.';

public static void Split(string type, out string @namespace, out string name, out string assembly)
{
if (string.IsNullOrWhiteSpace(type))
@namespace = name = assembly = null;
else
{
// assembly
int index = type.IndexOf(GenericArgumentsEnd) + 1; // after generic arguments
index = type.IndexOf(AssemblySeparator, index);
if (index >= 0)
{
assembly = type.Substring(index + AssemblySeparator.Length);
type = type.Substring(0, index);
}
else
assembly = null;
// namespace/name
index = type.LastIndexOf(NamespaceSeparator);
if (index >= 0)
{
@namespace = type.Substring(0, index);
name = type.Substring(index + 1);
}
else
{
@namespace = null;
name = type;
}
}
}

#endregion
}
}
12 changes: 8 additions & 4 deletions src/Hangfire.Core/Dashboard/HtmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using Hangfire.Annotations;
using Hangfire.Dashboard.Pages;
using Hangfire.Dashboard.Resources;
using Hangfire.Storage;

namespace Hangfire.Dashboard
{
Expand Down Expand Up @@ -126,11 +127,14 @@ public NonEscapedString JobId(string jobId, bool shorten = true)
: $"#{jobId}"));
}

public string JobName(Job job)
public string JobName(Job job, InvocationData invocationData)
{
if (job == null)
{
return Strings.Common_CannotFindTargetMethod;
string name = invocationData?.TypeMethodName;
return name is null ?
Strings.Common_CannotFindTargetMethod :
$"({name})";
}

var jobDisplayNameAttribute = job.Method.GetCustomAttribute<JobDisplayNameAttribute>();
Expand Down Expand Up @@ -194,9 +198,9 @@ public NonEscapedString JobIdLink(string jobId)
return Raw($"<a href=\"{HtmlEncode(_page.Url.JobDetails(jobId))}\">{JobId(jobId)}</a>");
}

public NonEscapedString JobNameLink(string jobId, Job job)
public NonEscapedString JobNameLink(string jobId, Job job, InvocationData invocationData)
{
return Raw($"<a class=\"job-method\" href=\"{HtmlEncode(_page.Url.JobDetails(jobId))}\">{HtmlEncode(JobName(job))}</a>");
return Raw($"<a class=\"job-method\" href=\"{HtmlEncode(_page.Url.JobDetails(jobId))}\">{HtmlEncode(JobName(job, invocationData))}</a>");
}

public NonEscapedString RelativeTime(DateTime value)
Expand Down
Loading