Ejemplo n.º 1
0
 public static AspSettings Load()
 {
     AspSettings ret = new AspSettings();
     using(IDataReader r = CManage.SettingsGet())
     {
         if (r.Read())
         {
             ret.MaxHDD = (int)r["MaxHDD"];
             ret.MaxUsers = (int)r["MaxUsers"];
             ret.MaxExternalUsers = (int)r["MaxExternalUsers"];
             ret.TrialPeriod = (int)r["TrialPeriod"];
             ret.EmailFrom = r["EmailFrom"].ToString();
             ret.OperatorEmail = r["OperatorEmail"].ToString();
             ret.DnsParentDomain = r["DnsParentDomain"].ToString();
             ret.IisIpAddress = r["IisIpAddress"].ToString();
             ret.IisPort = (int)r["IisPort"];
             ret.AutoDeactivateExpired = (bool)r["AutoDeactivateExpired"];
             ret.AutoDeleteOutdated = (bool)r["AutoDeleteOutdated"];
             ret.OutdatePeriod = (int)r["OutdatePeriod"];
             ret.SendSpam = (bool)r["SendSpam"];
             ret.SendSpamOneDayAfter = (bool)r["SendSpamOneDayAfter"];
             ret.SendSpamOneWeekAfter = (bool)r["SendSpamOneWeekAfter"];
             ret.SendSpamOneWeekBefore = (bool)r["SendSpamOneWeekBefore"];
             ret.SendSpamOneDayBefore = (bool)r["SendSpamOneDayBefore"];
             ret.OneDayAfterPeriod = (int)r["OneDayAfterPeriod"];
             ret.OneWeekAfterPeriod = (int)r["OneWeekAfterPeriod"];
             ret.OneWeekBeforePeriod = (int)r["OneWeekBeforePeriod"];
             ret.OneDayBeforePeriod = (int)r["OneDayBeforePeriod"];
             ret.UseTariffs = (bool)r["UseTariffs"];
             ret.SendBillableSpam = (bool)r["SendBillableSpam"];
             ret.SendBillableSpam7day = (bool)r["SendBillableSpam7day"];
             ret.SendBillableSpam3day = (bool)r["SendBillableSpam3day"];
             ret.SendBillableSpam1day = (bool)r["SendBillableSpam1day"];
             ret.SendBillableSpamNegativeBalance = (bool)r["SendBillableSpamNegativeBalance"];
             ret.AutoDeactivateUnpaid = (bool)r["AutoDeactivateUnpaid"];
             ret.SmtpServer = (string)r["SmtpServer"];
             ret.SmtpPort = (int)r["SmtpPort"];
             ret.SmtpSecureConnection = (SecureConnectionType)r["SmtpSecureConnection"];
             ret.SmtpAuthenticate = (bool)r["SmtpAuthenticate"];
             ret.SmtpUser = (string)r["SmtpUser"];
             ret.SmtpPassword = (string)r["SmtpPassword"];
             ret.DefaultTrialPool = (string)r["DefaultTrialPool"];
             ret.DefaultBillablePool = (string)r["DefaultBillablePool"];
             ret.DefaultTariff = (int)r["DefaultTariff"];
         }
         else
         {
             ret.MaxHDD = 100;
             ret.MaxUsers = 10;
             ret.MaxExternalUsers = 10;
             ret.TrialPeriod = 30;
             ret.EmailFrom = string.Empty;
             ret.OperatorEmail = string.Empty;
             ret.DnsParentDomain = string.Empty;
             ret.IisIpAddress = string.Empty;
             ret.IisPort = 80;
             ret.AutoDeactivateExpired = false;
             ret.AutoDeleteOutdated = false;
             ret.OutdatePeriod = 30;
             ret.SendSpam = false;
             ret.SendSpamOneDayAfter = false;
             ret.SendSpamOneWeekAfter = false;
             ret.SendSpamOneWeekBefore = false;
             ret.SendSpamOneDayBefore = false;
             ret.OneDayAfterPeriod = 1;
             ret.OneWeekAfterPeriod = 7;
             ret.OneWeekBeforePeriod = 7;
             ret.OneDayBeforePeriod = 7;
             ret.UseTariffs = false;
             ret.SendBillableSpam = false;
             ret.SendBillableSpam7day = false;
             ret.SendBillableSpam3day = false;
             ret.SendBillableSpam1day = false;
             ret.SendBillableSpamNegativeBalance = false;
             ret.AutoDeactivateUnpaid = false;
             ret.SmtpServer = "localhost";
             ret.SmtpPort = 25;
             ret.SmtpSecureConnection = SecureConnectionType.None;
             ret.SmtpAuthenticate = false;
             ret.SmtpUser = string.Empty;
             ret.SmtpPassword = string.Empty;
             ret.DefaultTrialPool = string.Empty;
             ret.DefaultBillablePool = string.Empty;
             ret.DefaultTariff = -1;
         }
     }
     return ret;
 }
Ejemplo n.º 2
0
        public static AspSettings Load()
        {
            AspSettings ret = new AspSettings();

            using (IDataReader r = CManage.SettingsGet())
            {
                if (r.Read())
                {
                    ret.MaxHDD                          = (int)r["MaxHDD"];
                    ret.MaxUsers                        = (int)r["MaxUsers"];
                    ret.MaxExternalUsers                = (int)r["MaxExternalUsers"];
                    ret.TrialPeriod                     = (int)r["TrialPeriod"];
                    ret.EmailFrom                       = r["EmailFrom"].ToString();
                    ret.OperatorEmail                   = r["OperatorEmail"].ToString();
                    ret.DnsParentDomain                 = r["DnsParentDomain"].ToString();
                    ret.IisIpAddress                    = r["IisIpAddress"].ToString();
                    ret.IisPort                         = (int)r["IisPort"];
                    ret.AutoDeactivateExpired           = (bool)r["AutoDeactivateExpired"];
                    ret.AutoDeleteOutdated              = (bool)r["AutoDeleteOutdated"];
                    ret.OutdatePeriod                   = (int)r["OutdatePeriod"];
                    ret.SendSpam                        = (bool)r["SendSpam"];
                    ret.SendSpamOneDayAfter             = (bool)r["SendSpamOneDayAfter"];
                    ret.SendSpamOneWeekAfter            = (bool)r["SendSpamOneWeekAfter"];
                    ret.SendSpamOneWeekBefore           = (bool)r["SendSpamOneWeekBefore"];
                    ret.SendSpamOneDayBefore            = (bool)r["SendSpamOneDayBefore"];
                    ret.OneDayAfterPeriod               = (int)r["OneDayAfterPeriod"];
                    ret.OneWeekAfterPeriod              = (int)r["OneWeekAfterPeriod"];
                    ret.OneWeekBeforePeriod             = (int)r["OneWeekBeforePeriod"];
                    ret.OneDayBeforePeriod              = (int)r["OneDayBeforePeriod"];
                    ret.UseTariffs                      = (bool)r["UseTariffs"];
                    ret.SendBillableSpam                = (bool)r["SendBillableSpam"];
                    ret.SendBillableSpam7day            = (bool)r["SendBillableSpam7day"];
                    ret.SendBillableSpam3day            = (bool)r["SendBillableSpam3day"];
                    ret.SendBillableSpam1day            = (bool)r["SendBillableSpam1day"];
                    ret.SendBillableSpamNegativeBalance = (bool)r["SendBillableSpamNegativeBalance"];
                    ret.AutoDeactivateUnpaid            = (bool)r["AutoDeactivateUnpaid"];
                    ret.SmtpServer                      = (string)r["SmtpServer"];
                    ret.SmtpPort                        = (int)r["SmtpPort"];
                    ret.SmtpSecureConnection            = (SecureConnectionType)r["SmtpSecureConnection"];
                    ret.SmtpAuthenticate                = (bool)r["SmtpAuthenticate"];
                    ret.SmtpUser                        = (string)r["SmtpUser"];
                    ret.SmtpPassword                    = (string)r["SmtpPassword"];
                    ret.DefaultTrialPool                = (string)r["DefaultTrialPool"];
                    ret.DefaultBillablePool             = (string)r["DefaultBillablePool"];
                    ret.DefaultTariff                   = (int)r["DefaultTariff"];
                }
                else
                {
                    ret.MaxHDD                          = 100;
                    ret.MaxUsers                        = 10;
                    ret.MaxExternalUsers                = 10;
                    ret.TrialPeriod                     = 30;
                    ret.EmailFrom                       = string.Empty;
                    ret.OperatorEmail                   = string.Empty;
                    ret.DnsParentDomain                 = string.Empty;
                    ret.IisIpAddress                    = string.Empty;
                    ret.IisPort                         = 80;
                    ret.AutoDeactivateExpired           = false;
                    ret.AutoDeleteOutdated              = false;
                    ret.OutdatePeriod                   = 30;
                    ret.SendSpam                        = false;
                    ret.SendSpamOneDayAfter             = false;
                    ret.SendSpamOneWeekAfter            = false;
                    ret.SendSpamOneWeekBefore           = false;
                    ret.SendSpamOneDayBefore            = false;
                    ret.OneDayAfterPeriod               = 1;
                    ret.OneWeekAfterPeriod              = 7;
                    ret.OneWeekBeforePeriod             = 7;
                    ret.OneDayBeforePeriod              = 7;
                    ret.UseTariffs                      = false;
                    ret.SendBillableSpam                = false;
                    ret.SendBillableSpam7day            = false;
                    ret.SendBillableSpam3day            = false;
                    ret.SendBillableSpam1day            = false;
                    ret.SendBillableSpamNegativeBalance = false;
                    ret.AutoDeactivateUnpaid            = false;
                    ret.SmtpServer                      = "localhost";
                    ret.SmtpPort                        = 25;
                    ret.SmtpSecureConnection            = SecureConnectionType.None;
                    ret.SmtpAuthenticate                = false;
                    ret.SmtpUser                        = string.Empty;
                    ret.SmtpPassword                    = string.Empty;
                    ret.DefaultTrialPool                = string.Empty;
                    ret.DefaultBillablePool             = string.Empty;
                    ret.DefaultTariff                   = -1;
                }
            }
            return(ret);
        }
Ejemplo n.º 3
0
        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;
            }
        }