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.
83 lines
2.9 KiB
83 lines
2.9 KiB
using Application.Domain.Entities;
|
|
using Infrastructure.Domain;
|
|
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.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IoTCenter
|
|
{
|
|
public class Startup : IoTServiceStartup
|
|
{
|
|
public Startup(IConfiguration configuration, IHostingEnvironment env) : base(configuration, env)
|
|
{
|
|
}
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddTransient<IEmailSender, EmptyEmailSender>();
|
|
services.AddTransient<ISmsSender, EmptySmsSender>();
|
|
services.AddTransient<IEventPublisher, EventPublisher>();
|
|
services.AddSingleton<HealthCheckService>();
|
|
Assembly.GetExecutingAssembly()
|
|
.GetTypes()
|
|
.Where(t => t.GetInterfaces().Any(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IEvent<>)))
|
|
.ToList()
|
|
.ForEach(t =>
|
|
{
|
|
services.AddTransient(t.GetInterfaces().Where(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IEvent<>)).First(), t);
|
|
});
|
|
base.ConfigureServices(services);
|
|
}
|
|
|
|
public override void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
{
|
|
base.Configure(app, env, loggerFactory);
|
|
Task.Run(() =>
|
|
{
|
|
app.ApplicationServices.GetService<HealthCheckService>().Start();
|
|
});
|
|
}
|
|
|
|
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(IApplicationBuilder app)
|
|
{
|
|
this.UseSignalR<PageHub>(app);
|
|
}
|
|
|
|
public override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<Setting>();
|
|
base.OnModelCreating(modelBuilder);
|
|
}
|
|
|
|
public override void Seed(DbContext dbContext, IServiceProvider serviceProvider, IConfiguration configuration)
|
|
{
|
|
dbContext.Set<Setting>().Add(new Setting
|
|
{
|
|
Longitude = 116.54296875m,
|
|
Latitude = 41.77131167974391m,
|
|
Altitude = 0m
|
|
});
|
|
dbContext.SaveChanges();
|
|
base.Seed(dbContext, serviceProvider, configuration);
|
|
}
|
|
}
|
|
} |