DocSpace-client/web/ASC.Web.Studio/Startup.cs

111 lines
4.3 KiB
C#
Raw Normal View History

2022-03-15 18:00:53 +00:00
// (c) Copyright Ascensio System SIA 2010-2022
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
2020-10-28 12:26:27 +00:00
namespace ASC.Web.Studio;
public class Startup : BaseStartup
2019-05-15 14:56:09 +00:00
{
public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment) : base(configuration, hostEnvironment)
2021-07-13 18:17:18 +00:00
{
}
2019-05-15 14:56:09 +00:00
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
2022-02-03 13:53:42 +00:00
{
base.Configure(app, env);
2021-06-22 16:55:47 +00:00
2022-02-03 13:53:42 +00:00
app.UseRouting();
2022-02-03 13:53:42 +00:00
app.UseEndpoints(endpoints =>
{
endpoints.InitializeHttpHandlers();
});
2020-02-20 14:57:48 +00:00
app.MapWhen(
context => context.Request.Path.ToString().EndsWith("ssologin.ashx"),
appBranch =>
{
appBranch.UseSsoHandler();
});
2019-06-04 14:43:20 +00:00
2022-02-03 13:53:42 +00:00
app.MapWhen(
context => context.Request.Path.ToString().EndsWith("login.ashx"),
appBranch =>
2019-06-04 14:43:20 +00:00
{
2022-02-03 13:53:42 +00:00
appBranch.UseLoginHandler();
});
}
2022-02-11 15:05:40 +00:00
public override void ConfigureServices(IServiceCollection services)
2022-11-21 09:44:28 +00:00
{
2022-02-11 15:05:40 +00:00
base.ConfigureServices(services);
2022-04-25 18:41:26 +00:00
2022-02-11 15:05:40 +00:00
services.AddMemoryCache();
DIHelper.TryAdd<Login>();
DIHelper.TryAdd<PathUtils>();
2022-03-25 09:23:28 +00:00
DIHelper.TryAdd<StorageFactory>();
2022-02-11 15:05:40 +00:00
DIHelper.TryAdd<GoogleLoginProvider>();
DIHelper.TryAdd<FacebookLoginProvider>();
DIHelper.TryAdd<LinkedInLoginProvider>();
2022-05-13 08:52:49 +00:00
DIHelper.TryAdd<SsoHandlerService>();
services.AddHttpClient();
DIHelper.TryAdd<DbWorker>();
services.AddHostedService<WorkerService>();
DIHelper.TryAdd<WorkerService>();
2023-04-24 10:52:56 +00:00
services.TryAddSingleton(new ConcurrentQueue<WebhookRequestIntegrationEvent>());
DIHelper.TryAdd<WebhookRequestIntegrationEventHandler>();
var lifeTime = TimeSpan.FromMinutes(5);
Func<IServiceProvider, HttpRequestMessage, IAsyncPolicy<HttpResponseMessage>> policyHandler = (s, request) =>
{
var settings = s.GetRequiredService<Settings>();
return HttpPolicyExtensions
.HandleTransientHttpError()
2023-04-24 10:52:56 +00:00
.OrResult(msg => msg.StatusCode == HttpStatusCode.NotFound)
.WaitAndRetryAsync(settings.RepeatCount.HasValue ? settings.RepeatCount.Value : 5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
};
services.AddHttpClient(WebhookSender.WEBHOOK)
.SetHandlerLifetime(lifeTime)
.AddPolicyHandler(policyHandler);
services.AddHttpClient(WebhookSender.WEBHOOK_SKIP_SSL)
.SetHandlerLifetime(lifeTime)
.AddPolicyHandler(policyHandler)
.ConfigurePrimaryHttpMessageHandler((s) =>
{
return new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => true
};
});
2019-05-15 14:56:09 +00:00
}
}