using Application.Domain.Entities; using Hangfire; using Infrastructure.Application.Entites.Settings; using Infrastructure.Data; using Infrastructure.Email; using Infrastructure.Extensions; using Infrastructure.Sms; using Infrastructure.UI; using Infrastructure.Web; 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.Hosting; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace IoTCenter { public class Startup : IoTServiceStartup { public Startup(IConfiguration configuration, IWebHostEnvironment env) : base(configuration, env) { } public override void ConfigureServices(IServiceCollection services) { services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); 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>(); var timers = timerRepo.ReadOnlyTable().Where(o => o.Scene.NodeId == null).ToList(); foreach (var timer in timers) { RecurringJob.AddOrUpdate(timer.Id.ToString(), o => o.TimerHanle(timer.Id), timer.Cron, TimeZoneInfo.Local); } var tiggerRepo = scope.ServiceProvider.GetService>(); var tiggers = tiggerRepo.ReadOnlyTable().Where(o => o.Scene.NodeId == null).ToList(); foreach (var tigger in tiggers) { IoTCenterEventHandler.Tiggers.TryAdd(tigger.Id, tigger); } }); } public override void CreateDatabase(IServiceProvider services) { if (this.env.IsDevelopment()) { base.CreateDatabase(services); } } public override void ConfigureOptions(IServiceCollection services) { //Console.WriteLine(IoT.Resources.Resource.WebFolder); services.ConfigureOptions(new FileConfigureOptions(env, new List { "IoT.Shared" })); } public override void UseSignalR(IEndpointRouteBuilder endpoints) { this.UseSignalR(endpoints); } public override void Seed(DbContext dbContext, IServiceProvider serviceProvider, IConfiguration configuration) { var set = dbContext.Set(); set.Add(new Setting { Name = "name", Value = "物联中心", Type = SettingType.Text }); set.Add(new Setting { Name = "logo", Value = "/images/logo.png", Type = SettingType.ImageUrl }); set.Add(new Setting { Name = "copyright", Value = "Copyright © {0} Company. All rights reserved", Type = SettingType.Html }); // var macAddress = Helper.Instance.GetMacAddress(); set.Add(new Setting { Name = "sn", Value = macAddress, Type = SettingType.Text }); set.Add(new Setting { Name = "id", Value = macAddress.Md5(), Type = SettingType.Text }); set.Add(new Setting { Name = "code", Value = "根据id生成的授权码", Type = SettingType.Text }); dbContext.SaveChanges(); base.Seed(dbContext, serviceProvider, configuration); } } }