DocSpace-client/products/ASC.People/Server/Startup.cs

156 lines
5.4 KiB
C#
Raw Normal View History

2019-09-09 12:56:33 +00:00
2019-10-22 11:21:44 +00:00
using System;
2019-09-10 12:42:15 +00:00
using ASC.Api.Core.Auth;
2019-07-09 10:29:53 +00:00
using ASC.Api.Core.Core;
using ASC.Api.Core.Middleware;
2019-09-09 12:56:33 +00:00
using ASC.Common.Data;
using ASC.Common.DependencyInjection;
2019-07-09 10:29:53 +00:00
using ASC.Common.Logging;
2019-10-22 11:21:44 +00:00
using ASC.Common.Threading.Progress;
using ASC.Common.Threading.Workers;
using ASC.Data.Reassigns;
2019-10-31 11:28:30 +00:00
using ASC.Employee.Core.Controllers;
2019-08-01 08:47:15 +00:00
using ASC.Web.Core.Users;
2019-08-02 14:40:33 +00:00
using Microsoft.AspNetCore.Authentication;
2019-05-15 14:56:09 +00:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
2019-07-12 14:28:14 +00:00
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Formatters;
2019-05-15 14:56:09 +00:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
2019-10-31 11:28:30 +00:00
using Microsoft.Extensions.DependencyInjection.Extensions;
2019-05-15 14:56:09 +00:00
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
2019-05-15 14:56:09 +00:00
namespace ASC.People
{
public class Startup
{
2019-05-15 14:56:09 +00:00
public IConfiguration Configuration { get; }
public IHostEnvironment HostEnvironment { get; }
2019-05-15 14:56:09 +00:00
public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment)
2019-05-15 14:56:09 +00:00
{
Configuration = configuration;
HostEnvironment = hostEnvironment;
}
2019-05-15 14:56:09 +00:00
public void ConfigureServices(IServiceCollection services)
{
2019-08-02 14:40:33 +00:00
services.AddHttpContextAccessor();
2019-09-09 12:56:33 +00:00
services.AddControllers().AddControllersAsServices()
.AddNewtonsoftJson()
.AddXmlSerializerFormatters();
services.AddTransient<IConfigureOptions<MvcNewtonsoftJsonOptions>, CustomJsonOptionsWrapper>();
2019-08-02 14:40:33 +00:00
services.AddMemoryCache();
services.AddDistributedMemoryCache();
services.AddSession();
2019-09-10 12:42:15 +00:00
services.AddAuthentication("cookie")
.AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { })
.AddScheme<AuthenticationSchemeOptions, ConfirmAuthHandler>("confirm", a => { });
var builder = services.AddMvc(config =>
{
config.Filters.Add(new TypeFilterAttribute(typeof(TenantStatusFilter)));
config.Filters.Add(new TypeFilterAttribute(typeof(PaymentFilter)));
config.Filters.Add(new TypeFilterAttribute(typeof(IpSecurityFilter)));
config.Filters.Add(new TypeFilterAttribute(typeof(ProductSecurityFilter)));
config.Filters.Add(new CustomResponseFilterAttribute());
config.Filters.Add(new CustomExceptionFilterAttribute());
config.Filters.Add(new TypeFilterAttribute(typeof(FormatFilter)));
2019-07-24 10:48:45 +00:00
config.OutputFormatters.RemoveType<XmlSerializerOutputFormatter>();
config.OutputFormatters.Add(new XmlOutputFormatter());
});
var container = services.AddAutofac(Configuration, HostEnvironment.ContentRootPath);
2019-10-17 15:55:35 +00:00
services.Configure<LogNLog>(r => r.Name = "ASC");
services.Configure<LogNLog>("ASC", r => r.Name = "ASC");
services.Configure<LogNLog>("ASC.Api", r => r.Name = "ASC.Api");
2019-10-18 13:29:24 +00:00
services.Configure<DbManager>(r => { });
services.Configure<DbManager>("default", r => { });
2019-10-18 14:22:40 +00:00
services.Configure<DbManager>("messages", r => { r.CommandTimeout = 180000; });
2019-10-18 13:29:24 +00:00
2019-10-22 11:21:44 +00:00
services.Configure<WorkerQueue<ResizeWorkerItem>>(r =>
{
r.workerCount = 2;
r.waitInterval = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;
r.errorCount = 1;
r.stopAfterFinsih = true;
});
services.Configure<ProgressQueue<ReassignProgressItem>>(r =>
{
r.workerCount = 1;
r.waitInterval = (int)TimeSpan.FromMinutes(5).TotalMilliseconds;
r.removeAfterCompleted = true;
r.stopAfterFinsih = false;
r.errorCount = 0;
});
services.Configure<ProgressQueue<RemoveProgressItem>>(r =>
{
r.workerCount = 1;
r.waitInterval = (int)TimeSpan.FromMinutes(5).TotalMilliseconds;
r.removeAfterCompleted = true;
r.stopAfterFinsih = false;
r.errorCount = 0;
});
2019-10-31 13:54:43 +00:00
services.TryAddSingleton(typeof(ILog), typeof(LogNLog));
2019-10-22 11:21:44 +00:00
services
2019-10-31 11:28:30 +00:00
.AddPeopleController()
.AddGroupController();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
2019-07-12 14:28:14 +00:00
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseCors(builder =>
builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
app.UseRouting();
app.UseSession();
app.UseAuthentication();
2019-09-10 12:42:15 +00:00
app.UseAuthorization();
app.UseCultureMiddleware();
app.UseDisposeMiddleware();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapCustom();
});
2019-07-08 11:57:03 +00:00
app.UseStaticFiles();
2019-05-15 14:56:09 +00:00
}
}
}