Skip to content

Commit 03f83d3

Browse files
committed
Add project files.
1 parent d94f3d4 commit 03f83d3

File tree

70 files changed

+25036
-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.

70 files changed

+25036
-0
lines changed

QuartzWithCore.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28729.10
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuartzWithCore", "QuartzWithCore\QuartzWithCore.csproj", "{362C27F1-8955-43C1-8EF1-0AAF9798E658}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowSteps", "WorkflowSteps\WorkflowSteps.csproj", "{0FA72B33-E377-4604-8A0A-CF7D01384B7F}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{362C27F1-8955-43C1-8EF1-0AAF9798E658}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{362C27F1-8955-43C1-8EF1-0AAF9798E658}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{362C27F1-8955-43C1-8EF1-0AAF9798E658}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{362C27F1-8955-43C1-8EF1-0AAF9798E658}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{0FA72B33-E377-4604-8A0A-CF7D01384B7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{0FA72B33-E377-4604-8A0A-CF7D01384B7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{0FA72B33-E377-4604-8A0A-CF7D01384B7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{0FA72B33-E377-4604-8A0A-CF7D01384B7F}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {75DC2088-EC0C-437C-B8A9-875D28FDBE9A}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Quartz;
3+
using QuartzWithCore.Models;
4+
using QuartzWithCore.Tasks;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Diagnostics;
8+
using System.Threading.Tasks;
9+
using WorkflowSteps.Tasks;
10+
11+
namespace QuartzWithCore.Controllers
12+
{
13+
public class HomeController : Controller
14+
{
15+
private readonly IScheduler _scheduler;
16+
17+
public HomeController(IScheduler factory)
18+
{
19+
_scheduler = factory;
20+
}
21+
22+
public IActionResult Index()
23+
{
24+
return View();
25+
}
26+
27+
public async Task<IActionResult> CheckAvailability(int intervalinSec = 5)
28+
{
29+
ITrigger trigger = TriggerBuilder.Create()
30+
.WithIdentity($"Check Availability-{DateTime.Now}")
31+
.StartNow()
32+
.WithSimpleSchedule(scheduleBuilder =>
33+
scheduleBuilder
34+
.WithIntervalInSeconds(intervalinSec)
35+
.RepeatForever())
36+
.Build();
37+
38+
IDictionary<string, object> map = new Dictionary<string, object>()
39+
{
40+
{"Current Date Time", $"{DateTime.Now}" },
41+
{"Tickets needed", $"5" },
42+
{"Concert Name", $"Rock" }
43+
};
44+
45+
IJobDetail job = JobBuilder.Create<SchedueleJob>()
46+
.WithIdentity($"Check Availability#{intervalinSec}-{DateTime.Now}")
47+
.SetJobData(new JobDataMap(map))
48+
.Build();
49+
50+
//Finally schedule the job
51+
await _scheduler.ScheduleJob(job, trigger);
52+
return RedirectToAction("Index");
53+
}
54+
55+
public async Task<IActionResult> CheckAvailabilityV1()
56+
{
57+
ITrigger trigger = TriggerBuilder.Create()
58+
.WithIdentity($"Check Availability 1-{DateTime.Now}")
59+
.StartAt(new DateTimeOffset(DateTime.Now.AddSeconds(15)))
60+
.WithPriority(1)
61+
.Build();
62+
63+
IDictionary<string, object> map = new Dictionary<string, object>()
64+
{
65+
{"Current Date Time", $"{DateTime.Now}" },
66+
{"Tickets needed", $"5" },
67+
{"Concert Name", $"Rock" }
68+
};
69+
70+
IJobDetail job = JobBuilder.Create<CheckAvailabilityTask>()
71+
//.WithIdentity("Check Availability")
72+
.WithIdentity($"Check Availability 1-{DateTime.Now}")
73+
.SetJobData(new JobDataMap(map))
74+
.Build();
75+
76+
77+
await _scheduler.ScheduleJob(job, trigger);
78+
return RedirectToAction("Index");
79+
}
80+
81+
public async Task<IActionResult> ReserveTickets()
82+
{
83+
ITrigger trigger = TriggerBuilder.Create()
84+
.WithIdentity($"Reserve Tickets-{DateTime.Now}")
85+
.StartNow()
86+
.WithPriority(1)
87+
.Build();
88+
89+
IDictionary<string, object> map = new Dictionary<string, object>()
90+
{
91+
};
92+
93+
IJobDetail job = JobBuilder.Create<ReserveTicketsTask>()
94+
.WithIdentity($"Reserve Tickets:{DateTime.Now.Ticks}")
95+
.SetJobData(new JobDataMap(map))
96+
.Build();
97+
98+
await _scheduler.ScheduleJob(job, trigger);
99+
return RedirectToAction("Index");
100+
}
101+
102+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
103+
public IActionResult Error()
104+
{
105+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
106+
}
107+
}
108+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace QuartzWithCore.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}

QuartzWithCore/Program.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace QuartzWithCore
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
CreateWebHostBuilder(args).Build().Run();
18+
}
19+
20+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
22+
.UseStartup<Startup>();
23+
}
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:52552/",
7+
"sslPort": 44351
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"QuartzWithCore": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
25+
}
26+
}
27+
}

QuartzWithCore/QuartzWithCore.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.App" />
9+
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
10+
<PackageReference Include="Quartz" Version="3.0.7" />
11+
<PackageReference Include="Quartz.Serialization.Json" Version="3.0.6" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\WorkflowSteps\WorkflowSteps.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

QuartzWithCore/Startup.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.Http;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Logging;
8+
using Quartz;
9+
using Quartz.Impl;
10+
using System.Collections.Specialized;
11+
using System.Threading.Tasks;
12+
using WorkflowSteps;
13+
14+
namespace QuartzWithCore
15+
{
16+
public class Startup
17+
{
18+
public Startup(IConfiguration configuration)
19+
{
20+
Configuration = configuration;
21+
}
22+
23+
public IConfiguration Configuration { get; }
24+
25+
// This method gets called by the runtime. Use this method to add services to the container.
26+
public void ConfigureServices(IServiceCollection services)
27+
{
28+
services.Configure<CookiePolicyOptions>(options =>
29+
{
30+
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
31+
options.CheckConsentNeeded = context => true;
32+
options.MinimumSameSitePolicy = SameSiteMode.None;
33+
});
34+
35+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
36+
services.AddSingleton(provider => GetScheduler().Result);
37+
services.AddSingleton<GetPriceStep>();
38+
services.AddSingleton<ReserveTickets>();
39+
services.AddSingleton<PrintReceiptStep>();
40+
}
41+
42+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
43+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
44+
{
45+
if (env.IsDevelopment())
46+
{
47+
app.UseDeveloperExceptionPage();
48+
}
49+
else
50+
{
51+
app.UseExceptionHandler("/Home/Error");
52+
app.UseHsts();
53+
}
54+
55+
app.UseHttpsRedirection();
56+
app.UseStaticFiles();
57+
app.UseCookiePolicy();
58+
59+
app.UseMvc(routes =>
60+
{
61+
routes.MapRoute(
62+
name: "default",
63+
template: "{controller=Home}/{action=Index}/{id?}");
64+
});
65+
}
66+
67+
private async Task<IScheduler> GetScheduler()
68+
{
69+
var properties = new NameValueCollection
70+
{
71+
{ "quartz.scheduler.instanceName", "QuartzWithCore" },
72+
{ "quartz.scheduler.instanceId", "QuartzWithCore" },
73+
{ "quartz.jobStore.type", "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" },
74+
{ "quartz.jobStore.useProperties", "true" },
75+
{ "quartz.jobStore.dataSource", "default" },
76+
{ "quartz.jobStore.tablePrefix", "QRTZ_" },
77+
{
78+
"quartz.dataSource.default.connectionString",
79+
"Server=(localdb)\\MSSQLLocalDB;Initial Catalog=quartz;integrated security=True;Trusted_Connection=True;"
80+
},
81+
{ "quartz.dataSource.default.provider", "SqlServer" },
82+
{ "quartz.threadPool.threadCount", "1" },
83+
{ "quartz.serializer.type", "json" },
84+
};
85+
var schedulerFactory = new StdSchedulerFactory(properties);
86+
var scheduler = await schedulerFactory.GetScheduler();
87+
//await scheduler.Start();
88+
return scheduler;
89+
}
90+
}
91+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Quartz;
2+
using System;
3+
using System.Diagnostics;
4+
using System.Threading.Tasks;
5+
6+
namespace QuartzWithCore.Tasks
7+
{
8+
public class CheckAvailabilityTask : IJob
9+
{
10+
public Task Execute(IJobExecutionContext context)
11+
12+
{
13+
var jobKey = context.JobDetail.Key;
14+
Debug.WriteLine($"Hello - executed at {DateTime.Now} | jobKey- {jobKey}");
15+
try
16+
{
17+
var dataMap = context.JobDetail.JobDataMap;
18+
var timeRequested = dataMap.GetDateTime("Current Date Time");
19+
var ticketsNeeded = dataMap.GetInt("Tickets needed");
20+
var concertName = dataMap.GetString("Concert Name");
21+
Debug.WriteLine($"{ticketsNeeded} Tickets to the {concertName} concert on {timeRequested.ToString("MM-dd-yyyy")} are available");
22+
}
23+
catch (Exception ex)
24+
{
25+
Console.WriteLine(ex);
26+
}
27+
return Task.FromResult(0);
28+
}
29+
}
30+
}

QuartzWithCore/Tasks/SheduleJob.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Quartz;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace QuartzWithCore.Tasks
9+
{
10+
public class SchedueleJob : IJob
11+
{
12+
public Task Execute(IJobExecutionContext context)
13+
{
14+
var jobKey = context.JobDetail.Key;
15+
Debug.WriteLine($"Hello - executed at {DateTime.Now} | jobKey- {jobKey}");
16+
return Task.FromResult(0);
17+
}
18+
}
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@{
2+
ViewData["Title"] = "About";
3+
}
4+
<h2>@ViewData["Title"]</h2>
5+
<h3>@ViewData["Message"]</h3>
6+
7+
<p>Use this area to provide additional information.</p>

0 commit comments

Comments
 (0)