Skip to content

Commit a288ff2

Browse files
first commit
1 parent 34772b7 commit a288ff2

File tree

73 files changed

+6394
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+6394
-0
lines changed
117 KB
Binary file not shown.

.vs/Hangfire/config/applicationhost.config

+996
Large diffs are not rendered by default.

.vs/Hangfire/v16/.suo

42.5 KB
Binary file not shown.
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Logging;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace Hangfire.Controllers
9+
{
10+
[ApiController]
11+
[Route("[controller]")]
12+
public class WeatherForecastController : ControllerBase
13+
{
14+
private static readonly string[] Summaries = new[]
15+
{
16+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
17+
};
18+
19+
private readonly ILogger<WeatherForecastController> _logger;
20+
21+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
22+
{
23+
_logger = logger;
24+
}
25+
26+
[HttpGet]
27+
public IEnumerable<WeatherForecast> Get()
28+
{
29+
var rng = new Random();
30+
//BackgroundJob.Enqueue(() => SendMessage("[email protected]"));
31+
//Console.WriteLine(DateTime.Now);
32+
//BackgroundJob.Schedule(() => SendMessage("[email protected]"),TimeSpan.FromMinutes(1));
33+
34+
RecurringJob.AddOrUpdate(() => SendMessage("[email protected]"), Cron.Minutely);
35+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
36+
{
37+
Date = DateTime.Now.AddDays(index),
38+
TemperatureC = rng.Next(-20, 55),
39+
Summary = Summaries[rng.Next(Summaries.Length)]
40+
})
41+
.ToArray();
42+
}
43+
44+
[ApiExplorerSettings(IgnoreApi = true)]
45+
public void SendMessage(string email)
46+
{
47+
Console.WriteLine(value:$"Email sent at {DateTime.Now} ");
48+
49+
}
50+
}
51+
}

Hangfire.csproj

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.33" />
9+
<PackageReference Include="Hangfire.Core" Version="1.7.33" />
10+
<PackageReference Include="Hangfire.SqlServer" Version="1.7.33" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
12+
</ItemGroup>
13+
14+
</Project>

Hangfire.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.32510.428
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hangfire", "Hangfire.csproj", "{E99BAB14-4A2D-4CEA-AD43-ABA75C655956}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E99BAB14-4A2D-4CEA-AD43-ABA75C655956}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E99BAB14-4A2D-4CEA-AD43-ABA75C655956}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E99BAB14-4A2D-4CEA-AD43-ABA75C655956}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E99BAB14-4A2D-4CEA-AD43-ABA75C655956}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B29CBF4D-6725-4C88-AF17-B124E0B01024}
24+
EndGlobalSection
25+
EndGlobal

Program.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
10+
namespace Hangfire
11+
{
12+
public class Program
13+
{
14+
public static void Main(string[] args)
15+
{
16+
CreateHostBuilder(args).Build().Run();
17+
}
18+
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.ConfigureWebHostDefaults(webBuilder =>
22+
{
23+
webBuilder.UseStartup<Startup>();
24+
});
25+
}
26+
}

Properties/launchSettings.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:55538",
8+
"sslPort": 44383
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "swagger",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"Hangfire": {
21+
"commandName": "Project",
22+
"dotnetRunMessages": "true",
23+
"launchBrowser": true,
24+
"launchUrl": "swagger",
25+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}

Startup.cs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.HttpsPolicy;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
9+
using Microsoft.OpenApi.Models;
10+
using System;
11+
using System.Collections.Generic;
12+
using System.Linq;
13+
using System.Threading.Tasks;
14+
using Hangfire;
15+
16+
namespace Hangfire
17+
{
18+
public class Startup
19+
{
20+
public Startup(IConfiguration configuration)
21+
{
22+
Configuration = configuration;
23+
}
24+
25+
public IConfiguration Configuration { get; }
26+
27+
// This method gets called by the runtime. Use this method to add services to the container.
28+
public void ConfigureServices(IServiceCollection services)
29+
{
30+
services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection")));
31+
services.AddHangfireServer();
32+
33+
services.AddControllers();
34+
services.AddSwaggerGen(c =>
35+
{
36+
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hangfire", Version = "v1" });
37+
});
38+
}
39+
40+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
41+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
42+
{
43+
if (env.IsDevelopment())
44+
{
45+
app.UseDeveloperExceptionPage();
46+
app.UseSwagger();
47+
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Hangfire v1"));
48+
}
49+
50+
51+
52+
app.UseHttpsRedirection();
53+
54+
app.UseRouting();
55+
56+
app.UseAuthorization();
57+
app.UseHangfireDashboard(pathMatch:"/dashboard");
58+
app.UseEndpoints(endpoints =>
59+
{
60+
endpoints.MapControllers();
61+
});
62+
}
63+
}
64+
}

WeatherForecast.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace Hangfire
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}

appsettings.Development.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
}
9+
}

appsettings.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*",
10+
"ConnectionStrings": {
11+
"DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database = Hangfire;Integrated Security= True"
12+
}
13+
}
27.5 KB
Binary file not shown.

bin/Debug/net5.0/Hangfire.Core.dll

1.51 MB
Binary file not shown.
324 KB
Binary file not shown.

0 commit comments

Comments
 (0)