private void SendOperatorEmails() { AspSettings settings = AspSettings.Load(); IConfigurator config = Configurator.Create(); // Trial - One day before end foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneDayBeforeEnd, settings.OneDayBeforePeriod, true)) { try { if (!CManage.NotificationGet(cid, EmailType.TrialOneDayBefore)) { if (string.IsNullOrEmpty(settings.OperatorEmail)) { CManage.NotificationUpdate(cid, EmailType.TrialOneDayBefore, true); TemplateVariables vars = CManage.CompanyGetVariables(cid); CManage.SendEmail(settings.OperatorEmail, EmailType.TrialOneDayBefore, vars); } } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } if (settings.UseTariffs) { // Billable - One day before end foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNdaysBefore, 1, false)) { // ensure that we send emails only once for a day DateTime lastSpamDate = CManage.GetNotificationOperatorSpamDate(cid); if (lastSpamDate > DateTime.Now.AddDays(-1)) { continue; } try { if (string.IsNullOrEmpty(settings.OperatorEmail)) { TemplateVariables vars = CManage.CompanyGetVariables(cid); CManage.SendEmail(settings.OperatorEmail, EmailType.OperatorCompanyDeactivatedDayBefore, vars); CManage.UpdateNotificationOperatorSpamDate(cid, DateTime.Now); } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } }
private void DeactivateExpiredCompanies() { AspSettings settings = AspSettings.Load(); if (settings.AutoDeactivateExpired) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.Expired, 0, false)) { try { CManage.DeactivateCompany(cid); // Send e-mail to operator if (!string.IsNullOrEmpty(settings.OperatorEmail)) { TemplateVariables vars = CManage.CompanyGetVariables(cid); CManage.SendEmail(settings.OperatorEmail, EmailType.TrialDeactivated, vars); } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } if (settings.AutoDeactivateUnpaid && settings.UseTariffs) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableForDeactivate, 0, false)) { try { CManage.DeactivateCompany(cid); // Send e-mail to operator if (!string.IsNullOrEmpty(settings.OperatorEmail)) { TemplateVariables vars = CManage.CompanyGetVariables(cid); CManage.SendEmail(settings.OperatorEmail, EmailType.OperatorCompanyDeactivated, vars); } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } }
private void SendUserEmails() { AspSettings settings = AspSettings.Load(); IConfigurator config = Configurator.Create(); #region trial spam if (settings.SendSpam) { // One day after start if (settings.SendSpamOneDayAfter) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneDayNoIM, settings.OneDayAfterPeriod, true)) { try { string dbName = config.GetCompanyInfo(cid.ToString()).Database; if (!CManage.NotificationGet(cid, EmailType.UserAfterOneDayIM)) { CManage.NotificationUpdate(cid, EmailType.UserAfterOneDayIM, true); if (!CManage.CheckImSessions(dbName)) { // Send e-mails to every active user TemplateVariables vars = CManage.CompanyGetVariables(cid); foreach (UserInfo ui in CManage.GetPortalUsers(dbName)) { vars["Login"] = ui.Login; vars["Name"] = ui.Name; try { CManage.SendEmail(ui.Email, EmailType.UserAfterOneDayIM, vars); } catch { } } } } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } // One week after start if (settings.SendSpamOneWeekAfter) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneWeekAfterStart, settings.OneWeekAfterPeriod, true)) { try { if (!CManage.NotificationGet(cid, EmailType.UserAfterOneWeek)) { CManage.NotificationUpdate(cid, EmailType.UserAfterOneWeek, true); // Send e-mail TemplateVariables vars = CManage.CompanyGetVariables(cid); if (!string.IsNullOrEmpty(vars["ContactEmail"])) { CManage.SendEmail(vars["ContactEmail"], EmailType.UserAfterOneWeek, vars); } } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } // One week before end if (settings.SendSpamOneWeekBefore) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneWeekBeforeEnd, settings.OneWeekBeforePeriod, true)) { try { if (!CManage.NotificationGet(cid, EmailType.UserOneWeekBefore)) { CManage.NotificationUpdate(cid, EmailType.UserOneWeekBefore, true); // Send e-mail TemplateVariables vars = CManage.CompanyGetVariables(cid); if (!string.IsNullOrEmpty(vars["ContactEmail"])) { CManage.SendEmail(vars["ContactEmail"], EmailType.UserOneWeekBefore, vars); } } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } // One day before end if (settings.SendSpamOneDayBefore) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.OneDayBeforeEnd, settings.OneDayBeforePeriod, true)) { try { if (!CManage.NotificationGet(cid, EmailType.UserOneDayBefore)) { CManage.NotificationUpdate(cid, EmailType.UserOneDayBefore, true); // Send e-mail TemplateVariables vars = CManage.CompanyGetVariables(cid); if (!string.IsNullOrEmpty(vars["ContactEmail"])) { CManage.SendEmail(vars["ContactEmail"], EmailType.UserOneDayBefore, vars); } } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } } #endregion #region billable spam if (settings.SendBillableSpam && settings.UseTariffs) { // 7 days before if (settings.SendBillableSpam7day) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNdaysBefore, 7, true)) { // ensure that we send emails only once for a day DateTime lastSpamDate = CManage.GetNotificationClientSpamDate(cid); if (lastSpamDate > DateTime.Now.AddDays(-1)) { continue; } // Send e-mail try { TemplateVariables vars = CManage.CompanyGetVariables(cid); if (!string.IsNullOrEmpty(vars["ContactEmail"])) { CManage.SendEmail(vars["ContactEmail"], EmailType.Client7DayZeroBalance, vars); CManage.UpdateNotificationClientSpamDate(cid, DateTime.Now); } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } // 3 days before if (settings.SendBillableSpam3day) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNdaysBefore, 3, true)) { // ensure that we send emails only once for a day DateTime lastSpamDate = CManage.GetNotificationClientSpamDate(cid); if (lastSpamDate > DateTime.Now.AddDays(-1)) { continue; } // Send e-mail try { TemplateVariables vars = CManage.CompanyGetVariables(cid); if (!string.IsNullOrEmpty(vars["ContactEmail"])) { CManage.SendEmail(vars["ContactEmail"], EmailType.Client3DayZeroBalance, vars); CManage.UpdateNotificationClientSpamDate(cid, DateTime.Now); } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } // 1 day before if (settings.SendBillableSpam1day) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNdaysBefore, 1, true)) { // ensure that we send emails only once for a day DateTime lastSpamDate = CManage.GetNotificationClientSpamDate(cid); if (lastSpamDate > DateTime.Now.AddDays(-1)) { continue; } // Send e-mail try { TemplateVariables vars = CManage.CompanyGetVariables(cid); if (!string.IsNullOrEmpty(vars["ContactEmail"])) { CManage.SendEmail(vars["ContactEmail"], EmailType.Client1DayZeroBalance, vars); CManage.UpdateNotificationClientSpamDate(cid, DateTime.Now); } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } // Negative balance if (settings.SendBillableSpamNegativeBalance) { foreach (Guid cid in CManage.GetCompaniesByCategory(CompanyCategory.BillableNegativeBalance, 0, true)) { // ensure that we send emails only once for a day DateTime lastSpamDate = CManage.GetNotificationClientSpamDate(cid); if (lastSpamDate > DateTime.Now.AddDays(-1)) { continue; } // Send e-mail try { TemplateVariables vars = CManage.CompanyGetVariables(cid); if (!string.IsNullOrEmpty(vars["ContactEmail"])) { CManage.SendEmail(vars["ContactEmail"], EmailType.ClientZeroBalance, vars); CManage.UpdateNotificationClientSpamDate(cid, DateTime.Now); } } catch (Exception ex) { Log.WriteError(ex.ToString()); } } } } #endregion }
public TrialResult ActivateTrialCompany2( int requestId , string requestGuid , out string portalUrl , out string login , out string password , out string companyId ) { portalUrl = ""; login = ""; password = ""; companyId = ""; TrialResult ret = TrialResult.InvalidRequest; Guid guid = new Guid(requestGuid); if (DBTrialRequest.CheckGuid(requestId, guid)) { bool isActive = false; using (IDataReader reader = DBTrialRequest.Get(requestId, true, false)) { if (reader.Read()) { isActive = (bool)reader["IsActive"]; if (reader["Company_uid"] != DBNull.Value) { companyId = (string)reader["Company_uid"]; } } } if (isActive) { ret = TrialResult.AlreadyActivated; } else { Guid companyUid = CManage.ASPCreateTrialCompany(requestId); ret = TrialResult.Success; companyId = companyUid.ToString(); AspSettings settings = AspSettings.Load(); TemplateVariables vars = CManage.CompanyGetVariables(companyUid); TemplateVariables varsR = DBTrialRequest.GetVariables(requestId); vars["Login"] = varsR["Login"]; vars["Password"] = varsR["Password"]; vars["TrialUsers"] = settings.MaxUsers.ToString(); vars["TrialDiskSpace"] = settings.MaxHDD.ToString(); vars["TrialPeriod"] = settings.TrialPeriod.ToString(); portalUrl = vars["PortalLink"]; if (!string.IsNullOrEmpty(vars["ContactEmail"])) { CManage.SendEmail(vars["ContactEmail"], EmailType.UserActivated, vars); } if (!string.IsNullOrEmpty(settings.OperatorEmail)) { CManage.SendEmail(settings.OperatorEmail, EmailType.TrialActivated, vars); } login = varsR["Login"]; password = varsR["Password"]; } } return(ret); }
public static void AddPayment(Guid companyUid, DateTime dt, decimal amount, decimal bonus, string orderNo, bool checkUnicity) { if (amount + bonus <= 0) { throw new ArgumentException("Wrong value", "amount"); } IConfigurator config = Configurator.Create(); ICompanyInfo company = config.GetCompanyInfo(companyUid.ToString()); if (company == null) { throw new ArgumentException(String.Concat("CompanyUid = ", companyUid, " doesn't exist.")); } if (checkUnicity && !string.IsNullOrEmpty(orderNo) && CheckPaymentOrderNo(companyUid, orderNo) > 0) { throw new Exception(String.Concat("Order # ", orderNo, " already registered.")); } bool newTran = DBHelper.BeginTransaction(); try { DBHelper.RunSP("ASP_PAYMENT_ADD", DBHelper.mp("@companyUid", SqlDbType.UniqueIdentifier, companyUid), DBHelper.mp("@dt", SqlDbType.DateTime, dt), DBHelper.mp("@amount", SqlDbType.Money, amount), DBHelper.mp("@bonus", SqlDbType.Money, bonus), DBHelper.mp("@orderNo", SqlDbType.NVarChar, 50, orderNo)); UpdateBalance(companyUid, amount + bonus); // Activate inactive company if (!company.IsActive) { DBHelper.RunSP("ASP_COMPANY_UPDATE_IS_ACTIVE", DBHelper.mp("@company_uid", SqlDbType.UniqueIdentifier, companyUid), DBHelper.mp("@is_active", SqlDbType.Bit, true)); config.ActivateCompany(companyUid.ToString(), true, false); } #region Change company type from trial to billable if (int.Parse(config.GetCompanyPropertyValue(companyUid.ToString(), CManage.keyCompanyType)) == (int)CompanyType.Trial) { bool tariffIsValid = false; int maxUsers = -1; int maxExternalUsers = -1; int maxDiskSpace = -1; AspSettings settings = AspSettings.Load(); if (settings.UseTariffs && settings.DefaultTariff > 0) { using (IDataReader reader = GetTariff(settings.DefaultTariff, 0)) { if (reader.Read()) { tariffIsValid = true; maxUsers = (int)reader["maxUsers"]; maxExternalUsers = (int)reader["maxExternalUsers"]; maxDiskSpace = (int)reader["maxHdd"]; } } } if (tariffIsValid) { config.SetCompanyPropertyValue(companyUid.ToString(), CManage.keyCompanyMaxUsers, maxUsers.ToString()); config.SetCompanyPropertyValue(companyUid.ToString(), CManage.keyCompanyMaxExternalUsers, maxExternalUsers.ToString()); config.SetCompanyPropertyValue(companyUid.ToString(), CManage.keyCompanyDatabaseSize, maxDiskSpace.ToString()); DBHelper.RunSP("ASP_COMPANY_UPDATE_TARIFF", DBHelper.mp("@companyUid", SqlDbType.UniqueIdentifier, companyUid), DBHelper.mp("@tariffId", SqlDbType.Int, settings.DefaultTariff)); } config.SetCompanyPropertyValue(companyUid.ToString(), CManage.keyCompanyType, ((int)CompanyType.Billable).ToString()); CManage.UpdateCompanyType(companyUid, (byte)CompanyType.Billable); } #endregion // Ensure, that the unpaid period is recalculated RecalculateBalance(); TemplateVariables vars = CManage.CompanyGetVariables(companyUid); if (!string.IsNullOrEmpty(vars["ContactEmail"])) { vars["Amount"] = amount.ToString("f"); vars["Bonus"] = bonus.ToString("f"); vars["Total"] = (amount + bonus).ToString("f"); CManage.SendEmail(vars["ContactEmail"], EmailType.ClientBalanceUp, vars); } DBHelper.Commit(newTran); } catch (Exception) { DBHelper.Rollback(newTran); throw; } }