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
|
|
|
|
|
2019-05-15 14:56:09 +00:00
|
|
|
using Constants = ASC.Core.Configuration.Constants;
|
2019-11-06 15:03:09 +00:00
|
|
|
using NotifyContext = ASC.Notify.Context;
|
2019-05-15 14:56:09 +00:00
|
|
|
|
2022-02-15 11:52:43 +00:00
|
|
|
namespace ASC.Core;
|
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
[Singletone]
|
|
|
|
public class WorkContext
|
2022-02-15 11:52:43 +00:00
|
|
|
{
|
|
|
|
private static readonly object _syncRoot = new object();
|
2022-03-25 14:51:03 +00:00
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
private readonly DispatchEngine _dispatchEngine;
|
|
|
|
private readonly JabberSender _jabberSender;
|
|
|
|
private readonly AWSSender _awsSender;
|
|
|
|
private readonly SmtpSender _smtpSender;
|
|
|
|
private readonly NotifyServiceSender _notifyServiceSender;
|
|
|
|
private readonly TelegramSender _telegramSender;
|
2022-02-15 11:52:43 +00:00
|
|
|
private static bool _notifyStarted;
|
|
|
|
private static bool? _isMono;
|
|
|
|
private static string _monoVersion;
|
|
|
|
|
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
public NotifyContext NotifyContext { get; private set; }
|
|
|
|
public NotifyEngine NotifyEngine { get; private set; }
|
2022-02-15 11:52:43 +00:00
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
public static string[] DefaultClientSenders => new[] { Constants.NotifyEMailSenderSysName };
|
2022-02-15 11:52:43 +00:00
|
|
|
|
|
|
|
public static bool IsMono
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (_isMono.HasValue)
|
|
|
|
{
|
|
|
|
return _isMono.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
var monoRuntime = Type.GetType("Mono.Runtime");
|
|
|
|
_isMono = monoRuntime != null;
|
|
|
|
if (monoRuntime != null)
|
|
|
|
{
|
|
|
|
var dispalayName = monoRuntime.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
|
|
|
if (dispalayName != null)
|
|
|
|
{
|
|
|
|
_monoVersion = dispalayName.Invoke(null, null) as string;
|
2022-02-14 21:02:57 +00:00
|
|
|
}
|
2022-02-15 11:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return _isMono.Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string MonoVersion => IsMono ? _monoVersion : null;
|
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
public WorkContext(
|
|
|
|
IServiceProvider serviceProvider,
|
|
|
|
IConfiguration configuration,
|
|
|
|
DispatchEngine dispatchEngine,
|
|
|
|
NotifyEngine notifyEngine,
|
|
|
|
NotifyContext notifyContext,
|
|
|
|
JabberSender jabberSender,
|
|
|
|
AWSSender awsSender,
|
|
|
|
SmtpSender smtpSender,
|
|
|
|
NotifyServiceSender notifyServiceSender,
|
|
|
|
TelegramSender telegramSender
|
|
|
|
)
|
|
|
|
{
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_configuration = configuration;
|
|
|
|
_dispatchEngine = dispatchEngine;
|
|
|
|
NotifyEngine = notifyEngine;
|
|
|
|
NotifyContext = notifyContext;
|
|
|
|
_jabberSender = jabberSender;
|
|
|
|
_awsSender = awsSender;
|
|
|
|
_smtpSender = smtpSender;
|
|
|
|
_notifyServiceSender = notifyServiceSender;
|
|
|
|
_telegramSender = telegramSender;
|
|
|
|
}
|
2022-02-15 11:52:43 +00:00
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
public void NotifyStartUp()
|
2022-02-15 11:52:43 +00:00
|
|
|
{
|
|
|
|
if (_notifyStarted)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lock (_syncRoot)
|
|
|
|
{
|
2022-02-14 21:02:57 +00:00
|
|
|
if (_notifyStarted)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
INotifySender jabberSender = _notifyServiceSender;
|
|
|
|
INotifySender emailSender = _notifyServiceSender;
|
|
|
|
INotifySender telegramSender = _telegramSender;
|
2022-02-15 11:52:43 +00:00
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
var postman = _configuration["core:notify:postman"];
|
2022-02-15 11:52:43 +00:00
|
|
|
|
|
|
|
if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase) || "smtp".Equals(postman, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
jabberSender = _jabberSender;
|
2022-02-15 11:52:43 +00:00
|
|
|
|
|
|
|
var properties = new Dictionary<string, string>
|
2022-02-14 21:02:57 +00:00
|
|
|
{
|
2022-02-15 11:52:43 +00:00
|
|
|
["useCoreSettings"] = "true"
|
|
|
|
};
|
|
|
|
if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
emailSender = _awsSender;
|
|
|
|
properties["accessKey"] = _configuration["ses:accessKey"];
|
|
|
|
properties["secretKey"] = _configuration["ses:secretKey"];
|
|
|
|
properties["refreshTimeout"] = _configuration["ses:refreshTimeout"];
|
2022-02-15 11:52:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
emailSender = _smtpSender;
|
2022-02-14 21:02:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 11:52:43 +00:00
|
|
|
emailSender.Init(properties);
|
|
|
|
}
|
|
|
|
|
2022-04-01 14:17:24 +00:00
|
|
|
NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyEMailSenderSysName, new EmailSenderSink(emailSender, _serviceProvider));
|
2022-03-25 14:51:03 +00:00
|
|
|
NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyMessengerSenderSysName, new JabberSenderSink(jabberSender, _serviceProvider));
|
|
|
|
NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyTelegramSenderSysName, new TelegramSenderSink(telegramSender, _serviceProvider));
|
2022-02-15 11:52:43 +00:00
|
|
|
|
2022-03-31 17:32:46 +00:00
|
|
|
NotifyEngine.AddAction<NotifyTransferRequest>();
|
|
|
|
|
2022-02-15 11:52:43 +00:00
|
|
|
_notifyStarted = true;
|
|
|
|
}
|
2020-10-28 12:26:27 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
public void RegisterSendMethod(Action<DateTime> method, string cron)
|
2020-10-28 12:26:27 +00:00
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
NotifyEngine.RegisterSendMethod(method, cron);
|
2022-02-15 11:52:43 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
public void UnregisterSendMethod(Action<DateTime> method)
|
2022-02-15 11:52:43 +00:00
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
NotifyEngine.UnregisterSendMethod(method);
|
2022-02-15 11:52:43 +00:00
|
|
|
|
|
|
|
}
|
2022-03-31 17:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Scope]
|
|
|
|
public class NotifyTransferRequest : INotifyEngineAction
|
|
|
|
{
|
|
|
|
private readonly TenantManager _tenantManager;
|
|
|
|
|
|
|
|
public NotifyTransferRequest(TenantManager tenantManager)
|
2022-02-15 11:52:43 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
_tenantManager = tenantManager;
|
2022-02-15 11:52:43 +00:00
|
|
|
}
|
|
|
|
|
2022-03-31 17:32:46 +00:00
|
|
|
public void AfterTransferRequest(NotifyRequest request)
|
2022-02-15 11:52:43 +00:00
|
|
|
{
|
|
|
|
if ((request.Properties.Contains("Tenant") ? request.Properties["Tenant"] : null) is Tenant tenant)
|
2020-10-28 12:26:27 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
_tenantManager.SetCurrentTenant(tenant);
|
2020-10-28 12:26:27 +00:00
|
|
|
}
|
2022-02-15 11:52:43 +00:00
|
|
|
}
|
2022-03-31 17:32:46 +00:00
|
|
|
|
|
|
|
public void BeforeTransferRequest(NotifyRequest request)
|
|
|
|
{
|
|
|
|
request.Properties.Add("Tenant", _tenantManager.GetCurrentTenant(false));
|
|
|
|
}
|
2022-02-15 11:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class WorkContextExtension
|
|
|
|
{
|
|
|
|
public static void Register(DIHelper dIHelper)
|
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
dIHelper.TryAdd<NotifyTransferRequest>();
|
2022-02-15 11:52:43 +00:00
|
|
|
dIHelper.TryAdd<TelegramHelper>();
|
2022-04-01 14:17:24 +00:00
|
|
|
dIHelper.TryAdd<TelegramSenderSinkMessageCreator>();
|
|
|
|
dIHelper.TryAdd<JabberSenderSinkMessageCreator>();
|
2022-04-01 14:20:00 +00:00
|
|
|
dIHelper.TryAdd<EmailSenderSinkMessageCreator>();
|
2022-02-15 11:52:43 +00:00
|
|
|
}
|
|
|
|
}
|