153 lines
6.1 KiB
C#
153 lines
6.1 KiB
C#
/*
|
|
*
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
*
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
* In accordance with Section 7(a) of the GNU GPL 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 more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
*
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
*
|
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
* in every copy of the program you distribute.
|
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
*
|
|
*/
|
|
|
|
|
|
using System;
|
|
using ASC.Notify.Engine;
|
|
using ASC.Notify.Patterns;
|
|
using ASC.Notify.Recipients;
|
|
|
|
namespace ASC.Notify.Model
|
|
{
|
|
class NotifyClientImpl : INotifyClient
|
|
{
|
|
private readonly Context ctx;
|
|
private readonly InterceptorStorage interceptors = new InterceptorStorage();
|
|
private readonly INotifySource notifySource;
|
|
|
|
|
|
public NotifyClientImpl(Context context, INotifySource notifySource)
|
|
{
|
|
this.notifySource = notifySource ?? throw new ArgumentNullException("notifySource");
|
|
ctx = context ?? throw new ArgumentNullException("context");
|
|
}
|
|
|
|
public void SendNoticeToAsync(INotifyAction action, IRecipient[] recipients, string[] senderNames, params ITagValue[] args)
|
|
{
|
|
SendNoticeToAsync(action, null, recipients, senderNames, false, args);
|
|
}
|
|
|
|
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, params ITagValue[] args)
|
|
{
|
|
SendNoticeToAsync(action, objectID, recipients, senderNames, false, args);
|
|
}
|
|
|
|
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, params ITagValue[] args)
|
|
{
|
|
SendNoticeToAsync(action, objectID, recipients, null, false, args);
|
|
}
|
|
|
|
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, bool checkSubscription, params ITagValue[] args)
|
|
{
|
|
SendNoticeToAsync(action, objectID, recipients, null, checkSubscription, args);
|
|
}
|
|
|
|
public void SendNoticeAsync(INotifyAction action, string objectID, IRecipient recipient, params ITagValue[] args)
|
|
{
|
|
SendNoticeToAsync(action, objectID, new[] { recipient }, null, false, args);
|
|
}
|
|
|
|
public void SendNoticeAsync(int tenantId, INotifyAction action, string objectID, params ITagValue[] args)
|
|
{
|
|
var subscriptionSource = notifySource.GetSubscriptionProvider();
|
|
var recipients = subscriptionSource.GetRecipients(tenantId, action, objectID);
|
|
SendNoticeToAsync(action, objectID, recipients, null, false, args);
|
|
}
|
|
|
|
public void SendNoticeAsync(INotifyAction action, string objectID, IRecipient recipient, bool checkSubscription, params ITagValue[] args)
|
|
{
|
|
SendNoticeToAsync(action, objectID, new[] { recipient }, null, checkSubscription, args);
|
|
}
|
|
|
|
|
|
|
|
public INotifyClient RegisterSendMethod(Action<DateTime> method, string cron)
|
|
{
|
|
ctx.NotifyEngine.RegisterSendMethod(method, cron);
|
|
return this;
|
|
}
|
|
|
|
public INotifyClient UnregisterSendMethod(Action<DateTime> method)
|
|
{
|
|
ctx.NotifyEngine.UnregisterSendMethod(method);
|
|
return this;
|
|
|
|
}
|
|
|
|
public void BeginSingleRecipientEvent(string name)
|
|
{
|
|
interceptors.Add(new SingleRecipientInterceptor(name));
|
|
}
|
|
|
|
public void EndSingleRecipientEvent(string name)
|
|
{
|
|
interceptors.Remove(name);
|
|
}
|
|
|
|
public void AddInterceptor(ISendInterceptor interceptor)
|
|
{
|
|
interceptors.Add(interceptor);
|
|
}
|
|
|
|
public void RemoveInterceptor(string name)
|
|
{
|
|
interceptors.Remove(name);
|
|
}
|
|
|
|
|
|
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, bool checkSubsciption, params ITagValue[] args)
|
|
{
|
|
if (recipients == null) throw new ArgumentNullException("recipients");
|
|
|
|
BeginSingleRecipientEvent("__syspreventduplicateinterceptor");
|
|
|
|
foreach (var recipient in recipients)
|
|
{
|
|
var r = CreateRequest(action, objectID, recipient, args, senderNames, checkSubsciption);
|
|
SendAsync(r);
|
|
}
|
|
}
|
|
|
|
private void SendAsync(NotifyRequest request)
|
|
{
|
|
request.Interceptors = interceptors.GetAll();
|
|
ctx.NotifyEngine.QueueRequest(request);
|
|
}
|
|
|
|
private NotifyRequest CreateRequest(INotifyAction action, string objectID, IRecipient recipient, ITagValue[] args, string[] senders, bool checkSubsciption)
|
|
{
|
|
if (action == null) throw new ArgumentNullException("action");
|
|
if (recipient == null) throw new ArgumentNullException("recipient");
|
|
|
|
var request = new NotifyRequest(notifySource, action, objectID, recipient)
|
|
{
|
|
SenderNames = senders,
|
|
IsNeedCheckSubscriptions = checkSubsciption
|
|
};
|
|
if (args != null) request.Arguments.AddRange(args);
|
|
return request;
|
|
}
|
|
}
|
|
} |