代码拉取完成,页面将自动刷新
using IoTSharp.Gateways.Data;
using IoTSharp.Gateways.Jobs;
using IoTSharp.MqttSdk;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Quartz;
using System.Configuration;
namespace IoTSharp.Gateways
{
public class Program
{
public static void Main(string[] args)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount=false)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddRazorPages();
builder.Services.AddMemoryCache();
builder.Services.AddSingleton<MQTTClient>()
.Configure<MqttSettings>(builder.Configuration)
.AddHostedService<MqttClientHost>();
builder.Services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionJobFactory();
var SystemInfoJobKey = new JobKey("SystemInfoJob");
q.AddJob<SystemInfoJob>(SystemInfoJobKey);
q.AddTrigger(opts => opts
.ForJob(SystemInfoJobKey)
.WithIdentity("SystemInfoJob-trigger")
.WithSimpleSchedule(x => x
.WithIntervalInMinutes(1)
.RepeatForever()).StartNow());
var ModbusSchedulerJobKey = new JobKey("ModbusSchedulerJob");
q.AddJob<SchedulerJob>(opts => opts.WithIdentity(ModbusSchedulerJobKey));
q.AddTrigger(opts => opts
.ForJob(ModbusSchedulerJobKey)
.WithIdentity("ModbusSchedulerJob-trigger")
.WithSimpleSchedule(x => x
.WithIntervalInMinutes(1)
.RepeatForever()).StartNow());
// base quartz scheduler, job and trigger configuration
});
// ASP.NET Core hosting
builder.Services.AddQuartzServer(options =>
{
options.StartDelay = TimeSpan.FromSeconds(10);
// when shutting down we want jobs to complete gracefully
options.WaitForJobsToComplete = true;
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。