DocSpace-client/common/ASC.Core.Common/Notify/Context.cs

82 lines
3.1 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
2022-03-25 14:51:03 +00:00
namespace ASC.Notify;
[Singletone]
2022-02-15 11:52:43 +00:00
public sealed class Context : INotifyRegistry
2019-05-15 14:56:09 +00:00
{
2022-02-15 11:52:43 +00:00
public const string SysRecipient = "_#" + SysRecipientId + "#_";
internal const string SysRecipientId = "SYS_RECIPIENT_ID";
internal const string SysRecipientName = "SYS_RECIPIENT_NAME";
internal const string SysRecipientAddress = "SYS_RECIPIENT_ADDRESS";
2019-05-15 14:56:09 +00:00
2022-04-01 14:17:24 +00:00
private readonly Dictionary<string, ISenderChannel> _channels = new Dictionary<string, ISenderChannel>(2);
private readonly ILoggerProvider _options;
2022-04-01 14:17:24 +00:00
2022-02-15 11:52:43 +00:00
public event Action<Context, INotifyClient> NotifyClientRegistration;
2022-04-01 14:17:24 +00:00
public Context(ILoggerProvider options)
2022-04-01 14:17:24 +00:00
{
_options = options;
}
2019-11-06 15:03:09 +00:00
2022-03-25 14:51:03 +00:00
public void RegisterSender(DispatchEngine dispatchEngine, string senderName, ISink senderSink)
2022-02-15 11:52:43 +00:00
{
lock (_channels)
2019-05-15 14:56:09 +00:00
{
2022-03-25 14:51:03 +00:00
_channels[senderName] = new SenderChannel(dispatchEngine, senderName, null, senderSink);
2019-05-15 14:56:09 +00:00
}
2022-02-15 11:52:43 +00:00
}
2019-05-15 14:56:09 +00:00
2022-03-25 14:51:03 +00:00
public void UnregisterSender(string senderName)
2022-02-15 11:52:43 +00:00
{
lock (_channels)
2019-05-15 14:56:09 +00:00
{
2022-02-15 11:52:43 +00:00
_channels.Remove(senderName);
2019-05-15 14:56:09 +00:00
}
2022-02-15 11:52:43 +00:00
}
2019-05-15 14:56:09 +00:00
2022-03-25 14:51:03 +00:00
public ISenderChannel GetSender(string senderName)
2022-02-15 11:52:43 +00:00
{
lock (_channels)
2019-05-15 14:56:09 +00:00
{
2022-02-15 11:52:43 +00:00
_channels.TryGetValue(senderName, out var channel);
2022-02-15 11:52:43 +00:00
return channel;
2019-05-15 14:56:09 +00:00
}
2022-02-15 11:52:43 +00:00
}
2019-05-15 14:56:09 +00:00
2022-03-31 17:32:46 +00:00
public INotifyClient RegisterClient(NotifyEngineQueue notifyEngineQueue, INotifySource source)
2022-02-15 11:52:43 +00:00
{
//ValidateNotifySource(source);
2022-04-01 14:17:24 +00:00
var client = new NotifyClientImpl(_options, notifyEngineQueue, source);
2022-02-15 11:52:43 +00:00
NotifyClientRegistration?.Invoke(this, client);
2022-02-15 11:52:43 +00:00
return client;
}
2019-05-15 14:56:09 +00:00
}