DocSpace-client/web/ASC.Web.Core/Notify/StudioPeriodicNotify.cs

1346 lines
71 KiB
C#
Raw Normal View History

/*
*
* (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 System.Collections.Generic;
using System.Globalization;
using System.Linq;
2020-02-17 08:58:14 +00:00
using System.Threading;
2020-08-12 09:58:08 +00:00
2020-02-17 08:58:14 +00:00
using ASC.Common;
using ASC.Common.Logging;
using ASC.Core;
using ASC.Core.Billing;
using ASC.Core.Common.Billing;
2020-02-17 08:58:14 +00:00
using ASC.Core.Common.EF;
using ASC.Core.Common.EF.Context;
using ASC.Core.Common.Settings;
using ASC.Core.Tenants;
using ASC.Core.Users;
using ASC.Notify.Model;
using ASC.Notify.Patterns;
using ASC.Web.Core.Helpers;
2019-11-06 15:03:09 +00:00
using ASC.Web.Core.PublicResources;
using ASC.Web.Core.Users;
using ASC.Web.Core.WhiteLabel;
2020-02-17 08:58:14 +00:00
using ASC.Web.Studio.Utility;
using Microsoft.Extensions.Configuration;
2019-11-06 15:03:09 +00:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace ASC.Web.Studio.Core.Notify
{
public class StudioPeriodicNotify
2019-11-06 15:03:09 +00:00
{
2020-08-12 09:58:08 +00:00
private IServiceProvider ServiceProvider { get; }
2019-11-06 15:03:09 +00:00
public ILog Log { get; }
public StudioPeriodicNotify(IServiceProvider serviceProvider, IOptionsMonitor<ILog> log)
{
ServiceProvider = serviceProvider;
Log = log.Get("ASC.Notify");
}
2019-11-01 08:49:08 +00:00
public void SendSaasLetters(string senderName, DateTime scheduleDate)
{
2020-01-23 08:52:07 +00:00
var nowDate = scheduleDate.Date;
const string dbid = "webstudio";
2019-11-06 15:03:09 +00:00
Log.Info("Start SendSaasTariffLetters");
var activeTenants = new List<Tenant>();
var monthQuotasIds = new List<int>();
using (var scope = ServiceProvider.CreateScope())
{
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
activeTenants = tenantManager.GetTenants().ToList();
if (activeTenants.Count <= 0)
{
Log.Info("End SendSaasTariffLetters");
return;
}
}
foreach (var tenant in activeTenants)
{
try
2019-11-06 15:03:09 +00:00
{
using var scope = ServiceProvider.CreateScope();
2020-08-24 18:41:06 +00:00
var scopeClass = scope.ServiceProvider.GetService<StudioPeriodicNotifyScope>();
2020-09-07 12:01:15 +00:00
var (tenantManager, userManager, studioNotifyHelper, paymentManager, tenantExtra, authContext, commonLinkUtility, apiSystemHelper, setupInfo, dbContextManager, couponManager, _, _, _, _, _, _) = scopeClass;
2020-08-31 08:18:07 +00:00
tenantManager.SetCurrentTenant(tenant.TenantId);
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(studioNotifyHelper.NotifySource, scope);
2020-07-30 13:33:54 +00:00
2020-08-31 08:18:07 +00:00
var tariff = paymentManager.GetTariff(tenant.TenantId);
var quota = tenantManager.GetTenantQuota(tenant.TenantId);
2020-02-17 08:58:14 +00:00
var createdDate = tenant.CreatedDateTime.Date;
var dueDateIsNotMax = tariff.DueDate != DateTime.MaxValue;
var dueDate = tariff.DueDate.Date;
var delayDueDateIsNotMax = tariff.DelayDueDate != DateTime.MaxValue;
2020-01-23 08:52:07 +00:00
var delayDueDate = tariff.DelayDueDate.Date;
INotifyAction action = null;
var paymentMessage = true;
var toadmins = false;
var tousers = false;
var toowner = false;
var coupon = string.Empty;
Func<string> greenButtonText = () => string.Empty;
2019-08-15 14:36:08 +00:00
string blueButtonText() => WebstudioNotifyPatternResource.ButtonRequestCallButton;
var greenButtonUrl = string.Empty;
Func<string> tableItemText1 = () => string.Empty;
Func<string> tableItemText2 = () => string.Empty;
Func<string> tableItemText3 = () => string.Empty;
Func<string> tableItemText4 = () => string.Empty;
Func<string> tableItemText5 = () => string.Empty;
Func<string> tableItemText6 = () => string.Empty;
Func<string> tableItemText7 = () => string.Empty;
var tableItemUrl1 = string.Empty;
var tableItemUrl2 = string.Empty;
var tableItemUrl3 = string.Empty;
var tableItemUrl4 = string.Empty;
var tableItemUrl5 = string.Empty;
var tableItemUrl6 = string.Empty;
var tableItemUrl7 = string.Empty;
var tableItemImg1 = string.Empty;
var tableItemImg2 = string.Empty;
var tableItemImg3 = string.Empty;
var tableItemImg4 = string.Empty;
var tableItemImg5 = string.Empty;
var tableItemImg6 = string.Empty;
var tableItemImg7 = string.Empty;
Func<string> tableItemComment1 = () => string.Empty;
Func<string> tableItemComment2 = () => string.Empty;
Func<string> tableItemComment3 = () => string.Empty;
Func<string> tableItemComment4 = () => string.Empty;
Func<string> tableItemComment5 = () => string.Empty;
Func<string> tableItemComment6 = () => string.Empty;
Func<string> tableItemComment7 = () => string.Empty;
Func<string> tableItemLearnMoreText1 = () => string.Empty;
2019-08-15 14:36:08 +00:00
string tableItemLearnMoreText2() => string.Empty;
string tableItemLearnMoreText3() => string.Empty;
string tableItemLearnMoreText4() => string.Empty;
string tableItemLearnMoreText5() => string.Empty;
string tableItemLearnMoreText6() => string.Empty;
string tableItemLearnMoreText7() => string.Empty;
var tableItemLearnMoreUrl1 = string.Empty;
var tableItemLearnMoreUrl2 = string.Empty;
var tableItemLearnMoreUrl3 = string.Empty;
var tableItemLearnMoreUrl4 = string.Empty;
var tableItemLearnMoreUrl5 = string.Empty;
var tableItemLearnMoreUrl6 = string.Empty;
var tableItemLearnMoreUrl7 = string.Empty;
if (quota.Trial)
{
#region After registration letters
#region 3 days after registration to admins SAAS TRIAL + only 1 user
2020-08-31 08:18:07 +00:00
if (createdDate.AddDays(3) == nowDate && userManager.GetUsers().Count() == 1)
{
action = Actions.SaasAdminInviteTeammatesV10;
paymentMessage = false;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonInviteRightNow;
2020-08-31 08:18:07 +00:00
greenButtonUrl = string.Format("{0}/products/people/", commonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/'));
}
#endregion
#region 5 days after registration to admins SAAS TRAIL + without activity in 1 or more days
2020-01-23 08:52:07 +00:00
else if (createdDate.AddDays(5) == nowDate)
{
List<DateTime> datesWithActivity;
2020-02-17 08:58:14 +00:00
datesWithActivity =
2020-08-31 08:18:07 +00:00
dbContextManager.Get(dbid).FeedAggregates
.Where(r => r.Tenant == tenantManager.GetCurrentTenant().TenantId)
2020-02-17 08:58:14 +00:00
.Where(r => r.CreatedDate <= nowDate.AddDays(-1))
.GroupBy(r => r.CreatedDate.Date)
.Select(r => r.Key)
2019-12-10 09:05:28 +00:00
.ToList();
if (datesWithActivity.Count < 5)
{
action = Actions.SaasAdminWithoutActivityV10;
paymentMessage = false;
toadmins = true;
}
}
#endregion
#region 7 days after registration to admins and users SAAS TRIAL
2020-01-23 08:52:07 +00:00
else if (createdDate.AddDays(7) == nowDate)
{
action = Actions.SaasAdminUserDocsTipsV10;
paymentMessage = false;
toadmins = true;
tousers = true;
2020-08-31 08:18:07 +00:00
tableItemImg1 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-formatting-100.png");
tableItemText1 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_formatting_hdr;
tableItemComment1 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_formatting;
2020-08-31 08:18:07 +00:00
tableItemLearnMoreUrl1 = studioNotifyHelper.Helplink + "/onlyoffice-editors/index.aspx";
tableItemLearnMoreText1 = () => WebstudioNotifyPatternResource.LinkLearnMore;
2020-08-31 08:18:07 +00:00
tableItemImg2 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-share-100.png");
tableItemText2 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_share_hdr;
tableItemComment2 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_share;
2020-08-31 08:18:07 +00:00
tableItemImg3 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-coediting-100.png");
tableItemText3 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_coediting_hdr;
tableItemComment3 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_coediting;
2020-08-31 08:18:07 +00:00
tableItemImg4 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-review-100.png");
tableItemText4 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_review_hdr;
tableItemComment4 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_review;
2020-08-31 08:18:07 +00:00
tableItemImg5 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-3rdparty-100.png");
tableItemText5 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_3rdparty_hdr;
tableItemComment5 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_3rdparty;
2020-08-31 08:18:07 +00:00
tableItemImg6 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-attach-100.png");
tableItemText6 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_attach_hdr;
tableItemComment6 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_attach;
2020-08-31 08:18:07 +00:00
tableItemImg7 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-apps-100.png");
tableItemText7 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_apps_hdr;
tableItemComment7 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_apps;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonAccessYouWebOffice;
2020-08-31 08:18:07 +00:00
greenButtonUrl = string.Format("{0}/products/files/", commonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/'));
}
#endregion
#region 14 days after registration to admins and users SAAS TRIAL
2020-01-23 08:52:07 +00:00
else if (createdDate.AddDays(14) == nowDate)
{
action = Actions.SaasAdminUserComfortTipsV10;
paymentMessage = false;
toadmins = true;
tousers = true;
}
#endregion
#region 21 days after registration to admins and users SAAS TRIAL
2020-01-23 08:52:07 +00:00
else if (createdDate.AddDays(21) == nowDate)
{
action = Actions.SaasAdminUserAppsTipsV10;
paymentMessage = false;
toadmins = true;
tousers = true;
}
#endregion
#endregion
#region Trial warning letters
#region 5 days before SAAS TRIAL ends to admins
2020-01-23 08:52:07 +00:00
else if (dueDateIsNotMax && dueDate.AddDays(-5) == nowDate)
{
toadmins = true;
action = Actions.SaasAdminTrialWarningBefore5V10;
coupon = "PortalCreation10%";
if (string.IsNullOrEmpty(coupon))
{
try
{
2019-11-01 08:49:08 +00:00
Log.InfoFormat("start CreateCoupon to {0}", tenant.TenantAlias);
2020-08-31 08:18:07 +00:00
coupon = SetupInfo.IsSecretEmail(userManager.GetUsers(tenant.OwnerId).Email)
? tenant.TenantAlias
2020-08-31 08:18:07 +00:00
: couponManager.CreateCoupon(tenantManager);
2019-11-01 08:49:08 +00:00
Log.InfoFormat("end CreateCoupon to {0} coupon = {1}", tenant.TenantAlias, coupon);
}
catch (AggregateException ae)
{
foreach (var ex in ae.InnerExceptions)
2019-11-01 08:49:08 +00:00
Log.Error(ex);
}
catch (Exception ex)
{
2019-11-01 08:49:08 +00:00
Log.Error(ex);
}
}
greenButtonText = () => WebstudioNotifyPatternResource.ButtonUseDiscount;
2020-08-31 08:18:07 +00:00
greenButtonUrl = commonLinkUtility.GetFullAbsolutePath("~/tariffs.aspx");
}
#endregion
#region SAAS TRIAL expires today to admins
2020-01-23 08:52:07 +00:00
else if (dueDate == nowDate)
{
action = Actions.SaasAdminTrialWarningV10;
toadmins = true;
}
#endregion
#region 5 days after SAAS TRIAL expired to admins
2020-01-23 08:52:07 +00:00
else if (dueDateIsNotMax && dueDate.AddDays(5) == nowDate && tenant.VersionChanged <= tenant.CreatedDateTime)
{
action = Actions.SaasAdminTrialWarningAfter5V10;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonSendRequest;
greenButtonUrl = "mailto:sales@onlyoffice.com";
}
#endregion
#region 30 days after SAAS TRIAL expired + only 1 user
2020-08-31 08:18:07 +00:00
else if (dueDateIsNotMax && dueDate.AddDays(30) == nowDate && userManager.GetUsers().Count() == 1)
{
action = Actions.SaasAdminTrialWarningAfter30V10;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonStartNow;
greenButtonUrl = "https://personal.onlyoffice.com";
}
#endregion
#region 6 months after SAAS TRIAL expired
2020-01-23 08:52:07 +00:00
else if (dueDateIsNotMax && dueDate.AddMonths(6) == nowDate)
{
action = Actions.SaasAdminTrialWarningAfterHalfYearV10;
toowner = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonLeaveFeedback;
2020-08-31 08:18:07 +00:00
var owner = userManager.GetUsers(tenant.OwnerId);
greenButtonUrl = setupInfo.TeamlabSiteRedirect + "/remove-portal-feedback-form.aspx#" +
2020-01-23 08:52:07 +00:00
System.Web.HttpUtility.UrlEncode(Convert.ToBase64String(
System.Text.Encoding.UTF8.GetBytes("{\"firstname\":\"" + owner.FirstName +
"\",\"lastname\":\"" + owner.LastName +
"\",\"alias\":\"" + tenant.TenantAlias +
2020-01-23 08:52:07 +00:00
"\",\"email\":\"" + owner.Email + "\"}")));
}
2020-01-23 08:52:07 +00:00
else if (dueDateIsNotMax && dueDate.AddMonths(6).AddDays(7) <= nowDate)
{
2020-08-31 08:18:07 +00:00
tenantManager.RemoveTenant(tenant.TenantId, true);
2020-08-31 08:18:07 +00:00
if (!string.IsNullOrEmpty(apiSystemHelper.ApiCacheUrl))
{
2020-08-31 08:18:07 +00:00
apiSystemHelper.RemoveTenantFromCache(tenant.TenantAlias, authContext.CurrentAccount.ID);
}
}
#endregion
#endregion
}
else if (tariff.State >= TariffState.Paid)
{
#region Payment warning letters
#region 5 days before SAAS PAID expired to admins
2020-01-23 08:52:07 +00:00
if (tariff.State == TariffState.Paid && dueDateIsNotMax && dueDate.AddDays(-5) == nowDate)
{
action = Actions.SaasAdminPaymentWarningBefore5V10;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonRenewNow;
2020-08-31 08:18:07 +00:00
greenButtonUrl = commonLinkUtility.GetFullAbsolutePath("~/tariffs.aspx");
}
#endregion
#region 1 day after SAAS PAID expired to admins
2020-01-23 08:52:07 +00:00
else if (tariff.State >= TariffState.Paid && dueDateIsNotMax && dueDate.AddDays(1) == nowDate)
{
action = Actions.SaasAdminPaymentWarningAfter1V10;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonRenewNow;
2020-08-31 08:18:07 +00:00
greenButtonUrl = commonLinkUtility.GetFullAbsolutePath("~/tariffs.aspx");
}
#endregion
2020-01-23 08:52:07 +00:00
#region 2 weeks before monthly SAAS PAID tariff expired to admins
2020-01-23 08:52:07 +00:00
else if (tariff.State == TariffState.Paid && !quota.Year && !quota.Year3 && dueDateIsNotMax && dueDate.AddDays(-14) == nowDate)
{
action = Actions.SaasAdminPaymentAfterMonthlySubscriptionsV10;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonBuyNow;
2020-08-31 08:18:07 +00:00
greenButtonUrl = commonLinkUtility.GetFullAbsolutePath("~/tariffs.aspx");
}
#endregion
#region 6 months after SAAS PAID expired
2020-01-23 08:52:07 +00:00
else if (tariff.State == TariffState.NotPaid && dueDateIsNotMax && dueDate.AddMonths(6) == nowDate)
{
action = Actions.SaasAdminTrialWarningAfterHalfYearV10;
toowner = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonLeaveFeedback;
2020-08-31 08:18:07 +00:00
var owner = userManager.GetUsers(tenant.OwnerId);
greenButtonUrl = setupInfo.TeamlabSiteRedirect + "/remove-portal-feedback-form.aspx#" +
2020-01-23 08:52:07 +00:00
System.Web.HttpUtility.UrlEncode(Convert.ToBase64String(
System.Text.Encoding.UTF8.GetBytes("{\"firstname\":\"" + owner.FirstName +
"\",\"lastname\":\"" + owner.LastName +
"\",\"alias\":\"" + tenant.TenantAlias +
2020-01-23 08:52:07 +00:00
"\",\"email\":\"" + owner.Email + "\"}")));
}
2020-01-23 08:52:07 +00:00
else if (tariff.State == TariffState.NotPaid && dueDateIsNotMax && dueDate.AddMonths(6).AddDays(7) <= nowDate)
{
2020-08-31 08:18:07 +00:00
tenantManager.RemoveTenant(tenant.TenantId, true);
2020-08-31 08:18:07 +00:00
if (!string.IsNullOrEmpty(apiSystemHelper.ApiCacheUrl))
{
2020-08-31 08:18:07 +00:00
apiSystemHelper.RemoveTenantFromCache(tenant.TenantAlias, authContext.CurrentAccount.ID);
}
}
#endregion
#endregion
}
if (action == null) continue;
var users = toowner
2020-08-31 08:18:07 +00:00
? new List<UserInfo> { userManager.GetUsers(tenant.OwnerId) }
: studioNotifyHelper.GetRecipients(toadmins, tousers, false);
2020-08-31 08:18:07 +00:00
var analytics = studioNotifyHelper.GetNotifyAnalytics(action, toowner, toadmins, tousers, false);
2020-08-31 08:18:07 +00:00
foreach (var u in users.Where(u => paymentMessage || studioNotifyHelper.IsSubscribedToNotify(u, Actions.PeriodicNotify)))
{
var culture = string.IsNullOrEmpty(u.CultureName) ? tenant.GetCulture() : u.GetCulture();
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
2020-08-31 08:18:07 +00:00
var rquota = tenantExtra.GetRightQuota() ?? TenantQuota.Default;
client.SendNoticeToAsync(
action,
2020-08-31 08:18:07 +00:00
new[] { studioNotifyHelper.ToRecipient(u.ID) },
new[] { senderName },
new TagValue(Tags.UserName, u.FirstName.HtmlEncode()),
2020-08-31 08:18:07 +00:00
new TagValue(Tags.PricingPage, commonLinkUtility.GetFullAbsolutePath("~/tariffs.aspx")),
new TagValue(Tags.ActiveUsers, userManager.GetUsers().Count()),
new TagValue(Tags.Price, rquota.Price),
new TagValue(Tags.PricePeriod, rquota.Year3 ? UserControlsCommonResource.TariffPerYear3 : rquota.Year ? UserControlsCommonResource.TariffPerYear : UserControlsCommonResource.TariffPerMonth),
2020-02-17 08:58:14 +00:00
new TagValue(Tags.DueDate, dueDate.ToLongDateString()),
2020-01-23 08:52:07 +00:00
new TagValue(Tags.DelayDueDate, (delayDueDateIsNotMax ? delayDueDate : dueDate).ToLongDateString()),
TagValues.BlueButton(blueButtonText, "http://www.onlyoffice.com/call-back-form.aspx"),
TagValues.GreenButton(greenButtonText, greenButtonUrl),
TagValues.TableTop(),
TagValues.TableItem(1, tableItemText1, tableItemUrl1, tableItemImg1, tableItemComment1, tableItemLearnMoreText1, tableItemLearnMoreUrl1),
TagValues.TableItem(2, tableItemText2, tableItemUrl2, tableItemImg2, tableItemComment2, tableItemLearnMoreText2, tableItemLearnMoreUrl2),
TagValues.TableItem(3, tableItemText3, tableItemUrl3, tableItemImg3, tableItemComment3, tableItemLearnMoreText3, tableItemLearnMoreUrl3),
TagValues.TableItem(4, tableItemText4, tableItemUrl4, tableItemImg4, tableItemComment4, tableItemLearnMoreText4, tableItemLearnMoreUrl4),
TagValues.TableItem(5, tableItemText5, tableItemUrl5, tableItemImg5, tableItemComment5, tableItemLearnMoreText5, tableItemLearnMoreUrl5),
TagValues.TableItem(6, tableItemText6, tableItemUrl6, tableItemImg6, tableItemComment6, tableItemLearnMoreText6, tableItemLearnMoreUrl6),
TagValues.TableItem(7, tableItemText7, tableItemUrl7, tableItemImg7, tableItemComment7, tableItemLearnMoreText7, tableItemLearnMoreUrl7),
TagValues.TableBottom(),
2020-08-31 08:18:07 +00:00
new TagValue(CommonTags.Footer, u.IsAdmin(userManager) ? "common" : "social"),
new TagValue(CommonTags.Analytics, analytics),
new TagValue(Tags.Coupon, coupon));
}
}
catch (Exception err)
{
2019-11-01 08:49:08 +00:00
Log.Error(err);
}
}
2019-11-01 08:49:08 +00:00
Log.Info("End SendSaasTariffLetters");
2020-07-30 13:33:54 +00:00
}
2019-11-01 08:49:08 +00:00
public void SendEnterpriseLetters(string senderName, DateTime scheduleDate)
{
2020-01-23 08:52:07 +00:00
var nowDate = scheduleDate.Date;
const string dbid = "webstudio";
2019-11-06 15:03:09 +00:00
Log.Info("Start SendTariffEnterpriseLetters");
var activeTenants = new List<Tenant>();
using (var scope = ServiceProvider.CreateScope())
{
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
activeTenants = tenantManager.GetTenants().ToList();
if (activeTenants.Count <= 0)
{
Log.Info("End SendTariffEnterpriseLetters");
return;
}
}
foreach (var tenant in activeTenants)
{
try
2019-11-06 15:03:09 +00:00
{
using var scope = ServiceProvider.CreateScope();
2020-08-31 08:18:07 +00:00
var scopeClass = scope.ServiceProvider.GetService<StudioPeriodicNotifyScope>();
2020-09-07 12:01:15 +00:00
var (tenantManager, userManager, studioNotifyHelper, paymentManager, tenantExtra, _, commonLinkUtility, _, _, dbContextManager, _, configuration, settingsManager, coreBaseSettings, _, _, _) = scopeClass;
2020-08-31 08:18:07 +00:00
var defaultRebranding = MailWhiteLabelSettings.IsDefault(settingsManager, configuration);
tenantManager.SetCurrentTenant(tenant.TenantId);
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(studioNotifyHelper.NotifySource, scope);
var tariff = paymentManager.GetTariff(tenant.TenantId);
var quota = tenantManager.GetTenantQuota(tenant.TenantId);
2020-02-17 08:58:14 +00:00
var createdDate = tenant.CreatedDateTime.Date;
var dueDateIsNotMax = tariff.DueDate != DateTime.MaxValue;
var dueDate = tariff.DueDate.Date;
var delayDueDateIsNotMax = tariff.DelayDueDate != DateTime.MaxValue;
2020-01-23 08:52:07 +00:00
var delayDueDate = tariff.DelayDueDate.Date;
INotifyAction action = null;
var paymentMessage = true;
var toadmins = false;
var tousers = false;
Func<string> greenButtonText = () => string.Empty;
2019-08-15 14:36:08 +00:00
string blueButtonText() => WebstudioNotifyPatternResource.ButtonRequestCallButton;
var greenButtonUrl = string.Empty;
Func<string> tableItemText1 = () => string.Empty;
Func<string> tableItemText2 = () => string.Empty;
Func<string> tableItemText3 = () => string.Empty;
Func<string> tableItemText4 = () => string.Empty;
Func<string> tableItemText5 = () => string.Empty;
Func<string> tableItemText6 = () => string.Empty;
Func<string> tableItemText7 = () => string.Empty;
var tableItemUrl1 = string.Empty;
var tableItemUrl2 = string.Empty;
var tableItemUrl3 = string.Empty;
var tableItemUrl4 = string.Empty;
var tableItemUrl5 = string.Empty;
var tableItemUrl6 = string.Empty;
var tableItemUrl7 = string.Empty;
var tableItemImg1 = string.Empty;
var tableItemImg2 = string.Empty;
var tableItemImg3 = string.Empty;
var tableItemImg4 = string.Empty;
var tableItemImg5 = string.Empty;
var tableItemImg6 = string.Empty;
var tableItemImg7 = string.Empty;
Func<string> tableItemComment1 = () => string.Empty;
Func<string> tableItemComment2 = () => string.Empty;
Func<string> tableItemComment3 = () => string.Empty;
Func<string> tableItemComment4 = () => string.Empty;
Func<string> tableItemComment5 = () => string.Empty;
Func<string> tableItemComment6 = () => string.Empty;
Func<string> tableItemComment7 = () => string.Empty;
Func<string> tableItemLearnMoreText1 = () => string.Empty;
2019-08-15 14:36:08 +00:00
string tableItemLearnMoreText2() => string.Empty;
string tableItemLearnMoreText3() => string.Empty;
string tableItemLearnMoreText4() => string.Empty;
string tableItemLearnMoreText5() => string.Empty;
string tableItemLearnMoreText6() => string.Empty;
string tableItemLearnMoreText7() => string.Empty;
var tableItemLearnMoreUrl1 = string.Empty;
var tableItemLearnMoreUrl2 = string.Empty;
var tableItemLearnMoreUrl3 = string.Empty;
var tableItemLearnMoreUrl4 = string.Empty;
var tableItemLearnMoreUrl5 = string.Empty;
var tableItemLearnMoreUrl6 = string.Empty;
var tableItemLearnMoreUrl7 = string.Empty;
if (quota.Trial && defaultRebranding)
{
#region After registration letters
#region 1 day after registration to admins ENTERPRISE TRIAL + defaultRebranding
2020-01-23 08:52:07 +00:00
if (createdDate.AddDays(1) == nowDate)
{
action = Actions.EnterpriseAdminCustomizePortalV10;
paymentMessage = false;
toadmins = true;
2020-08-31 08:18:07 +00:00
tableItemImg1 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-brand-100.png");
tableItemText1 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_brand_hdr;
tableItemComment1 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_brand;
2020-08-31 08:18:07 +00:00
tableItemImg2 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-regional-100.png");
tableItemText2 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_regional_hdr;
tableItemComment2 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_regional;
2020-08-31 08:18:07 +00:00
tableItemImg3 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-customize-100.png");
tableItemText3 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_customize_hdr;
tableItemComment3 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_customize;
2020-08-31 08:18:07 +00:00
tableItemImg4 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-modules-100.png");
tableItemText4 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_modules_hdr;
tableItemComment4 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_modules;
2020-08-31 08:18:07 +00:00
tableItemImg5 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-3rdparty-100.png");
tableItemText5 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_3rdparty_hdr;
tableItemComment5 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_3rdparty;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonConfigureRightNow;
2020-08-31 08:18:07 +00:00
greenButtonUrl = commonLinkUtility.GetFullAbsolutePath(commonLinkUtility.GetAdministration(ManagementType.General));
}
#endregion
#region 4 days after registration to admins ENTERPRISE TRIAL + only 1 user + defaultRebranding
2020-08-31 08:18:07 +00:00
else if (createdDate.AddDays(4) == nowDate && userManager.GetUsers().Count() == 1)
{
action = Actions.EnterpriseAdminInviteTeammatesV10;
paymentMessage = false;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonInviteRightNow;
2020-08-31 08:18:07 +00:00
greenButtonUrl = string.Format("{0}/products/people/", commonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/'));
}
#endregion
#region 5 days after registration to admins ENTERPRISE TRAIL + without activity in 1 or more days + defaultRebranding
2020-01-23 08:52:07 +00:00
else if (createdDate.AddDays(5) == nowDate)
{
List<DateTime> datesWithActivity;
2020-02-17 08:58:14 +00:00
datesWithActivity =
2020-08-31 08:18:07 +00:00
dbContextManager.Get(dbid).FeedAggregates
.Where(r => r.Tenant == tenantManager.GetCurrentTenant().TenantId)
2020-02-17 08:58:14 +00:00
.Where(r => r.CreatedDate <= nowDate.AddDays(-1))
.GroupBy(r => r.CreatedDate.Date)
.Select(r => r.Key)
.ToList();
if (datesWithActivity.Count < 5)
{
action = Actions.EnterpriseAdminWithoutActivityV10;
paymentMessage = false;
toadmins = true;
}
}
#endregion
#region 7 days after registration to admins and users ENTERPRISE TRIAL + defaultRebranding
2020-01-23 08:52:07 +00:00
else if (createdDate.AddDays(7) == nowDate)
{
action = Actions.EnterpriseAdminUserDocsTipsV10;
paymentMessage = false;
toadmins = true;
tousers = true;
2020-08-31 08:18:07 +00:00
tableItemImg1 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-formatting-100.png");
tableItemText1 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_formatting_hdr;
tableItemComment1 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_formatting;
2020-08-31 08:18:07 +00:00
tableItemLearnMoreUrl1 = studioNotifyHelper.Helplink + "/onlyoffice-editors/index.aspx";
tableItemLearnMoreText1 = () => WebstudioNotifyPatternResource.LinkLearnMore;
2020-08-31 08:18:07 +00:00
tableItemImg2 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-share-100.png");
tableItemText2 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_share_hdr;
tableItemComment2 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_share;
2020-08-31 08:18:07 +00:00
tableItemImg3 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-coediting-100.png");
tableItemText3 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_coediting_hdr;
tableItemComment3 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_coediting;
2020-08-31 08:18:07 +00:00
tableItemImg4 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-review-100.png");
tableItemText4 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_review_hdr;
tableItemComment4 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_review;
2020-08-31 08:18:07 +00:00
tableItemImg5 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-3rdparty-100.png");
tableItemText5 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_3rdparty_hdr;
tableItemComment5 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_3rdparty;
2020-08-31 08:18:07 +00:00
tableItemImg6 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-attach-100.png");
tableItemText6 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_attach_hdr;
tableItemComment6 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_attach;
2020-08-31 08:18:07 +00:00
tableItemImg7 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-apps-100.png");
tableItemText7 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_apps_hdr;
tableItemComment7 = () => WebstudioNotifyPatternResource.pattern_saas_admin_user_docs_tips_v10_item_apps;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonAccessYouWebOffice;
2020-08-31 08:18:07 +00:00
greenButtonUrl = string.Format("{0}/products/files/", commonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/'));
}
#endregion
#region 21 days after registration to admins and users ENTERPRISE TRIAL + defaultRebranding
2020-01-23 08:52:07 +00:00
else if (createdDate.AddDays(21) == nowDate)
{
action = Actions.EnterpriseAdminUserAppsTipsV10;
paymentMessage = false;
toadmins = true;
tousers = true;
}
#endregion
#endregion
#region Trial warning letters
#region 7 days before ENTERPRISE TRIAL ends to admins + defaultRebranding
2020-01-23 08:52:07 +00:00
else if (dueDateIsNotMax && dueDate.AddDays(-7) == nowDate)
{
action = Actions.EnterpriseAdminTrialWarningBefore7V10;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonSelectPricingPlans;
greenButtonUrl = "http://www.onlyoffice.com/enterprise-edition.aspx";
}
#endregion
#region ENTERPRISE TRIAL expires today to admins + defaultRebranding
2020-01-23 08:52:07 +00:00
else if (dueDate == nowDate)
{
action = Actions.EnterpriseAdminTrialWarningV10;
toadmins = true;
}
#endregion
#endregion
}
else if (quota.Trial && !defaultRebranding)
{
#region After registration letters
#region 1 day after registration to admins ENTERPRISE TRIAL + !defaultRebranding
2020-01-23 08:52:07 +00:00
if (createdDate.AddDays(1) == nowDate)
{
action = Actions.EnterpriseWhitelabelAdminCustomizePortalV10;
paymentMessage = false;
toadmins = true;
2020-08-31 08:18:07 +00:00
tableItemImg1 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-brand-100.png");
tableItemText1 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_brand_hdr;
tableItemComment1 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_brand;
2020-08-31 08:18:07 +00:00
tableItemImg2 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-regional-100.png");
tableItemText2 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_regional_hdr;
tableItemComment2 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_regional;
2020-08-31 08:18:07 +00:00
tableItemImg3 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-customize-100.png");
tableItemText3 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_customize_hdr;
tableItemComment3 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_customize;
2020-08-31 08:18:07 +00:00
tableItemImg4 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-modules-100.png");
tableItemText4 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_modules_hdr;
tableItemComment4 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_modules;
2020-08-31 08:18:07 +00:00
if (!coreBaseSettings.CustomMode)
{
2020-08-31 08:18:07 +00:00
tableItemImg5 = studioNotifyHelper.GetNotificationImageUrl("tips-customize-3rdparty-100.png");
tableItemText5 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_3rdparty_hdr;
tableItemComment5 = () => WebstudioNotifyPatternResource.pattern_enterprise_admin_customize_portal_v10_item_3rdparty;
}
greenButtonText = () => WebstudioNotifyPatternResource.ButtonConfigureRightNow;
2020-08-31 08:18:07 +00:00
greenButtonUrl = commonLinkUtility.GetFullAbsolutePath(commonLinkUtility.GetAdministration(ManagementType.General));
}
#endregion
#endregion
}
else if (tariff.State == TariffState.Paid)
{
#region Payment warning letters
#region 7 days before ENTERPRISE PAID expired to admins
2020-01-23 08:52:07 +00:00
if (dueDateIsNotMax && dueDate.AddDays(-7) == nowDate)
{
action = defaultRebranding
? Actions.EnterpriseAdminPaymentWarningBefore7V10
: Actions.EnterpriseWhitelabelAdminPaymentWarningBefore7V10;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonSelectPricingPlans;
2020-08-31 08:18:07 +00:00
greenButtonUrl = commonLinkUtility.GetFullAbsolutePath("~/tariffs.aspx");
}
#endregion
#region ENTERPRISE PAID expires today to admins
2020-01-23 08:52:07 +00:00
else if (dueDate == nowDate)
{
action = defaultRebranding
? Actions.EnterpriseAdminPaymentWarningV10
: Actions.EnterpriseWhitelabelAdminPaymentWarningV10;
toadmins = true;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonSelectPricingPlans;
2020-08-31 08:18:07 +00:00
greenButtonUrl = commonLinkUtility.GetFullAbsolutePath("~/tariffs.aspx");
}
#endregion
#endregion
}
if (action == null) continue;
2020-08-31 08:18:07 +00:00
var users = studioNotifyHelper.GetRecipients(toadmins, tousers, false);
2020-08-31 08:18:07 +00:00
foreach (var u in users.Where(u => paymentMessage || studioNotifyHelper.IsSubscribedToNotify(u, Actions.PeriodicNotify)))
{
var culture = string.IsNullOrEmpty(u.CultureName) ? tenant.GetCulture() : u.GetCulture();
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
2020-08-31 08:18:07 +00:00
var rquota = tenantExtra.GetRightQuota() ?? TenantQuota.Default;
client.SendNoticeToAsync(
action,
2020-08-31 08:18:07 +00:00
new[] { studioNotifyHelper.ToRecipient(u.ID) },
new[] { senderName },
new TagValue(Tags.UserName, u.FirstName.HtmlEncode()),
2020-08-31 08:18:07 +00:00
new TagValue(Tags.PricingPage, commonLinkUtility.GetFullAbsolutePath("~/tariffs.aspx")),
new TagValue(Tags.ActiveUsers, userManager.GetUsers().Count()),
new TagValue(Tags.Price, rquota.Price),
new TagValue(Tags.PricePeriod, rquota.Year3 ? UserControlsCommonResource.TariffPerYear3 : rquota.Year ? UserControlsCommonResource.TariffPerYear : UserControlsCommonResource.TariffPerMonth),
2020-02-17 08:58:14 +00:00
new TagValue(Tags.DueDate, dueDate.ToLongDateString()),
2020-01-23 08:52:07 +00:00
new TagValue(Tags.DelayDueDate, (delayDueDateIsNotMax ? delayDueDate : dueDate).ToLongDateString()),
TagValues.BlueButton(blueButtonText, "http://www.onlyoffice.com/call-back-form.aspx"),
TagValues.GreenButton(greenButtonText, greenButtonUrl),
TagValues.TableTop(),
TagValues.TableItem(1, tableItemText1, tableItemUrl1, tableItemImg1, tableItemComment1, tableItemLearnMoreText1, tableItemLearnMoreUrl1),
TagValues.TableItem(2, tableItemText2, tableItemUrl2, tableItemImg2, tableItemComment2, tableItemLearnMoreText2, tableItemLearnMoreUrl2),
TagValues.TableItem(3, tableItemText3, tableItemUrl3, tableItemImg3, tableItemComment3, tableItemLearnMoreText3, tableItemLearnMoreUrl3),
TagValues.TableItem(4, tableItemText4, tableItemUrl4, tableItemImg4, tableItemComment4, tableItemLearnMoreText4, tableItemLearnMoreUrl4),
TagValues.TableItem(5, tableItemText5, tableItemUrl5, tableItemImg5, tableItemComment5, tableItemLearnMoreText5, tableItemLearnMoreUrl5),
TagValues.TableItem(6, tableItemText6, tableItemUrl6, tableItemImg6, tableItemComment6, tableItemLearnMoreText6, tableItemLearnMoreUrl6),
TagValues.TableItem(7, tableItemText7, tableItemUrl7, tableItemImg7, tableItemComment7, tableItemLearnMoreText7, tableItemLearnMoreUrl7),
TagValues.TableBottom());
}
}
catch (Exception err)
{
2019-11-01 08:49:08 +00:00
Log.Error(err);
}
}
2019-11-01 08:49:08 +00:00
Log.Info("End SendTariffEnterpriseLetters");
}
2019-11-01 08:49:08 +00:00
public void SendOpensourceLetters(string senderName, DateTime scheduleDate)
{
2020-01-23 08:52:07 +00:00
var nowDate = scheduleDate.Date;
2019-11-06 15:03:09 +00:00
Log.Info("Start SendOpensourceTariffLetters");
var activeTenants = new List<Tenant>();
using (var scope = ServiceProvider.CreateScope())
{
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
activeTenants = tenantManager.GetTenants().ToList();
if (activeTenants.Count <= 0)
{
Log.Info("End SendOpensourceTariffLetters");
return;
}
}
foreach (var tenant in activeTenants)
{
try
2019-11-06 15:03:09 +00:00
{
using var scope = ServiceProvider.CreateScope();
2020-08-31 08:18:07 +00:00
var scopeClass = scope.ServiceProvider.GetService<StudioPeriodicNotifyScope>();
2020-09-07 12:01:15 +00:00
var (tenantManager, _, studioNotifyHelper, _, _, _, _, _, _, _, _, _, _, _, displayUserSettingsHelper, _, _) = scopeClass;
2020-08-31 08:18:07 +00:00
tenantManager.SetCurrentTenant(tenant.TenantId);
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(studioNotifyHelper.NotifySource, scope);
2020-02-17 08:58:14 +00:00
var createdDate = tenant.CreatedDateTime.Date;
INotifyAction action = null;
Func<string> greenButtonText = () => string.Empty;
var greenButtonUrl = string.Empty;
2019-08-15 14:36:08 +00:00
string tableItemText1() => string.Empty;
string tableItemText2() => string.Empty;
string tableItemText3() => string.Empty;
string tableItemText4() => string.Empty;
string tableItemText5() => string.Empty;
string tableItemText6() => string.Empty;
string tableItemText7() => string.Empty;
var tableItemUrl1 = string.Empty;
var tableItemUrl2 = string.Empty;
var tableItemUrl3 = string.Empty;
var tableItemUrl4 = string.Empty;
var tableItemUrl5 = string.Empty;
var tableItemUrl6 = string.Empty;
var tableItemUrl7 = string.Empty;
var tableItemImg1 = string.Empty;
var tableItemImg2 = string.Empty;
var tableItemImg3 = string.Empty;
var tableItemImg4 = string.Empty;
var tableItemImg5 = string.Empty;
var tableItemImg6 = string.Empty;
var tableItemImg7 = string.Empty;
Func<string> tableItemComment1 = () => string.Empty;
Func<string> tableItemComment2 = () => string.Empty;
Func<string> tableItemComment3 = () => string.Empty;
Func<string> tableItemComment4 = () => string.Empty;
Func<string> tableItemComment5 = () => string.Empty;
Func<string> tableItemComment6 = () => string.Empty;
Func<string> tableItemComment7 = () => string.Empty;
Func<string> tableItemLearnMoreText1 = () => string.Empty;
Func<string> tableItemLearnMoreText2 = () => string.Empty;
Func<string> tableItemLearnMoreText3 = () => string.Empty;
Func<string> tableItemLearnMoreText4 = () => string.Empty;
Func<string> tableItemLearnMoreText5 = () => string.Empty;
Func<string> tableItemLearnMoreText6 = () => string.Empty;
Func<string> tableItemLearnMoreText7 = () => string.Empty;
var tableItemLearnMoreUrl1 = string.Empty;
var tableItemLearnMoreUrl2 = string.Empty;
var tableItemLearnMoreUrl3 = string.Empty;
var tableItemLearnMoreUrl4 = string.Empty;
var tableItemLearnMoreUrl5 = string.Empty;
var tableItemLearnMoreUrl6 = string.Empty;
var tableItemLearnMoreUrl7 = string.Empty;
#region After registration letters
#region 7 days after registration to admins
2020-01-23 08:52:07 +00:00
if (createdDate.AddDays(7) == nowDate)
{
action = Actions.OpensourceAdminSecurityTips;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonStartFreeTrial;
greenButtonUrl = "https://www.onlyoffice.com/enterprise-edition-free.aspx";
}
#endregion
#region 3 weeks after registration to admins
2020-01-23 08:52:07 +00:00
else if (createdDate.AddDays(21) == nowDate)
{
action = Actions.OpensourceAdminDocsTips;
2020-08-31 08:18:07 +00:00
tableItemImg1 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-coediting-100.png");
tableItemComment1 = () => WebstudioNotifyPatternResource.ItemOpensourceDocsTips1;
2020-08-31 08:18:07 +00:00
tableItemLearnMoreUrl1 = studioNotifyHelper.Helplink + "/ONLYOFFICE-Editors/ONLYOFFICE-Document-Editor/HelpfulHints/CollaborativeEditing.aspx";
tableItemLearnMoreText1 = () => WebstudioNotifyPatternResource.LinkLearnMore;
2020-08-31 08:18:07 +00:00
tableItemImg2 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-docinfo-100.png");
tableItemComment2 = () => WebstudioNotifyPatternResource.ItemOpensourceDocsTips2;
2020-08-31 08:18:07 +00:00
tableItemLearnMoreUrl2 = studioNotifyHelper.Helplink + "/ONLYOFFICE-Editors/ONLYOFFICE-Document-Editor/UsageInstructions/ViewDocInfo.aspx";
tableItemLearnMoreText2 = () => WebstudioNotifyPatternResource.LinkLearnMore;
2020-08-31 08:18:07 +00:00
tableItemImg3 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-review-100.png");
tableItemComment3 = () => WebstudioNotifyPatternResource.ItemOpensourceDocsTips3;
2020-08-31 08:18:07 +00:00
tableItemLearnMoreUrl3 = studioNotifyHelper.Helplink + "/ONLYOFFICE-Editors/ONLYOFFICE-Document-Editor/HelpfulHints/Review.aspx";
tableItemLearnMoreText3 = () => WebstudioNotifyPatternResource.LinkLearnMore;
2020-08-31 08:18:07 +00:00
tableItemImg4 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-share-100.png");
tableItemComment4 = () => WebstudioNotifyPatternResource.ItemOpensourceDocsTips4;
2020-08-31 08:18:07 +00:00
tableItemLearnMoreUrl4 = studioNotifyHelper.Helplink + "/gettingstarted/documents.aspx#SharingDocuments_block";
tableItemLearnMoreText4 = () => WebstudioNotifyPatternResource.LinkLearnMore;
2020-08-31 08:18:07 +00:00
tableItemImg5 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-mailmerge-100.png");
tableItemComment5 = () => WebstudioNotifyPatternResource.ItemOpensourceDocsTips5;
2020-08-31 08:18:07 +00:00
tableItemLearnMoreUrl5 = studioNotifyHelper.Helplink + "/ONLYOFFICE-Editors/ONLYOFFICE-Document-Editor/UsageInstructions/UseMailMerge.aspx";
tableItemLearnMoreText5 = () => WebstudioNotifyPatternResource.LinkLearnMore;
2020-08-31 08:18:07 +00:00
tableItemImg6 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-desktop-100.png");
tableItemComment6 = () => WebstudioNotifyPatternResource.ItemOpensourceDocsTips6;
tableItemLearnMoreUrl6 = "http://www.onlyoffice.com/desktop.aspx";
tableItemLearnMoreText6 = () => WebstudioNotifyPatternResource.ButtonDownloadNow;
2020-08-31 08:18:07 +00:00
tableItemImg7 = studioNotifyHelper.GetNotificationImageUrl("tips-documents-apps-100.png");
tableItemComment7 = () => WebstudioNotifyPatternResource.ItemOpensourceDocsTips7;
tableItemLearnMoreUrl7 = "https://itunes.apple.com/us/app/onlyoffice-documents/id944896972";
tableItemLearnMoreText7 = () => WebstudioNotifyPatternResource.ButtonGoToAppStore;
}
#endregion
#endregion
if (action == null) continue;
2020-08-31 08:18:07 +00:00
var users = studioNotifyHelper.GetRecipients(true, false, false);
2020-08-31 08:18:07 +00:00
foreach (var u in users.Where(u => studioNotifyHelper.IsSubscribedToNotify(u, Actions.PeriodicNotify)))
{
var culture = string.IsNullOrEmpty(u.CultureName) ? tenant.GetCulture() : u.GetCulture();
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
client.SendNoticeToAsync(
action,
2020-08-31 08:18:07 +00:00
new[] { studioNotifyHelper.ToRecipient(u.ID) },
new[] { senderName },
2020-08-31 08:18:07 +00:00
new TagValue(Tags.UserName, u.DisplayUserName(displayUserSettingsHelper)),
TagValues.GreenButton(greenButtonText, greenButtonUrl),
TagValues.TableTop(),
TagValues.TableItem(1, tableItemText1, tableItemUrl1, tableItemImg1, tableItemComment1, tableItemLearnMoreText1, tableItemLearnMoreUrl1),
TagValues.TableItem(2, tableItemText2, tableItemUrl2, tableItemImg2, tableItemComment2, tableItemLearnMoreText2, tableItemLearnMoreUrl2),
TagValues.TableItem(3, tableItemText3, tableItemUrl3, tableItemImg3, tableItemComment3, tableItemLearnMoreText3, tableItemLearnMoreUrl3),
TagValues.TableItem(4, tableItemText4, tableItemUrl4, tableItemImg4, tableItemComment4, tableItemLearnMoreText4, tableItemLearnMoreUrl4),
TagValues.TableItem(5, tableItemText5, tableItemUrl5, tableItemImg5, tableItemComment5, tableItemLearnMoreText5, tableItemLearnMoreUrl5),
TagValues.TableItem(6, tableItemText6, tableItemUrl6, tableItemImg6, tableItemComment6, tableItemLearnMoreText6, tableItemLearnMoreUrl6),
TagValues.TableItem(7, tableItemText7, tableItemUrl7, tableItemImg7, tableItemComment7, tableItemLearnMoreText7, tableItemLearnMoreUrl7),
TagValues.TableBottom(),
new TagValue(CommonTags.Footer, "opensource"));
}
}
catch (Exception err)
{
2019-11-01 08:49:08 +00:00
Log.Error(err);
}
}
2019-11-01 08:49:08 +00:00
Log.Info("End SendOpensourceTariffLetters");
}
2019-11-01 08:49:08 +00:00
public void SendPersonalLetters(string senderName, DateTime scheduleDate)
{
2019-11-06 15:03:09 +00:00
Log.Info("Start SendLettersPersonal...");
var activeTenants = new List<Tenant>();
using (var scope = ServiceProvider.CreateScope())
{
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
activeTenants = tenantManager.GetTenants().ToList();
}
2019-09-17 12:42:32 +00:00
foreach (var tenant in activeTenants)
{
try
{
Func<string> greenButtonText = () => string.Empty;
var greenButtonUrl = string.Empty;
2019-11-06 15:03:09 +00:00
var sendCount = 0;
using var scope = ServiceProvider.CreateScope();
2020-08-31 08:18:07 +00:00
var scopeClass = scope.ServiceProvider.GetService<StudioPeriodicNotifyScope>();
2020-09-07 12:01:15 +00:00
var (tenantManager, userManager, studioNotifyHelper, _, _, _, _, _, _, _, _, _, _, coreBaseSettings, _, authManager, securityContext) = scopeClass;
2019-11-06 15:03:09 +00:00
2020-08-31 08:18:07 +00:00
tenantManager.SetCurrentTenant(tenant.TenantId);
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(studioNotifyHelper.NotifySource, scope);
2019-11-01 08:49:08 +00:00
Log.InfoFormat("Current tenant: {0}", tenant.TenantId);
2020-08-31 08:18:07 +00:00
var users = userManager.GetUsers(EmployeeStatus.Active);
2020-08-31 08:18:07 +00:00
foreach (var user in users.Where(u => studioNotifyHelper.IsSubscribedToNotify(u, Actions.PeriodicNotify)))
{
INotifyAction action;
2020-08-31 08:18:07 +00:00
securityContext.AuthenticateMe(authManager.GetAccountByID(tenant.TenantId, user.ID));
var culture = tenant.GetCulture();
if (!string.IsNullOrEmpty(user.CultureName))
{
try
{
culture = user.GetCulture();
}
catch (CultureNotFoundException exception)
{
2019-11-01 08:49:08 +00:00
Log.Error(exception);
}
}
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
var dayAfterRegister = (int)scheduleDate.Date.Subtract(user.CreateDate.Date).TotalDays;
2020-08-31 08:18:07 +00:00
if (coreBaseSettings.CustomMode)
{
switch (dayAfterRegister)
{
case 7:
action = Actions.PersonalCustomModeAfterRegistration7;
break;
default:
continue;
}
}
else
{
switch (dayAfterRegister)
{
case 7:
action = Actions.PersonalAfterRegistration7;
break;
case 14:
action = Actions.PersonalAfterRegistration14;
break;
case 21:
action = Actions.PersonalAfterRegistration21;
break;
case 28:
action = Actions.PersonalAfterRegistration28;
greenButtonText = () => WebstudioNotifyPatternResource.ButtonStartFreeTrial;
greenButtonUrl = "https://www.onlyoffice.com/enterprise-edition-free.aspx";
break;
default:
continue;
}
}
if (action == null) continue;
2019-11-01 08:49:08 +00:00
Log.InfoFormat(@"Send letter personal '{1}' to {0} culture {2}. tenant id: {3} user culture {4} create on {5} now date {6}",
2019-08-22 15:59:49 +00:00
user.Email, action.ID, culture, tenant.TenantId, user.GetCulture(), user.CreateDate, scheduleDate.Date);
sendCount++;
client.SendNoticeToAsync(
action,
null,
2020-08-31 08:18:07 +00:00
studioNotifyHelper.RecipientFromEmail(user.Email, true),
new[] { senderName },
TagValues.PersonalHeaderStart(),
TagValues.PersonalHeaderEnd(),
TagValues.GreenButton(greenButtonText, greenButtonUrl),
2020-08-31 08:18:07 +00:00
new TagValue(CommonTags.Footer, coreBaseSettings.CustomMode ? "personalCustomMode" : "personal"));
}
2019-11-01 08:49:08 +00:00
Log.InfoFormat("Total send count: {0}", sendCount);
}
catch (Exception err)
{
2019-11-01 08:49:08 +00:00
Log.Error(err);
}
}
2019-11-01 08:49:08 +00:00
Log.Info("End SendLettersPersonal.");
}
public static bool ChangeSubscription(Guid userId, StudioNotifyHelper studioNotifyHelper)
{
var recipient = studioNotifyHelper.ToRecipient(userId);
var isSubscribe = studioNotifyHelper.IsSubscribedToNotify(recipient, Actions.PeriodicNotify);
2019-09-09 12:56:33 +00:00
studioNotifyHelper.SubscribeToNotify(recipient, Actions.PeriodicNotify, !isSubscribe);
return !isSubscribe;
}
2020-08-24 18:41:06 +00:00
}
2020-07-30 13:33:54 +00:00
2020-08-24 18:41:06 +00:00
public class StudioPeriodicNotifyScope
{
2020-08-31 08:18:07 +00:00
private TenantManager TenantManager { get; }
private UserManager UserManager { get; }
private StudioNotifyHelper StudioNotifyHelper { get; }
private PaymentManager PaymentManager { get; }
private TenantExtra TenantExtra { get; }
private AuthContext AuthContext { get; }
private CommonLinkUtility CommonLinkUtility { get; }
private ApiSystemHelper ApiSystemHelper { get; }
private SetupInfo SetupInfo { get; }
private DbContextManager<FeedDbContext> DbContextManager { get; }
private CouponManager CouponManager { get; }
private IConfiguration Configuration { get; }
private SettingsManager SettingsManager { get; }
private CoreBaseSettings CoreBaseSettings { get; }
private DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
private AuthManager AuthManager { get; }
private SecurityContext SecurityContext { get; }
2020-07-30 13:33:54 +00:00
2020-08-24 18:41:06 +00:00
public StudioPeriodicNotifyScope(TenantManager tenantManager,
UserManager userManager,
StudioNotifyHelper studioNotifyHelper,
PaymentManager paymentManager,
TenantExtra tenantExtra,
AuthContext authContext,
CommonLinkUtility commonLinkUtility,
ApiSystemHelper apiSystemHelper,
SetupInfo setupInfo,
DbContextManager<FeedDbContext> dbContextManager,
CouponManager couponManager,
IConfiguration configuration,
SettingsManager settingsManager,
CoreBaseSettings coreBaseSettings,
DisplayUserSettingsHelper displayUserSettingsHelper,
AuthManager authManager,
SecurityContext securityContext)
{
TenantManager = tenantManager;
UserManager = userManager;
StudioNotifyHelper = studioNotifyHelper;
PaymentManager = paymentManager;
TenantExtra = tenantExtra;
AuthContext = authContext;
CommonLinkUtility = commonLinkUtility;
ApiSystemHelper = apiSystemHelper;
SetupInfo = setupInfo;
DbContextManager = dbContextManager;
CouponManager = couponManager;
Configuration = configuration;
SettingsManager = settingsManager;
CoreBaseSettings = coreBaseSettings;
DisplayUserSettingsHelper = displayUserSettingsHelper;
AuthManager = authManager;
SecurityContext = securityContext;
}
2020-08-31 08:18:07 +00:00
public void Deconstruct(out TenantManager tenantManager,
out UserManager userManager,
out StudioNotifyHelper studioNotifyHelper,
out PaymentManager paymentManager,
out TenantExtra tenantExtra,
out AuthContext authContext,
out CommonLinkUtility commonLinkUtility,
out ApiSystemHelper apiSystemHelper,
out SetupInfo setupInfo,
out DbContextManager<FeedDbContext> dbContextManager,
out CouponManager couponManager,
out IConfiguration configuration,
out SettingsManager settingsManager,
out CoreBaseSettings coreBaseSettings,
out DisplayUserSettingsHelper displayUserSettingsHelper,
out AuthManager authManager,
out SecurityContext securityContext)
{
tenantManager = TenantManager;
userManager = UserManager;
studioNotifyHelper = StudioNotifyHelper;
paymentManager = PaymentManager;
tenantExtra = TenantExtra;
authContext = AuthContext;
commonLinkUtility = CommonLinkUtility;
apiSystemHelper = ApiSystemHelper;
setupInfo = SetupInfo;
dbContextManager = DbContextManager;
couponManager = CouponManager;
configuration = Configuration;
settingsManager = SettingsManager;
coreBaseSettings = CoreBaseSettings;
displayUserSettingsHelper = DisplayUserSettingsHelper;
authManager = AuthManager;
securityContext = SecurityContext;
}
2019-11-06 15:03:09 +00:00
}
2020-08-24 18:41:06 +00:00
public static class StudioPeriodicNotifyExtension
2019-11-06 15:03:09 +00:00
{
2020-02-17 08:58:14 +00:00
public static DIHelper AddStudioPeriodicNotify(this DIHelper services)
2019-11-06 15:03:09 +00:00
{
services.TryAddSingleton<StudioPeriodicNotify>();
2020-08-24 18:41:06 +00:00
services.TryAddSingleton<CouponManager>();
services.TryAddScoped<StudioPeriodicNotifyScope>();
2019-11-06 15:03:09 +00:00
return services
.AddApiSystemHelper()
.AddTenantManagerService()
.AddUserManagerService()
.AddStudioNotifyHelperService()
.AddPaymentManagerService()
.AddTenantExtraService()
.AddAuthContextService()
.AddCommonLinkUtilityService()
2020-02-17 08:58:14 +00:00
.AddSetupInfo()
2019-12-10 13:42:29 +00:00
.AddFeedDbService()
2019-11-06 15:03:09 +00:00
.AddCoreBaseSettingsService()
.AddDisplayUserSettingsService()
.AddSecurityContextService()
.AddAuthManager();
}
}
}