2019-06-14 11:56:32 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (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;
|
2020-02-17 08:58:14 +00:00
|
|
|
|
|
|
|
using ASC.Common;
|
2019-06-14 11:56:32 +00:00
|
|
|
using ASC.Common.Logging;
|
2019-12-05 08:51:28 +00:00
|
|
|
using ASC.Core.Common.EF.Context;
|
2020-02-17 08:58:14 +00:00
|
|
|
|
2019-09-24 10:32:12 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2019-10-17 15:55:35 +00:00
|
|
|
using Microsoft.Extensions.Options;
|
2019-06-14 11:56:32 +00:00
|
|
|
|
|
|
|
namespace ASC.MessagingSystem.DbSender
|
|
|
|
{
|
|
|
|
public class DbMessageSender : IMessageSender
|
|
|
|
{
|
2019-10-17 15:55:35 +00:00
|
|
|
private readonly ILog log;
|
2019-06-14 11:56:32 +00:00
|
|
|
|
2019-11-06 15:03:09 +00:00
|
|
|
public DbMessageSender(IConfiguration configuration, MessagesRepository messagesRepository, IOptionsMonitor<ILog> options)
|
2019-06-14 11:56:32 +00:00
|
|
|
{
|
2019-09-24 10:32:12 +00:00
|
|
|
var setting = configuration["messaging:enabled"];
|
|
|
|
MessagingEnabled = !string.IsNullOrEmpty(setting) && setting == "true";
|
2019-10-10 08:52:21 +00:00
|
|
|
MessagesRepository = messagesRepository;
|
2019-10-17 15:55:35 +00:00
|
|
|
log = options.Get("ASC.Messaging");
|
2019-06-14 11:56:32 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 11:28:30 +00:00
|
|
|
private MessagesRepository MessagesRepository { get; }
|
2019-09-24 10:32:12 +00:00
|
|
|
private bool MessagingEnabled { get; }
|
|
|
|
|
2019-06-14 11:56:32 +00:00
|
|
|
|
|
|
|
public void Send(EventMessage message)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!MessagingEnabled) return;
|
2019-08-15 12:04:42 +00:00
|
|
|
|
2019-06-14 11:56:32 +00:00
|
|
|
if (message == null) return;
|
2019-08-15 12:04:42 +00:00
|
|
|
|
2019-06-14 11:56:32 +00:00
|
|
|
MessagesRepository.Add(message);
|
|
|
|
}
|
2019-08-15 12:04:42 +00:00
|
|
|
catch (Exception ex)
|
2019-06-14 11:56:32 +00:00
|
|
|
{
|
|
|
|
log.Error("Failed to send a message", ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-31 11:28:30 +00:00
|
|
|
|
2019-11-11 09:03:49 +00:00
|
|
|
public static class DbMessageSenderExtension
|
2019-10-31 11:28:30 +00:00
|
|
|
{
|
2020-02-17 08:58:14 +00:00
|
|
|
public static DIHelper AddDbMessageSenderService(this DIHelper services)
|
2019-10-31 11:28:30 +00:00
|
|
|
{
|
|
|
|
services.TryAddSingleton<DbMessageSender>();
|
|
|
|
services.TryAddSingleton<MessagesRepository>();
|
2019-12-05 08:51:28 +00:00
|
|
|
services.AddMessagesContextService();
|
2019-10-31 11:28:30 +00:00
|
|
|
|
|
|
|
return services;
|
|
|
|
}
|
|
|
|
}
|
2019-06-14 11:56:32 +00:00
|
|
|
}
|