DocSpace-buildtools/common/services/ASC.Notify/Config/NotifyServiceCfg.cs

135 lines
4.4 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-02-16 13:14:31 +00:00
namespace ASC.Notify.Config;
[Singletone]
public class ConfigureNotifyServiceCfg : IConfigureOptions<NotifyServiceCfg>
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
public ConfigureNotifyServiceCfg(IServiceProvider serviceProvider)
2019-11-05 10:20:00 +00:00
{
2022-02-16 13:14:31 +00:00
_serviceProvider = serviceProvider;
}
2019-11-05 10:20:00 +00:00
2022-02-16 13:14:31 +00:00
private readonly IServiceProvider _serviceProvider;
2019-11-05 10:20:00 +00:00
2022-02-16 13:14:31 +00:00
public void Configure(NotifyServiceCfg options)
{
options.Init(_serviceProvider);
2019-11-05 10:20:00 +00:00
}
2022-02-16 13:14:31 +00:00
}
2019-11-05 10:20:00 +00:00
2022-02-16 13:14:31 +00:00
[Singletone(typeof(ConfigureNotifyServiceCfg))]
public class NotifyServiceCfg
{
public string ConnectionStringName { get; set; }
public int StoreMessagesDays { get; set; }
public string ServerRoot { get; set; }
public NotifyServiceCfgProcess Process { get; set; }
public List<NotifyServiceCfgSender> Senders { get; set; }
public List<NotifyServiceCfgScheduler> Schedulers { get; set; }
public void Init(IServiceProvider serviceProvider)
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
ServerRoot = string.IsNullOrEmpty(ServerRoot) ? "http://*/" : ServerRoot;
2019-07-29 09:15:48 +00:00
2022-02-16 13:14:31 +00:00
Process.Init();
2019-07-29 09:15:48 +00:00
2022-02-16 13:14:31 +00:00
foreach (var s in Senders)
{
try
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
s.Init(serviceProvider);
2019-07-29 09:15:48 +00:00
}
2022-02-16 13:14:31 +00:00
catch (Exception)
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
2019-07-29 09:15:48 +00:00
}
}
2023-01-19 20:13:29 +00:00
if (Schedulers != null)
2019-07-29 09:15:48 +00:00
{
2023-01-19 20:13:29 +00:00
foreach (var s in Schedulers)
2022-02-16 13:14:31 +00:00
{
2023-01-19 20:13:29 +00:00
try
{
s.Init();
}
catch (Exception)
{
2022-02-16 13:14:31 +00:00
2023-01-19 20:13:29 +00:00
}
2019-07-29 09:15:48 +00:00
}
}
}
2022-02-16 13:14:31 +00:00
}
2019-07-29 09:15:48 +00:00
2022-02-16 13:14:31 +00:00
public class NotifyServiceCfgProcess
{
public int MaxThreads { get; set; }
public int BufferSize { get; set; }
public int MaxAttempts { get; set; }
public string AttemptsInterval { get; set; }
2019-07-29 09:15:48 +00:00
2022-02-16 13:14:31 +00:00
public void Init()
{
if (MaxThreads == 0)
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
MaxThreads = Environment.ProcessorCount;
2019-07-29 09:15:48 +00:00
}
}
2022-02-16 13:14:31 +00:00
}
2019-07-29 09:15:48 +00:00
2022-02-16 13:14:31 +00:00
public class NotifyServiceCfgSender
{
public string Name { get; set; }
public string Type { get; set; }
public Dictionary<string, string> Properties { get; set; }
public INotifySender NotifySender { get; set; }
public void Init(IServiceProvider serviceProvider)
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
var sender = (INotifySender)serviceProvider.GetService(System.Type.GetType(Type, true));
sender.Init(Properties);
NotifySender = sender;
}
}
2019-07-29 09:15:48 +00:00
2022-02-16 13:14:31 +00:00
public class NotifyServiceCfgScheduler
{
public string Name { get; set; }
public string Register { get; set; }
public MethodInfo MethodInfo { get; set; }
public void Init()
{
var typeName = Register.Substring(0, Register.IndexOf(','));
var assemblyName = Register.Substring(Register.IndexOf(','));
var type = Type.GetType(string.Concat(typeName.AsSpan(0, typeName.LastIndexOf('.')), assemblyName), true);
2022-02-16 13:14:31 +00:00
MethodInfo = type.GetMethod(typeName.Substring(typeName.LastIndexOf('.') + 1), BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
2019-07-29 09:15:48 +00:00
}
}