You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.9 KiB
78 lines
2.9 KiB
using Application.Domain.Entities;
|
|
using Hangfire;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Email;
|
|
using Infrastructure.Sms;
|
|
using Infrastructure.UI;
|
|
using IoT.UI.Shard;
|
|
using IoTCenter.Services;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IoTCenter
|
|
{
|
|
public class Startup : IoTServiceStartup
|
|
{
|
|
private readonly IWebHostEnvironment _env;
|
|
|
|
public Startup(IConfiguration configuration, IWebHostEnvironment env) : base(configuration, env)
|
|
{
|
|
this._env = env;
|
|
}
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddTransient<IEmailSender, EmptyEmailSender>();
|
|
services.AddTransient<ISmsSender, EmptySmsSender>();
|
|
services.AddTransient<IoTCenterJob>();
|
|
base.ConfigureServices(services);
|
|
}
|
|
|
|
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
|
|
{
|
|
base.Configure(app, env, loggerFactory);
|
|
//
|
|
Task.Run(() =>
|
|
{
|
|
using var scope = app.ApplicationServices.CreateScope();
|
|
var timerRepo = scope.ServiceProvider.GetService<IRepository<IoTTimer>>();
|
|
var timers = timerRepo.ReadOnlyTable().Where(o => o.NodeId == null).ToList();
|
|
foreach (var timer in timers)
|
|
{
|
|
RecurringJob.AddOrUpdate<IoTCenterJob>(timer.Id.ToString(), o => o.TimerHanle(timer.Id), timer.Cron, TimeZoneInfo.Local);
|
|
}
|
|
var tiggerRepo = scope.ServiceProvider.GetService<IRepository<IoTTigger>>();
|
|
var tiggers = tiggerRepo.ReadOnlyTable().Where(o => o.NodeId == null).ToList();
|
|
foreach (var tigger in tiggers)
|
|
{
|
|
IoTCenterEventHandler.Tiggers.TryAdd(tigger.Id, tigger);
|
|
}
|
|
});
|
|
}
|
|
|
|
public override void ConfigureOptions(IServiceCollection services)
|
|
{
|
|
Console.WriteLine(IoT.Resources.Resource.WebFolder);
|
|
services.ConfigureOptions(new FileConfigureOptions(_env, new List<string> { "IoT.Shared", "IoT.Resources" }));
|
|
}
|
|
|
|
public override void UseSignalR(IEndpointRouteBuilder endpoints)
|
|
{
|
|
this.UseSignalR<IoTCenterHub>(endpoints);
|
|
}
|
|
|
|
public override void Seed(DbContext dbContext, IServiceProvider serviceProvider, IConfiguration configuration)
|
|
{
|
|
base.Seed(dbContext, serviceProvider, configuration);
|
|
}
|
|
}
|
|
} |