43aae08d1e
- Update visualizzazione ODL ed Energy
157 lines
5.6 KiB
C#
157 lines
5.6 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.OpenApi.Models;
|
|
using MP.Data.Services;
|
|
using MP.Stats.Data;
|
|
using MP.TaskMan.Services;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace MP.Stats
|
|
{
|
|
public class Startup
|
|
{
|
|
#region Public Constructors
|
|
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
// aggiunt base URL x routing corretto
|
|
app.UsePathBase(Configuration.GetValue<string>("SpecialConf:AppUrl"));
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/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();
|
|
}
|
|
|
|
// cultura IT...
|
|
var supportedCultures = new[]{
|
|
new CultureInfo("it-IT")
|
|
};
|
|
app.UseRequestLocalization(new RequestLocalizationOptions
|
|
{
|
|
DefaultRequestCulture = new RequestCulture("it-IT"),
|
|
SupportedCultures = supportedCultures,
|
|
FallBackToParentCultures = false
|
|
});
|
|
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("it-IT");
|
|
|
|
//// Registrazione Elmah:
|
|
//// https://github.com/ElmahCore/ElmahCore
|
|
//app.UseElmah();
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
// aggiunta swagger, alla pagina /swagger/index.html
|
|
if (env.IsDevelopment() || env.IsStaging())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
// Configure the HTTP request pipeline.
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
endpoints.MapBlazorHub();
|
|
endpoints.MapFallbackToPage("/_Host");
|
|
});
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
services.AddEndpointsApiExplorer();
|
|
services.AddSwaggerGen(options =>
|
|
{
|
|
options.SwaggerDoc("v1", new OpenApiInfo
|
|
{
|
|
Version = "v1",
|
|
Title = "MP-STATS API",
|
|
Description = "ASP.NET Core Web API for managing MP-STATS items",
|
|
TermsOfService = new Uri("https://www.egalware.com/mp-stats-api-terms"),
|
|
//Contact = new OpenApiContact
|
|
//{
|
|
// Name = "Example Contact",
|
|
// Url = new Uri("https://example.com/contact")
|
|
//},
|
|
//License = new OpenApiLicense
|
|
//{
|
|
// Name = "Example License",
|
|
// Url = new Uri("https://example.com/license")
|
|
//}
|
|
});
|
|
|
|
// using System.Reflection;
|
|
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
|
|
});
|
|
|
|
//// Elmah
|
|
//services.AddElmah();
|
|
//string elmaConn = "Data Source=SQL2016DEV;Initial Catalog=Elmah;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=SHERPA.BBM;";
|
|
//services.AddElmah<SqlErrorLog>(options =>
|
|
//{
|
|
// options.ConnectionString = elmaConn;
|
|
//});
|
|
|
|
// REDIS setup
|
|
var cString = Configuration.GetConnectionString("Redis");
|
|
string connStringRedis = cString ?? "localhost:6379, DefaultDatabase=5, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false";
|
|
// avvio oggetto shared x redis...
|
|
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
|
|
|
// Add services x accesso dati
|
|
services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
|
|
|
|
|
services.AddLocalization();
|
|
|
|
services.AddRazorPages();
|
|
services.AddServerSideBlazor();
|
|
services.AddSingleton<IConfiguration>(Configuration);
|
|
|
|
services.AddSingleton<MpStatsService>();
|
|
services.AddSingleton<TaskService>();
|
|
services.AddSingleton<TranslateSrv>();
|
|
|
|
services.AddScoped<MP.Stats.Data.MessageService>();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |