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.
94 lines
3.6 KiB
94 lines
3.6 KiB
using Hangfire;
|
|
using Hangfire.Dashboard.BasicAuthorization;
|
|
using Hangfire.MySql;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Email;
|
|
using Infrastructure.Sms;
|
|
using Infrastructure.UI;
|
|
using Infrastructure.Web;
|
|
using IoT.Shared.Services;
|
|
using IoTCenter.Services;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Transactions;
|
|
|
|
namespace IoTCenter
|
|
{
|
|
public class Startup : BaseStartup
|
|
{
|
|
public Startup(IConfiguration configuration, IWebHostEnvironment env) : base(configuration, env)
|
|
{
|
|
}
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddTransient<SceneTiggerService>();
|
|
services.AddTransient<ISceneTiggerService, CachedSceneTiggerService>();
|
|
services.AddTransient<IDbConfig, DbConfig>();
|
|
services.AddTransient<IRoleService, RoleService>();
|
|
services.AddTransient<IEmailSender, EmptyEmailSender>();
|
|
services.AddTransient<ISmsSender, EmptySmsSender>();
|
|
services.AddTransient<DataService>();
|
|
services.AddTransient<IoTCenterEventHandler>();
|
|
services.AddHostedService<DataSyncService>();
|
|
base.ConfigureServices(services);
|
|
var connectionString = Configuration.GetConnectionString("HangfireConnection");
|
|
services.AddHangfire(configuration => configuration.UseStorage(new MySqlStorage(connectionString, new MySqlStorageOptions
|
|
{
|
|
TransactionIsolationLevel = IsolationLevel.ReadCommitted,
|
|
QueuePollInterval = TimeSpan.FromSeconds(15),
|
|
JobExpirationCheckInterval = TimeSpan.FromHours(1),
|
|
CountersAggregateInterval = TimeSpan.FromMinutes(5),
|
|
PrepareSchemaIfNecessary = true,
|
|
DashboardJobListLimit = 50000,
|
|
TransactionTimeout = TimeSpan.FromMinutes(1),
|
|
TablesPrefix = "Hangfire"
|
|
})));
|
|
}
|
|
|
|
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
|
|
{
|
|
base.Configure(app, env, loggerFactory);
|
|
var options = new DashboardOptions
|
|
{
|
|
Authorization = new[] { new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
|
|
{
|
|
RequireSsl = false,
|
|
SslRedirect = false,
|
|
LoginCaseSensitive = true,
|
|
Users = new []
|
|
{
|
|
new BasicAuthAuthorizationUser
|
|
{
|
|
Login = Configuration["auth:usr"],
|
|
PasswordClear = Configuration["auth:pwd"]
|
|
}
|
|
}
|
|
}) }
|
|
};
|
|
|
|
app.UseHangfireDashboard("/job", options);
|
|
|
|
app.UseHangfireServer(new BackgroundJobServerOptions
|
|
{
|
|
ServerName = $"IoTCenter:{Guid.NewGuid()}",
|
|
});
|
|
}
|
|
|
|
public override void ConfigureOptions(IServiceCollection services)
|
|
{
|
|
services.ConfigureOptions(new FileConfigureOptions(Env, new List<string> { "IoT.Shared" }));
|
|
}
|
|
|
|
public override void UseSignalR(IEndpointRouteBuilder endpoints)
|
|
{
|
|
this.UseSignalR<IoTCenterHub>(endpoints);
|
|
}
|
|
}
|
|
} |