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

105 lines
2.8 KiB
C#
Raw Normal View History

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
}
}
2022-02-16 13:14:31 +00:00
foreach (var s in Schedulers)
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
try
2019-08-15 12:04:42 +00:00
{
2022-02-16 13:14:31 +00:00
s.Init();
}
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
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
}
}