DI: StudioNotifyService

This commit is contained in:
pavelbannov 2019-11-01 11:49:08 +03:00
parent 9d08727f4c
commit c54f575c26
15 changed files with 309 additions and 114 deletions

View File

@ -37,7 +37,13 @@ using Microsoft.Extensions.Options;
using HttpContext = Microsoft.AspNetCore.Http.HttpContext;
namespace ASC.Core.Common
{
{
public class CommonLinkUtilitySettings
{
public string ServerUri { get; set; }
}
public class BaseCommonLinkUtility
{
private const string LOCALHOST = "localhost";
@ -51,8 +57,9 @@ namespace ASC.Core.Common
CoreBaseSettings coreBaseSettings,
CoreSettings coreSettings,
TenantManager tenantManager,
IOptionsMonitor<LogNLog> options)
: this(null, coreBaseSettings, coreSettings, tenantManager, options)
IOptionsMonitor<LogNLog> options,
IOptions<CommonLinkUtilitySettings> settings)
: this(null, coreBaseSettings, coreSettings, tenantManager, options, settings)
{
}
@ -61,22 +68,34 @@ namespace ASC.Core.Common
CoreBaseSettings coreBaseSettings,
CoreSettings coreSettings,
TenantManager tenantManager,
IOptionsMonitor<LogNLog> options)
{
try
IOptionsMonitor<LogNLog> options,
IOptions<CommonLinkUtilitySettings> settings)
{
var serverUri = settings.Value.ServerUri;
if (!string.IsNullOrEmpty(serverUri))
{
HttpContext = httpContextAccessor?.HttpContext;
var uriBuilder = new UriBuilder(Uri.UriSchemeHttp, LOCALHOST);
if (HttpContext?.Request != null)
{
var u = HttpContext.Request.GetUrlRewriter();
uriBuilder = new UriBuilder(u.Scheme, LOCALHOST, u.Port);
}
_serverRoot = uriBuilder;
}
catch (Exception error)
{
options.Get("ASC.Web").Error(error);
var uri = new Uri(serverUri.Replace('*', 'x').Replace('+', 'x'));
_serverRoot = new UriBuilder(uri.Scheme, LOCALHOST, uri.Port);
_vpath = "/" + uri.AbsolutePath.Trim('/');
}
else
{
try
{
HttpContext = httpContextAccessor?.HttpContext;
var uriBuilder = new UriBuilder(Uri.UriSchemeHttp, LOCALHOST);
if (HttpContext?.Request != null)
{
var u = HttpContext.Request.GetUrlRewriter();
uriBuilder = new UriBuilder(u.Scheme, LOCALHOST, u.Port);
}
_serverRoot = uriBuilder;
}
catch (Exception error)
{
options.Get("ASC.Web").Error(error);
}
}
CoreBaseSettings = coreBaseSettings;
@ -84,18 +103,6 @@ namespace ASC.Core.Common
TenantManager = tenantManager;
}
public void Initialize(string serverUri)
{
if (string.IsNullOrEmpty(serverUri))
{
throw new ArgumentNullException("serverUri");
}
var uri = new Uri(serverUri.Replace('*', 'x').Replace('+', 'x'));
_serverRoot = new UriBuilder(uri.Scheme, LOCALHOST, uri.Port);
_vpath = "/" + uri.AbsolutePath.Trim('/');
}
public string VirtualRoot
{
get { return ToAbsolute("~"); }

View File

@ -33,6 +33,7 @@ using ASC.Common.Data.Sql;
using ASC.Common.Data.Sql.Expressions;
using ASC.Core;
using ASC.Core.Tenants;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
namespace ASC.Feed.Data
@ -386,4 +387,16 @@ namespace ASC.Feed.Data
return feedMin;
}
}
public static class FeedAggregateDataProviderFactory
{
public static IServiceCollection AddFeedAggregateDataProvider(this IServiceCollection services)
{
return services
.AddAuthContextService()
.AddTenantManagerService()
.AddTenantUtilService()
.AddDbManagerService();
}
}
}

View File

@ -36,6 +36,8 @@ using ASC.Notify.Config;
using ASC.Notify.Messages;
using Google.Protobuf.Collections;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace ASC.Notify
@ -48,10 +50,10 @@ namespace ASC.Notify
public IServiceProvider ServiceProvider { get; }
public NotifyServiceCfg NotifyServiceCfg { get; }
public DbWorker(IServiceProvider serviceProvider, NotifyServiceCfg notifyServiceCfg)
public DbWorker(IServiceProvider serviceProvider, IOptions<NotifyServiceCfg> notifyServiceCfg)
{
ServiceProvider = serviceProvider;
NotifyServiceCfg = notifyServiceCfg;
NotifyServiceCfg = notifyServiceCfg.Value;
dbid = NotifyServiceCfg.ConnectionStringName;
}
@ -168,4 +170,15 @@ namespace ASC.Notify
tx.Commit();
}
}
public static class DbWorkerFactory
{
public static IServiceCollection AddDbWorker(this IServiceCollection services)
{
services.TryAddSingleton<DbWorker>();
return services
.AddDbManagerService();
}
}
}

View File

@ -31,6 +31,7 @@ using ASC.Common.Data;
using ASC.Common.Logging;
using ASC.Notify.Config;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace ASC.Notify
@ -43,10 +44,10 @@ namespace ASC.Notify
public IServiceProvider ServiceProvider { get; }
public CancellationTokenSource CancellationTokenSource { get; }
public NotifyCleaner(NotifyServiceCfg notifyServiceCfg, IServiceProvider serviceProvider, IOptionsMonitor<LogNLog> options)
public NotifyCleaner(IOptions<NotifyServiceCfg> notifyServiceCfg, IServiceProvider serviceProvider, IOptionsMonitor<LogNLog> options)
{
log = options.Get("ASC.Notify");
NotifyServiceCfg = notifyServiceCfg;
NotifyServiceCfg = notifyServiceCfg.Value;
ServiceProvider = serviceProvider;
CancellationTokenSource = new CancellationTokenSource();
}
@ -97,5 +98,15 @@ namespace ASC.Notify
}
}
}
}
public static class NotifyCleanerFactory
{
public static IServiceCollection AddNotifyCleaner(this IServiceCollection services)
{
services.TryAddSingleton<NotifyCleaner>();
return services;
}
}
}

View File

@ -33,6 +33,8 @@ using System.Threading.Tasks;
using ASC.Common.Logging;
using ASC.Notify.Config;
using ASC.Notify.Messages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace ASC.Notify
@ -46,10 +48,10 @@ namespace ASC.Notify
public NotifyServiceCfg NotifyServiceCfg { get; }
public NotifySender(NotifyServiceCfg notifyServiceCfg, DbWorker dbWorker, IOptionsMonitor<LogNLog> options)
public NotifySender(IOptions<NotifyServiceCfg> notifyServiceCfg, DbWorker dbWorker, IOptionsMonitor<LogNLog> options)
{
log = options.Get("ASC");
NotifyServiceCfg = notifyServiceCfg;
NotifyServiceCfg = notifyServiceCfg.Value;
db = dbWorker;
}
@ -144,5 +146,16 @@ namespace ASC.Notify
log.Error(e);
}
}
}
public static class NotifySenderFactory
{
public static IServiceCollection AddNotifySender(this IServiceCollection services)
{
services.TryAddSingleton<NotifySender>();
return services
.AddDbWorker();
}
}
}

View File

@ -32,6 +32,7 @@ using ASC.Core;
using ASC.Notify.Messages;
using ASC.Web.Core.WhiteLabel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace ASC.Notify
@ -106,4 +107,16 @@ namespace ASC.Notify
cacheNotify.Unsubscribe(CacheNotifyAction.InsertOrUpdate);
}
}
public static class NotifyServiceFactory
{
public static IServiceCollection AddNotifyService(this IServiceCollection services)
{
services.TryAddSingleton<NotifyService>();
services.TryAddSingleton(typeof(ICacheNotify<>), typeof(KafkaCache<>));
return services
.AddDbWorker();
}
}
}

View File

@ -29,6 +29,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ASC.Common.Logging;
using ASC.Core.Common;
using ASC.Notify.Config;
using ASC.Web.Core;
using ASC.Web.Studio.Core.Notify;
@ -39,6 +40,21 @@ using Microsoft.Extensions.Options;
namespace ASC.Notify
{
public class ConfigureCommonLinkUtilitySettings : IConfigureOptions<CommonLinkUtilitySettings>
{
public ConfigureCommonLinkUtilitySettings(IOptions<NotifyServiceCfg> notifyServiceCfg)
{
NotifyServiceCfg = notifyServiceCfg.Value;
}
public NotifyServiceCfg NotifyServiceCfg { get; }
public void Configure(CommonLinkUtilitySettings clu)
{
clu.ServerUri = NotifyServiceCfg.ServerRoot;
}
}
public class NotifyServiceLauncher : IHostedService
{
public NotifyServiceCfg NotifyServiceCfg { get; }
@ -49,7 +65,8 @@ namespace ASC.Notify
public IServiceProvider ServiceProvider { get; }
public ILog Log { get; }
public NotifyServiceLauncher(NotifyServiceCfg notifyServiceCfg,
public NotifyServiceLauncher(
IOptions<NotifyServiceCfg> notifyServiceCfg,
NotifySender notifySender,
NotifyService notifyService,
NotifyCleaner notifyCleaner,
@ -57,7 +74,7 @@ namespace ASC.Notify
IServiceProvider serviceProvider,
IOptionsMonitor<LogNLog> options)
{
NotifyServiceCfg = notifyServiceCfg;
NotifyServiceCfg = notifyServiceCfg.Value;
NotifyService = notifyService;
NotifySender = notifySender;
NotifyCleaner = notifyCleaner;
@ -100,10 +117,6 @@ namespace ASC.Notify
private void InitializeNotifySchedulers()
{
var scope = ServiceProvider.CreateScope();
var commonLinkUtility = scope.ServiceProvider.GetService<CommonLinkUtility>();
//resolve with options
commonLinkUtility.Initialize(NotifyServiceCfg.ServerRoot);
NotifyConfiguration.Configure(ServiceProvider);
WebItemManager.LoadItems();
foreach (var pair in NotifyServiceCfg.Schedulers.Where(r => r.MethodInfo != null))
@ -113,4 +126,17 @@ namespace ASC.Notify
}
}
}
public static class NotifyServiceLauncherFactory
{
public static IServiceCollection AddNotifyServiceLauncher(this IServiceCollection services)
{
return services
.AddCommonLinkUtilityService()
.AddNotifySender()
.AddNotifyService()
.AddWebItemManager()
.AddNotifyCleaner();
}
}
}

View File

@ -2,14 +2,14 @@
using System.Threading.Tasks;
using ASC.Common.DependencyInjection;
using ASC.Common.Utils;
using ASC.Core.Common;
using ASC.Notify.Config;
using ASC.Web.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
namespace ASC.Notify
{
@ -40,16 +40,14 @@ namespace ASC.Notify
.ConfigureServices((hostContext, services) =>
{
services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
services.AddWebItemManager();
var serviceProvider = services.BuildServiceProvider();
var c = hostContext.Configuration.GetSetting<NotifyServiceCfg>("notify");
c.Init();
services.TryAddSingleton(c);
services.TryAddSingleton<DbWorker>();
services.TryAddSingleton<NotifyCleaner>();
services.TryAddSingleton<NotifySender>();
services.TryAddSingleton<NotifyService>();
services.Configure<NotifyServiceCfg>(hostContext.Configuration.GetSection("notify"));
services.Configure<NotifyServiceCfg>(r => r.Init());
services.TryAddSingleton<CommonLinkUtilitySettings>();
services.AddSingleton<IConfigureOptions<CommonLinkUtilitySettings>, ConfigureCommonLinkUtilitySettings>();
services.AddNotifyServiceLauncher();
services.AddHostedService<NotifyServiceLauncher>();
})
.UseConsoleLifetime()

View File

@ -1,13 +1,9 @@
using System.IO;
using System.Threading.Tasks;
using ASC.Common.DependencyInjection;
using ASC.Data.Storage.Configuration;
using ASC.Notify;
using ASC.Web.Core;
using ASC.Web.Studio.Core.Notify;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
namespace ASC.Studio.Notify
@ -41,11 +37,8 @@ namespace ASC.Studio.Notify
.ConfigureServices((hostContext, services) =>
{
services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
services.AddWebItemManager();
services.TryAddSingleton<StudioNotifyServiceSender>();
services.AddHostedService<ServiceLauncher>();
services.AddHttpContextAccessor()
.AddStorage();
services.AddServiceLauncher();
})
.UseConsoleLifetime()
.Build();

View File

@ -29,7 +29,8 @@ using System.Threading;
using System.Threading.Tasks;
using ASC.Web.Core;
using ASC.Web.Studio.Core.Notify;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
namespace ASC.Notify
@ -62,4 +63,17 @@ namespace ASC.Notify
return Task.CompletedTask;
}
}
public static class ServiceLauncherFactory
{
public static IServiceCollection AddServiceLauncher(this IServiceCollection services)
{
services.TryAddSingleton<StudioNotifyServiceSender>();
return services
.AddWebItemManager()
.AddStudioNotifyServiceSender()
;
}
}
}

View File

@ -36,6 +36,8 @@ using ASC.Core.Tenants;
using ASC.Web.Studio.Utility;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Newtonsoft.Json.Linq;
namespace ASC.Web.Core.Helpers
@ -164,5 +166,14 @@ namespace ASC.Web.Core.Helpers
using var reader = new StreamReader(stream, Encoding.UTF8);
return reader.ReadToEnd();
}
}
}
public static class ApiSystemHelperFactory
{
public static IServiceCollection AddApiSystemHelper(this IServiceCollection services)
{
services.TryAddScoped<ApiSystemHelper>();
return services;
}
}
}

View File

@ -38,6 +38,7 @@ using ASC.Web.Core.Users;
using ASC.Web.Studio.Utility;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace ASC.Web.Studio.Core.Notify
{
@ -145,22 +146,26 @@ namespace ASC.Web.Studio.Core.Notify
public void SendSaasTariffLetters(DateTime scheduleDate)
{
//remove client
StudioPeriodicNotify.SendSaasLetters(EMailSenderName, scheduleDate, ServiceProvider);
using var scope = ServiceProvider.CreateScope();
scope.ServiceProvider.GetService<StudioPeriodicNotify>().SendSaasLetters(EMailSenderName, scheduleDate);
}
public void SendEnterpriseTariffLetters(DateTime scheduleDate)
{
StudioPeriodicNotify.SendEnterpriseLetters(EMailSenderName, scheduleDate, ServiceProvider);
using var scope = ServiceProvider.CreateScope();
scope.ServiceProvider.GetService<StudioPeriodicNotify>().SendEnterpriseLetters(EMailSenderName, scheduleDate);
}
public void SendOpensourceTariffLetters(DateTime scheduleDate)
{
StudioPeriodicNotify.SendOpensourceLetters(EMailSenderName, scheduleDate, ServiceProvider);
using var scope = ServiceProvider.CreateScope();
scope.ServiceProvider.GetService<StudioPeriodicNotify>().SendOpensourceLetters(EMailSenderName, scheduleDate);
}
public void SendLettersPersonal(DateTime scheduleDate)
{
StudioPeriodicNotify.SendPersonalLetters(EMailSenderName, scheduleDate, ServiceProvider);
using var scope = ServiceProvider.CreateScope();
scope.ServiceProvider.GetService<StudioPeriodicNotify>().SendPersonalLetters(EMailSenderName, scheduleDate);
}
public void SendMsgWhatsNew(DateTime scheduleDate)
@ -169,4 +174,25 @@ namespace ASC.Web.Studio.Core.Notify
scope.ServiceProvider.GetService<StudioWhatsNewNotify>().SendMsgWhatsNew(scheduleDate);
}
}
public static class ServiceLauncherFactory
{
public static IServiceCollection AddStudioNotifyServiceSender(this IServiceCollection services)
{
services.TryAddSingleton<StudioNotifyServiceSender>();
return services
.AddStudioPeriodicNotify()
.AddStudioWhatsNewNotify()
.AddTenantManagerService()
.AddUserManagerService()
.AddSecurityContextService()
.AddAuthContextService()
.AddStudioNotifyHelperService()
.AddDisplayUserSettingsService()
.AddTenantExtraService()
.AddCoreBaseSettingsService()
;
}
}
}

View File

@ -46,24 +46,33 @@ using ASC.Web.Core.Users;
using ASC.Web.Core.WhiteLabel;
using ASC.Web.Studio.Utility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace ASC.Web.Studio.Core.Notify
{
public class StudioPeriodicNotify
{
public static void SendSaasLetters(string senderName, DateTime scheduleDate, IServiceProvider serviceProvider)
{
public IServiceProvider ServiceProvider { get; }
public ILog Log { get; }
public StudioPeriodicNotify(IServiceProvider serviceProvider, IOptionsMonitor<LogNLog> log)
{
ServiceProvider = serviceProvider;
Log = log.Get("ASC.Notify");
}
public void SendSaasLetters(string senderName, DateTime scheduleDate)
{
var log = serviceProvider.GetService<IOptionsMonitor<LogNLog>>().Get("ASC.Notify");
var now = scheduleDate.Date;
const string dbid = "webstudio";
log.Info("Start SendSaasTariffLetters");
Log.Info("Start SendSaasTariffLetters");
var activeTenants = new List<Tenant>();
var monthQuotasIds = new List<int>();
using (var scope = serviceProvider.CreateScope())
using (var scope = ServiceProvider.CreateScope())
{
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
@ -71,7 +80,7 @@ namespace ASC.Web.Studio.Core.Notify
if (activeTenants.Count <= 0)
{
log.Info("End SendSaasTariffLetters");
Log.Info("End SendSaasTariffLetters");
return;
}
@ -86,7 +95,7 @@ namespace ASC.Web.Studio.Core.Notify
{
try
{
using var scope = serviceProvider.CreateScope();
using var scope = ServiceProvider.CreateScope();
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
tenantManager.SetCurrentTenant(tenant.TenantId);
@ -302,22 +311,22 @@ namespace ASC.Web.Studio.Core.Notify
{
try
{
log.InfoFormat("start CreateCoupon to {0}", tenant.TenantAlias);
Log.InfoFormat("start CreateCoupon to {0}", tenant.TenantAlias);
coupon = SetupInfo.IsSecretEmail(userManager.GetUsers(tenant.OwnerId).Email)
? tenant.TenantAlias
: couponManager.CreateCoupon(tenantManager);
log.InfoFormat("end CreateCoupon to {0} coupon = {1}", tenant.TenantAlias, coupon);
Log.InfoFormat("end CreateCoupon to {0} coupon = {1}", tenant.TenantAlias, coupon);
}
catch (AggregateException ae)
{
foreach (var ex in ae.InnerExceptions)
log.Error(ex);
Log.Error(ex);
}
catch (Exception ex)
{
log.Error(ex);
Log.Error(ex);
}
}
@ -513,24 +522,23 @@ namespace ASC.Web.Studio.Core.Notify
}
catch (Exception err)
{
log.Error(err);
Log.Error(err);
}
}
log.Info("End SendSaasTariffLetters");
Log.Info("End SendSaasTariffLetters");
}
public static void SendEnterpriseLetters(string senderName, DateTime scheduleDate, IServiceProvider serviceProvider)
public void SendEnterpriseLetters(string senderName, DateTime scheduleDate)
{
var log = serviceProvider.GetService<IOptionsMonitor<LogNLog>>().Get("ASC.Notify");
var now = scheduleDate.Date;
const string dbid = "webstudio";
log.Info("Start SendTariffEnterpriseLetters");
Log.Info("Start SendTariffEnterpriseLetters");
var activeTenants = new List<Tenant>();
using (var scope = serviceProvider.CreateScope())
using (var scope = ServiceProvider.CreateScope())
{
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
@ -538,7 +546,7 @@ namespace ASC.Web.Studio.Core.Notify
if (activeTenants.Count <= 0)
{
log.Info("End SendTariffEnterpriseLetters");
Log.Info("End SendTariffEnterpriseLetters");
return;
}
}
@ -547,7 +555,7 @@ namespace ASC.Web.Studio.Core.Notify
{
try
{
using var scope = serviceProvider.CreateScope();
using var scope = ServiceProvider.CreateScope();
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
var defaultRebranding = scope.ServiceProvider.GetService<MailWhiteLabelSettings>().Instance.IsDefault;
@ -909,23 +917,22 @@ namespace ASC.Web.Studio.Core.Notify
}
catch (Exception err)
{
log.Error(err);
Log.Error(err);
}
}
log.Info("End SendTariffEnterpriseLetters");
Log.Info("End SendTariffEnterpriseLetters");
}
public static void SendOpensourceLetters(string senderName, DateTime scheduleDate, IServiceProvider serviceProvider)
public void SendOpensourceLetters(string senderName, DateTime scheduleDate)
{
var log = serviceProvider.GetService<IOptionsMonitor<LogNLog>>().Get("ASC.Notify");
var now = scheduleDate.Date;
log.Info("Start SendOpensourceTariffLetters");
Log.Info("Start SendOpensourceTariffLetters");
var activeTenants = new List<Tenant>();
using (var scope = serviceProvider.CreateScope())
using (var scope = ServiceProvider.CreateScope())
{
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
@ -933,7 +940,7 @@ namespace ASC.Web.Studio.Core.Notify
if (activeTenants.Count <= 0)
{
log.Info("End SendOpensourceTariffLetters");
Log.Info("End SendOpensourceTariffLetters");
return;
}
}
@ -942,7 +949,7 @@ namespace ASC.Web.Studio.Core.Notify
{
try
{
using var scope = serviceProvider.CreateScope();
using var scope = ServiceProvider.CreateScope();
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
tenantManager.SetCurrentTenant(tenant.TenantId);
@ -1097,23 +1104,21 @@ namespace ASC.Web.Studio.Core.Notify
}
catch (Exception err)
{
log.Error(err);
Log.Error(err);
}
}
log.Info("End SendOpensourceTariffLetters");
Log.Info("End SendOpensourceTariffLetters");
}
public static void SendPersonalLetters(string senderName, DateTime scheduleDate, IServiceProvider serviceProvider)
public void SendPersonalLetters(string senderName, DateTime scheduleDate)
{
var log = serviceProvider.GetService<IOptionsMonitor<LogNLog>>().Get("ASC.Notify");
log.Info("Start SendLettersPersonal...");
Log.Info("Start SendLettersPersonal...");
var activeTenants = new List<Tenant>();
using (var scope = serviceProvider.CreateScope())
using (var scope = ServiceProvider.CreateScope())
{
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
@ -1129,7 +1134,7 @@ namespace ASC.Web.Studio.Core.Notify
var sendCount = 0;
using var scope = serviceProvider.CreateScope();
using var scope = ServiceProvider.CreateScope();
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
tenantManager.SetCurrentTenant(tenant.TenantId);
@ -1141,7 +1146,7 @@ namespace ASC.Web.Studio.Core.Notify
var coreBaseSettings = scope.ServiceProvider.GetService<CoreBaseSettings>();
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(studioNotifyHelper.NotifySource, scope);
log.InfoFormat("Current tenant: {0}", tenant.TenantId);
Log.InfoFormat("Current tenant: {0}", tenant.TenantId);
var users = userManager.GetUsers(EmployeeStatus.Active);
@ -1161,7 +1166,7 @@ namespace ASC.Web.Studio.Core.Notify
catch (CultureNotFoundException exception)
{
log.Error(exception);
Log.Error(exception);
}
}
@ -1207,7 +1212,7 @@ namespace ASC.Web.Studio.Core.Notify
if (action == null) continue;
log.InfoFormat(@"Send letter personal '{1}' to {0} culture {2}. tenant id: {3} user culture {4} create on {5} now date {6}",
Log.InfoFormat(@"Send letter personal '{1}' to {0} culture {2}. tenant id: {3} user culture {4} create on {5} now date {6}",
user.Email, action.ID, culture, tenant.TenantId, user.GetCulture(), user.CreateDate, scheduleDate.Date);
sendCount++;
@ -1223,15 +1228,15 @@ namespace ASC.Web.Studio.Core.Notify
new TagValue(CommonTags.Footer, coreBaseSettings.CustomMode ? "personalCustomMode" : "personal"));
}
log.InfoFormat("Total send count: {0}", sendCount);
Log.InfoFormat("Total send count: {0}", sendCount);
}
catch (Exception err)
{
log.Error(err);
Log.Error(err);
}
}
log.Info("End SendLettersPersonal.");
Log.Info("End SendLettersPersonal.");
}
public static bool ChangeSubscription(Guid userId, StudioNotifyHelper studioNotifyHelper)
@ -1244,5 +1249,29 @@ namespace ASC.Web.Studio.Core.Notify
return !isSubscribe;
}
}
}
public static class StudioPeriodicNotifyFactory
{
public static IServiceCollection AddStudioPeriodicNotify(this IServiceCollection services)
{
services.TryAddSingleton<StudioPeriodicNotify>();
services.TryAddSingleton<CouponManager>();
return services
.AddApiSystemHelper()
.AddTenantManagerService()
.AddUserManagerService()
.AddStudioNotifyHelperService()
.AddPaymentManagerService()
.AddTenantExtraService()
.AddAuthContextService()
.AddCommonLinkUtilityService()
.AddSetupInfo()
.AddDbManagerService()
.AddCoreBaseSettingsService()
.AddDisplayUserSettingsService()
.AddSecurityContextService()
.AddAuthManager();
}
}
}

View File

@ -44,6 +44,7 @@ using ASC.Web.Core.Users;
using ASC.Web.Studio.Utility;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace ASC.Web.Studio.Core.Notify
@ -300,5 +301,30 @@ namespace ASC.Web.Studio.Core.Notify
public DateTime Date { get; set; }
public string Action { get; set; }
}
}
}
public static class StudioWhatsNewNotifyFactory
{
public static IServiceCollection AddStudioWhatsNewNotify(this IServiceCollection services)
{
services.TryAddSingleton<StudioWhatsNewNotify>();
return services
.AddWebItemManager()
.AddFeedAggregateDataProvider()
.AddTenantManagerService()
.AddPaymentManagerService()
.AddStudioNotifyHelperService()
.AddUserManagerService()
.AddSecurityContextService()
.AddAuthContextService()
.AddAuthManager()
.AddTenantUtilService()
.AddCommonLinkUtilityService()
.AddDisplayUserSettingsService()
.AddCoreSettingsService()
;
}
}
}

View File

@ -85,8 +85,9 @@ namespace ASC.Web.Studio.Utility
WebItemManagerSecurity webItemManagerSecurity,
WebItemManager webItemManager,
EmailValidationKeyProvider emailValidationKeyProvider,
IOptionsMonitor<LogNLog> options) :
this(null, coreBaseSettings, coreSettings, tenantManager, userManager, webItemManagerSecurity, webItemManager, emailValidationKeyProvider, options)
IOptionsMonitor<LogNLog> options,
IOptions<CommonLinkUtilitySettings> settings) :
this(null, coreBaseSettings, coreSettings, tenantManager, userManager, webItemManagerSecurity, webItemManager, emailValidationKeyProvider, options, settings)
{
}
@ -99,8 +100,9 @@ namespace ASC.Web.Studio.Utility
WebItemManagerSecurity webItemManagerSecurity,
WebItemManager webItemManager,
EmailValidationKeyProvider emailValidationKeyProvider,
IOptionsMonitor<LogNLog> options) :
base(httpContextAccessor, coreBaseSettings, coreSettings, tenantManager, options) =>
IOptionsMonitor<LogNLog> options,
IOptions<CommonLinkUtilitySettings> settings) :
base(httpContextAccessor, coreBaseSettings, coreSettings, tenantManager, options, settings) =>
(UserManager, WebItemManagerSecurity, WebItemManager, EmailValidationKeyProvider) = (userManager, webItemManagerSecurity, webItemManager, emailValidationKeyProvider);
public string Logout