181 lines
7.4 KiB
C#
181 lines
7.4 KiB
C#
using Microsoft.AspNetCore.Authentication.Cookies;
|
||
using Microsoft.AspNetCore.Builder;
|
||
using Microsoft.AspNetCore.Hosting;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.Extensions.Configuration;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using Microsoft.Extensions.Hosting;
|
||
using Microsoft.Extensions.Logging;
|
||
using MySql.Data.MySqlClient;
|
||
using Quartz;
|
||
using Quartz.Impl;
|
||
using Quartz.Spi;
|
||
using SolarPower.Helper;
|
||
using SolarPower.Models;
|
||
using SolarPower.Quartz;
|
||
using SolarPower.Quartz.Jobs;
|
||
using SolarPower.Repository.Implement;
|
||
using SolarPower.Repository.Interface;
|
||
using SolarPower.Services;
|
||
using SolarPower.Services.Implement;
|
||
using SolarPower.Services.Interface;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace SolarPower
|
||
{
|
||
public class Startup
|
||
{
|
||
public IConfiguration Configuration { get; }
|
||
public DBConfig dBConfig = new DBConfig();
|
||
|
||
public Startup(IConfiguration configuration)
|
||
{
|
||
Configuration = configuration;
|
||
|
||
dBConfig.Server = Configuration.GetValue<string>("DBConfig:Server");
|
||
dBConfig.Port = Configuration.GetValue<string>("DBConfig:Port");
|
||
dBConfig.Database = Configuration.GetValue<string>("DBConfig:Database");
|
||
dBConfig.Root = Configuration.GetValue<string>("DBConfig:Root");
|
||
dBConfig.Password = Configuration.GetValue<string>("DBConfig:Password");
|
||
}
|
||
|
||
// This method gets called by the runtime. Use this method to add services to the container.
|
||
public void ConfigureServices(IServiceCollection services)
|
||
{
|
||
services.AddControllersWithViews();
|
||
|
||
services.AddLogging(
|
||
builder =>
|
||
{
|
||
builder.AddFilter("Microsoft", LogLevel.Warning)
|
||
.AddFilter("System", LogLevel.Warning)
|
||
.AddFilter("NToastNotify", LogLevel.Warning)
|
||
.AddConsole();
|
||
});
|
||
|
||
#region SMPT<EFBFBD>t<EFBFBD>m
|
||
services.AddTransient<ISendEmailService, SendEmailService>();
|
||
services.Configure<SMTPConfig>(Configuration.GetSection("SMTPConfig"));
|
||
#endregion
|
||
|
||
#region DBHelper <EFBFBD>`<EFBFBD>J
|
||
services.AddTransient<IDatabaseHelper>(x => new DatabaseHelper(dBConfig));
|
||
#endregion
|
||
|
||
#region Repository <EFBFBD>`<EFBFBD>J
|
||
services.AddTransient<IUserRepository, UserRepository>();
|
||
services.AddTransient<ICompanyRepository, CompanyRepository>();
|
||
services.AddTransient<IRoleRepository, RoleRepository>();
|
||
services.AddTransient<IPowerStationRepository, PowerStationRepository>();
|
||
services.AddTransient<IOperatorLogRepository, OperatorLogRepository>();
|
||
services.AddTransient<IOperationRepository, OperationRepository>();
|
||
services.AddTransient<IOverviewRepository, OverviewRepository>();
|
||
services.AddTransient<IAnalysisStationCombineRepository,AnalysisStationCombineRepository>();
|
||
services.AddTransient<IStationReportRepository, StationReportRepository>();
|
||
services.AddTransient<INoticeScheduleRepository, NoticeScheduleRepository>();
|
||
services.AddTransient<IElectricitySoldRecordRepository, ElectricitySoldRecordRepository>();
|
||
#endregion
|
||
|
||
double loginExpireMinute = this.Configuration.GetValue<double>("LoginExpireMinute");
|
||
services.AddSession(options =>
|
||
{
|
||
options.IdleTimeout = TimeSpan.FromMinutes(loginExpireMinute);
|
||
});
|
||
|
||
//#region <20>[<5B>J<EFBFBD>I<EFBFBD><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
////services.AddHostedService<OperationScheduleBackgroundService>();
|
||
|
||
////<2F>K<EFBFBD>[Quartz<74>A<EFBFBD><41>
|
||
//services.AddSingleton<IJobFactory, SingletonJobFactory>();
|
||
//services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
|
||
////<2F>K<EFBFBD>[Job
|
||
//#region <20>w<EFBFBD><77><EFBFBD>p<EFBFBD>e
|
||
//services.AddSingleton<OperationScheduleJob>();
|
||
//services.AddSingleton(
|
||
// new JobSchedule(jobType: typeof(OperationScheduleJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:OperationScheduleJob"))
|
||
//);
|
||
//#endregion
|
||
|
||
//#region <20>p<EFBFBD><70><EFBFBD>q<EFBFBD><71><EFBFBD>f<EFBFBD>ܾ<EFBFBD><DCBE><EFBFBD><EFBFBD>T(<28>C<EFBFBD><43><EFBFBD>I2<49><32><EFBFBD>}<7D>l<EFBFBD><6C><EFBFBD><EFBFBD>15<31><35><EFBFBD><EFBFBD><EFBFBD>@<40>Ӵ`<60><>)
|
||
//services.AddSingleton<CalcInverter15minJob>();
|
||
//services.AddSingleton(
|
||
// new JobSchedule(jobType: typeof(CalcInverter15minJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcInverter15minJob"))
|
||
//);
|
||
//#endregion
|
||
|
||
//#region <20>p<EFBFBD><70><EFBFBD>q<EFBFBD><71><EFBFBD>o<EFBFBD>q<EFBFBD>q<EFBFBD><71><EFBFBD><EFBFBD><EFBFBD>T(<28>C<EFBFBD><43><EFBFBD>I5<49><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||
//services.AddSingleton<CalcPowerStationJob>();
|
||
//services.AddSingleton(
|
||
//new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcPowerStationJob"))
|
||
////new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0/10 * * * * ?")
|
||
//);
|
||
//#endregion
|
||
|
||
//#region <20>p<EFBFBD><70><EFBFBD>q<EFBFBD><71><EFBFBD><EFBFBD><EFBFBD>Ӷq<D3B6>BPR<50>BkWP 30<33>饭<EFBFBD><E9A5AD><EFBFBD>B(<28>C<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD>2<EFBFBD>I<EFBFBD><49><EFBFBD><EFBFBD>)
|
||
//services.AddSingleton<CalcAvgPowerStationJob>();
|
||
//services.AddSingleton(
|
||
//new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcAvgPowerStationJob"))
|
||
////new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 03 7 ? * * *")
|
||
//);
|
||
//#endregion
|
||
|
||
//#region <20>H<EFBFBD>eEmail(<28>C<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD>2<EFBFBD>I<EFBFBD><49><EFBFBD><EFBFBD>)
|
||
//services.AddSingleton<SendEmailJob>();
|
||
//services.AddSingleton(
|
||
//new JobSchedule(jobType: typeof(SendEmailJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:SendEmailJob"))
|
||
//);
|
||
//#endregion
|
||
|
||
//#region <20>d<EFBFBD>߲<EFBFBD><DFB2>`<60>s<EFBFBD>W<EFBFBD><57>Email
|
||
//services.AddSingleton<ExceptionSchedule>();
|
||
//services.AddSingleton(
|
||
//new JobSchedule(jobType: typeof(ExceptionSchedule), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:ExceptionSchedule"))
|
||
//);
|
||
//#endregion
|
||
|
||
//services.AddHostedService<QuartzHostedService>();
|
||
//#endregion
|
||
|
||
services.AddApplicationInsightsTelemetry();
|
||
}
|
||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
|
||
{
|
||
loggerFactory.AddFile("Logs/log-{Date}.txt");
|
||
|
||
if (env.IsDevelopment())
|
||
{
|
||
app.UseDeveloperExceptionPage();
|
||
}
|
||
else
|
||
{
|
||
app.UseExceptionHandler("/Home/Error");
|
||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||
app.UseHsts();
|
||
}
|
||
|
||
app.UseSession();
|
||
app.UseHttpsRedirection();
|
||
app.UseStaticFiles();
|
||
|
||
app.UseRouting();
|
||
|
||
app.UseAuthorization();
|
||
|
||
app.UseEndpoints(endpoints =>
|
||
{
|
||
endpoints.MapControllerRoute(
|
||
name: "default",
|
||
pattern: "{controller=Login}/{action=Index}/{id?}");
|
||
});
|
||
}
|
||
}
|
||
}
|