-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathIndex.cshtml.cs
More file actions
52 lines (43 loc) · 1.57 KB
/
Index.cshtml.cs
File metadata and controls
52 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
namespace KK.DotNet.BackgroundTasks.Scheduled.Sample.Web.Pages
{
using System.Threading.Tasks;
using KK.DotNet.BackgroundTasks.Scheduled.Sample.Web.Backgroundservices;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
public class IndexModel : PageModel
{
private readonly ILogger<RuntimeSampleTask> runtimeSampleTaskLogger;
public Scheduler Scheduler { get; }
[BindProperty]
public ScheduledTaskOptions<RuntimeSampleTask> Options { get; set; }
// When using the default SchedulerHostedService than there is also a Scheduler
// this can be used to get access to the scheduled task list for example
public IndexModel(
Scheduler scheduler,
ILogger<RuntimeSampleTask> runtimeSampleTaskLogger
)
{
this.Scheduler = scheduler;
this.runtimeSampleTaskLogger = runtimeSampleTaskLogger;
this.Options = new ScheduledTaskOptions<RuntimeSampleTask>()
{
Name = "Awesome Runntime Task",
Schedule = "*/15 * * * *"
};
}
public void OnGet()
{
//this.Scheduler.SchedulerTasks;
}
public IActionResult OnPost()
{
if (!this.ModelState.IsValid)
{
return this.Page();
}
this.Scheduler.AddTask(new RuntimeSampleTask(this.Options, this.runtimeSampleTaskLogger));
return this.Page();
}
}
}