Skip to content

Commit

Permalink
Update to .NET 7
Browse files Browse the repository at this point in the history
  • Loading branch information
henkmollema committed Nov 9, 2022
1 parent a624dfe commit 6007941
Show file tree
Hide file tree
Showing 17 changed files with 483 additions and 494 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '{build}'
pull_requests:
do_not_increment_build_number: true
image: Visual Studio 2019
image: Visual Studio 2022
nuget:
disable_publish_on_pr: true
build_script:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: csharp
mono: none
dotnet: 5.0
dotnet: 7.0
dist: xenial
env:
global:
Expand Down
47 changes: 23 additions & 24 deletions src/Webenable.Hangfire.Contrib/AutoScheduleAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
using System;

namespace Webenable.Hangfire.Contrib
namespace Webenable.Hangfire.Contrib;

/// <summary>
/// Specifies that the job should be automatically scheduled in Hangfire
/// using the specified <see cref="MethodName"/> and <see cref="CronExpression"/>.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class AutoScheduleAttribute : Attribute
{
/// <summary>
/// Specifies that the job should be automatically scheduled in Hangfire
/// using the specified <see cref="MethodName"/> and <see cref="CronExpression"/>.
/// using the specified <paramref name="methodName"/> and <paramref name="cronExpression"/>.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class AutoScheduleAttribute : Attribute
/// <param name="methodName">The name of the method to invoke the job with.</param>
/// <param name="cronExpression">The CRON expression to schedule the job with.</param>
public AutoScheduleAttribute(string methodName, string cronExpression)
{
/// <summary>
/// Specifies that the job should be automatically scheduled in Hangfire
/// using the specified <paramref name="methodName"/> and <paramref name="cronExpression"/>.
/// </summary>
/// <param name="methodName">The name of the method to invoke the job with.</param>
/// <param name="cronExpression">The CRON expression to schedule the job with.</param>
public AutoScheduleAttribute(string methodName, string cronExpression)
{
MethodName = methodName;
CronExpression = cronExpression;
}
MethodName = methodName;
CronExpression = cronExpression;
}

/// <summary>
/// Gets the name of the method to invoke the job with.
/// </summary>
public string MethodName { get; }
/// <summary>
/// Gets the name of the method to invoke the job with.
/// </summary>
public string MethodName { get; }

/// <summary>
/// Gets the CRON expression to schedule the job with.
/// </summary>
public string CronExpression { get; }
}
/// <summary>
/// Gets the CRON expression to schedule the job with.
/// </summary>
public string CronExpression { get; }
}
57 changes: 28 additions & 29 deletions src/Webenable.Hangfire.Contrib/Crons.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
namespace Webenable.Hangfire.Contrib
namespace Webenable.Hangfire.Contrib;

/// <summary>
/// Contains constant CRON expressions for convenience use in <see cref="AutoScheduleAttribute"/>.
/// </summary>
public static class Crons
{
/// <summary>
/// Contains constant CRON expressions for convenience use in <see cref="AutoScheduleAttribute"/>.
/// Every minute.
/// </summary>
public static class Crons
{
/// <summary>
/// Every minute.
/// </summary>
public const string Minutely = "* * * * *";
public const string Minutely = "* * * * *";

/// <summary>
/// Every hour.
/// </summary>
public const string Hourly = "0 * * * *";
/// <summary>
/// Every hour.
/// </summary>
public const string Hourly = "0 * * * *";

/// <summary>
/// Every day at 00:00.
/// </summary>
public const string Daily = "0 0 * * *";
/// <summary>
/// Every day at 00:00.
/// </summary>
public const string Daily = "0 0 * * *";

/// <summary>
/// Every Monday at 00:00.
/// </summary>
public const string Weekly = "0 0 * * 1";
/// <summary>
/// Every Monday at 00:00.
/// </summary>
public const string Weekly = "0 0 * * 1";

/// <summary>
/// Every first day of the month at 00:00.
/// </summary>
public const string Monthly = "0 0 1 * *";
/// <summary>
/// Every first day of the month at 00:00.
/// </summary>
public const string Monthly = "0 0 1 * *";

/// <summary>
/// Every year on January 1st at 00:00.
/// </summary>
public const string Yearly = "0 0 1 1 *";
}
/// <summary>
/// Every year on January 1st at 00:00.
/// </summary>
public const string Yearly = "0 0 1 1 *";
}
69 changes: 34 additions & 35 deletions src/Webenable.Hangfire.Contrib/HangfireContribOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,54 @@
using System.Reflection;
using Microsoft.AspNetCore.Http;

namespace Webenable.Hangfire.Contrib
namespace Webenable.Hangfire.Contrib;

/// <summary>
/// Defines options for the Hangfire contrib extensions.
/// </summary>
public class HangfireContribOptions
{
/// <summary>
/// Defines options for the Hangfire contrib extensions.
/// Gets or sets a value indicating whether the Hangfire background server should be enabled.
/// </summary>
public bool EnableServer { get; set; }

/// <summary>
/// Gets or sets the assemblies used to scan for job types.
/// By default the entry assembly of the application.
/// </summary>
public Assembly[] ScanningAssemblies { get; set; } = Array.Empty<Assembly>();

/// <summary>
/// Gets or sets options for the Hangfire dashboard.
/// </summary>
public DasbhoardOptions Dasbhoard { get; set; } = new DasbhoardOptions();

/// <summary>
/// Defines options for the Hangfire dashboard.
/// </summary>
public class HangfireContribOptions
public class DasbhoardOptions
{
/// <summary>
/// Gets or sets a value indicating whether the Hangfire background server should be enabled.
/// Gets or sets a value indicating whether the Hangfire dashboard should be enabled.
/// </summary>
public bool EnableServer { get; set; }
public bool Enabled { get; set; }

/// <summary>
/// Gets or sets the assemblies used to scan for job types.
/// By default the entry assembly of the application.
/// Gets or sets a value indicating whether the Hangfire dashboard IP-based authorization filter should be enabled.
/// </summary>
public Assembly[] ScanningAssemblies { get; set; } = Array.Empty<Assembly>();
public bool EnableAuthorization { get; set; }

/// <summary>
/// Gets or sets options for the Hangfire dashboard.
/// Gets or sets a callback which gets invoked when authorizing a dashboard request.
/// If not specified, the default authorization polcy is IP-based using <see cref="AllowedIps"/> when IP-addresses are specified.
/// </summary>
public DasbhoardOptions Dasbhoard { get; set; } = new DasbhoardOptions();
public Func<HttpContext, bool>? AuthorizationCallback { get; set; }

/// <summary>
/// Defines options for the Hangfire dashboard.
/// Gets or sets the collection of IP-addresses which are allowed to access the Hangfire dashboard.
/// This is the default authorization policy.
/// </summary>
public class DasbhoardOptions
{
/// <summary>
/// Gets or sets a value indicating whether the Hangfire dashboard should be enabled.
/// </summary>
public bool Enabled { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the Hangfire dashboard IP-based authorization filter should be enabled.
/// </summary>
public bool EnableAuthorization { get; set; }

/// <summary>
/// Gets or sets a callback which gets invoked when authorizing a dashboard request.
/// If not specified, the default authorization polcy is IP-based using <see cref="AllowedIps"/> when IP-addresses are specified.
/// </summary>
public Func<HttpContext, bool>? AuthorizationCallback { get; set; }

/// <summary>
/// Gets or sets the collection of IP-addresses which are allowed to access the Hangfire dashboard.
/// This is the default authorization policy.
/// </summary>
public string[]? AllowedIps { get; set; }
}
public string[]? AllowedIps { get; set; }
}
}
32 changes: 15 additions & 17 deletions src/Webenable.Hangfire.Contrib/HangfireExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@
using Microsoft.Extensions.Logging;
using Webenable.Hangfire.Contrib.Internal;

namespace Webenable.Hangfire.Contrib
namespace Webenable.Hangfire.Contrib;

/// <summary>
/// Extensions for logging in Hangfire jobs.
/// </summary>
public static class HangfireExtensions
{
/// <summary>
/// Extensions for logging in Hangfire jobs.
/// Begins a logical operation scope for the given <see cref="PerformContext"/> within the scope of a job.
/// </summary>
public static class HangfireExtensions
{
/// <summary>
/// Begins a logical operation scope for the given <see cref="PerformContext"/> within the scope of a job.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> instance.</param>
/// <param name="performContext">The <see cref="PerformContext"/> instance for the job.</param>
public static IDisposable BeginJobScope(this ILogger logger, PerformContext performContext) =>
performContext != null ? logger.BeginScope(new PerformContextWrapper(performContext)) : NoopDisposable.Instance;
/// <param name="logger">The <see cref="ILogger"/> instance.</param>
/// <param name="performContext">The <see cref="PerformContext"/> instance for the job.</param>
public static IDisposable BeginJobScope(this ILogger logger, PerformContext performContext) =>
performContext != null ? logger.BeginScope(new PerformContextWrapper(performContext))! : NoopDisposable.Instance;

private class NoopDisposable : IDisposable
{
public static NoopDisposable Instance = new();

private class NoopDisposable : IDisposable
public void Dispose()
{
public static NoopDisposable Instance = new();

public void Dispose()
{
}
}
}
}
Loading

0 comments on commit 6007941

Please sign in to comment.