123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using Microsoft.AspNetCore.Authentication.Cookies;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Hosting;
- using Microsoft.Extensions.WebEncoders;
- using ProductionLineMonitor.Application.Services;
- using ProductionLineMonitor.Application.Services.AdminService;
- using ProductionLineMonitor.Application.Services.CimService;
- using ProductionLineMonitor.Application.Services.FaultService;
- using ProductionLineMonitor.Application.Services.HomeService;
- using ProductionLineMonitor.Application.Services.LineService;
- using ProductionLineMonitor.Application.Services.OEEService;
- using ProductionLineMonitor.Core.IRepositories;
- using ProductionLineMonitor.Core.Services;
- using ProductionLineMonitor.EntityFramework;
- using ProductionLineMonitor.EntityFramework.Repositories;
- using ProductionLineMonitor.Web.Converter;
- using ProductionLineMonitor.Web.HostedServices;
- using System;
- using System.Text.Encodings.Web;
- using System.Text.Unicode;
- namespace ProductionLineMonitor.Web
- {
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
- public IConfiguration Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddControllers().AddJsonOptions(options =>
- {
- //设置时间格式
- options.JsonSerializerOptions.Converters.Add(new DateTimeConverter("yyyy-MM-dd HH:mm:ss"));
- });
- DBOptions.ConnectionString = Configuration.GetConnectionString("DefaultConnection");
- services.AddDbContext<ProductionLineContext>(
- opt => opt.UseSqlite(DBOptions.ConnectionString,
- b => b.MigrationsAssembly("ProductionLineMonitor.Web")));
- services.Configure<WebEncoderOptions>(options =>
- options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All));
- services
- .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
- .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, option =>
- {
- option.LoginPath = new PathString("/Account/Login");
- });
- // AutoMapper
- services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
- // Services
- services.AddScoped<IUnitOfWork, UnitOfWork>();
- services.AddScoped<IAdminService, AdminService>();
- services.AddScoped<IProductionLineCoreService, ProductionLineCoreService>();
- services.AddScoped<IRecipeService, RecipeService>();
- services.AddScoped<ICimService, CimService>();
- services.AddScoped<IReportFormService, ReportFormService>();
- services.AddScoped<IFaultService, FaultService>();
- services.AddScoped<IExternalService, ExternalService>();
- services.AddScoped<ILineService, LineService>();
- services.AddScoped<IHomeService, HomeService>();
- services.AddScoped<IOEEService, OEEService>();
- services.AddScoped<IExcelService, ExcelService>();
- // Dispatch service
- services.AddSingleton<IHostedService, DispatchService>();
- services.AddSingleton<IHostedService, ElectricEnergyMeterCheckService>();
- // Publish show views
- services.AddControllersWithViews();
- services.AddControllersWithViews().AddRazorRuntimeCompilation();
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- app.UseStaticFiles();
- app.UseRouting();
- app.UseAuthentication();
- app.UseAuthorization();
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllerRoute(
- name: "default",
- pattern: "{controller=Home}/{action=Index}/{id?}");
- });
- // Hsl Authorization
- var rev = HslCommunication.Authorization.SetAuthorizationCode("3e54799d-f65f-4be6-9e34-517ea9ee294c");
- if (rev == false)
- {
- throw new NotImplementedException("hsl 激活失败!");
- }
- // MQTT Client
- string ip = Configuration.GetSection("MqttOptions").GetValue<string>("IpAddress");
- int port = Configuration.GetSection("MqttOptions").GetValue<int>("Port");
- string clientId = Configuration.GetSection("MqttOptions").GetValue<string>("ClientId");
- app.UseHostMqtt(ip, port, clientId);
- // Safeguard Url
- Config.SafeguardUrl = Configuration.GetValue<string>("SafeguardUrl");
- }
- }
- }
|