|
|
using Application.Domain.Entities;
|
|
|
using Infrastructure.Email;
|
|
|
using Infrastructure.Extensions;
|
|
|
using IoT.Shared.Services;
|
|
|
using IoT.UI.Shard;
|
|
|
using IoTNode.Services;
|
|
|
using IoTNode.DeviceServices.FBee;
|
|
|
using IoTNode.DeviceServices.Onvif;
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using System;
|
|
|
using System.Threading.Tasks;
|
|
|
using Hangfire;
|
|
|
using Infrastructure.Data;
|
|
|
using System.Linq;
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using IoTNode.DeviceServices.SerialPortManager;
|
|
|
|
|
|
namespace IoTNode
|
|
|
{
|
|
|
public class Startup : IoTServiceStartup
|
|
|
{
|
|
|
public Startup(IConfiguration configuration, IWebHostEnvironment env) : base(configuration, env)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
|
{
|
|
|
services.AddTransient<IEmailSender, EmptyEmailSender>();
|
|
|
services.AddTransient<IoTNodeJob>();
|
|
|
services.AddSingleton<IoTNodeClient>();
|
|
|
services.AddSingleton<OnvifService>();
|
|
|
services.AddSingleton<FBeeService>();
|
|
|
services.AddSingleton<SerialPortService>();
|
|
|
services.AddHostedService(o => o.GetService<IoTNodeClient>());
|
|
|
services.AddHostedService(o => o.GetService<OnvifService>());
|
|
|
services.AddHostedService(o => o.GetService<FBeeService>());
|
|
|
services.AddHostedService(o => o.GetService<SerialPortService>());
|
|
|
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<IoTNodeJob>(timer.Id.ToString(), o => o.TimerHanle(timer.Id), timer.Cron);
|
|
|
}
|
|
|
var tiggerRepo = scope.ServiceProvider.GetService<IRepository<IoTTigger>>();
|
|
|
var tiggers = tiggerRepo.ReadOnlyTable().Where(o => o.NodeId != null).ToList();
|
|
|
foreach (var tigger in tiggers)
|
|
|
{
|
|
|
IoTNodeEventHandler.Tiggers.TryAdd(tigger.Id, tigger);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public override void Seed(DbContext dbContext, IServiceProvider serviceProvider, IConfiguration configuration)
|
|
|
{
|
|
|
var cpuid = Helper.Instance.GetCPUNumber();
|
|
|
dbContext.Set<Node>().Add(new Node
|
|
|
{
|
|
|
Id = $"nodeid-{cpuid}".ToGuid(),
|
|
|
Name = "<22>ڵ<EFBFBD>",
|
|
|
Number = cpuid,
|
|
|
Image = "/images/classroom.png",
|
|
|
Type = "<22>ǻ۽<C7BB><DBBD><EFBFBD>"
|
|
|
});
|
|
|
dbContext.SaveChanges();
|
|
|
base.Seed(dbContext, serviceProvider, configuration);
|
|
|
}
|
|
|
}
|
|
|
} |