Esempio n. 1
0
 private void UpdateIfChanged_Stat(CheckBox cbChanged, TextBox val, ref Data_AppUserFile.eUserStatus res)
 {
     if (cbChanged.Checked)
     {
         res = (Data_AppUserFile.eUserStatus) int.Parse(val.Text);
     }
 }
Esempio n. 2
0
        //public static string SqlDate(this Int64 i)
        //{
        //    DateTime dt = new DateTime(i, DateTimeKind.Utc);
        //    string r = dt.ToString("yyyyMMdd HH:mm:ss");
        //    return r;
        //}
        public static string ToIntString(this Data_AppUserFile.eUserStatus s)
        {
            int    i   = (int)s;
            string str = i.ToString();

            return(str);
        }
Esempio n. 3
0
 private void ReadFromStream_V0(BinaryReader br)
 {
     this.Email         = br.ReadString();
     this.Title         = br.ReadString();
     this.DisplayLines  = DisplayLines.ReadFromStream(br);
     this.RequestedType = (Data_AppUserFile.eUserStatus)br.ReadInt32();
     this.Numbers       = new AmountAndPrice(br);
     this.Messages      = new AmountAndPrice(br);
     this.Month         = new AmountAndPrice(br);
     this.Setup         = new AmountAndPrice(br);
 }
Esempio n. 4
0
 private void InitWithDefaults()
 {
     this.Email         = string.Empty;
     this.Title         = string.Empty;
     this.DisplayLines  = new string[0];
     this.RequestedType = Data_AppUserFile.eUserStatus._end;
     this.Numbers       = new AmountAndPrice(0, 0M);
     this.Messages      = new AmountAndPrice(0, 0M);
     this.Month         = new AmountAndPrice(0, 0M);
     this.Setup         = new AmountAndPrice(0, 0M);
     this.FullPayment   = new AmountAndPrice(0, 0M);
 }
Esempio n. 5
0
 public static Data_AppUserWallet Create(
     string Email,
     string Title,
     string[] DisplayLines,
     Data_AppUserFile.eUserStatus RequestedType,
     AmountAndPrice Numbers,
     AmountAndPrice Messages,
     AmountAndPrice Month,
     AmountAndPrice Setup,
     AmountAndPrice FullPayment)
 {
     return(new Data_AppUserWallet(Email, Title, DisplayLines, RequestedType, Numbers, Messages, Month, Setup, FullPayment));
 }
Esempio n. 6
0
        public void UpdateStatus(string email, Data_AppUserFile.eUserStatus newStatus, IMyLog log)
        {
            SqlCmdBuilder cmd = new SqlCmdBuilder(TABLE_NAME);

            cmd.Add("[AccountStatus]", newStatus.ToIntString());

            string strCmd = cmd.GetSql_Update(string.Format("WHERE [Email] like '{0}'", email));

            using (SqlDisposable s = new SqlDisposable(Db, strCmd))
            {
                if (s.Reader.RecordsAffected != 1)
                {
                    log.Error("UpdateAll: *** unexpected RecordsAffected != 1");
                }
            }
        }
Esempio n. 7
0
 public Data_AppUserWallet(
     Data_AppUserFile.eUserStatus RequestedType,
     AmountAndPrice Numbers,
     AmountAndPrice Messages,
     AmountAndPrice Month,
     AmountAndPrice Setup,
     AmountAndPrice FullPayment
     )
 {
     InitWithDefaults();
     this.RequestedType = RequestedType;
     this.Numbers       = Numbers.Clone();
     this.Messages      = Messages.Clone();
     this.Month         = Month.Clone();
     this.Setup         = Setup.Clone();
     this.FullPayment   = FullPayment.Clone();
 }
Esempio n. 8
0
        public static UpdateInfo GetInfo(Data_AppUserFile.eUserStatus type)
        {
            switch (type)
            {
            case Data_AppUserFile.eUserStatus.free_account:
                return(UpdatePriceText.s_FreeAccountInfo);

            case Data_AppUserFile.eUserStatus.commercial_payassent:
                return(UpdatePriceText.s_PayAsYouSend);

            case Data_AppUserFile.eUserStatus.commercial_monthly:
                return(UpdatePriceText.s_PayMonthly);

            case Data_AppUserFile.eUserStatus.commercial_monthlyDifPrice:
                return(UpdatePriceText.s_PayMonthlyDifPrice);

            case Data_AppUserFile.eUserStatus.commercial_systemDuplication:
                return(UpdatePriceText.s_SystemDuplication);
            }
            return(null);
        }
Esempio n. 9
0
 private Data_AppUserWallet(
     string Email,
     string Title,
     string[] DisplayLines,
     Data_AppUserFile.eUserStatus RequestedType,
     AmountAndPrice Numbers,
     AmountAndPrice Messages,
     AmountAndPrice Month,
     AmountAndPrice Setup,
     AmountAndPrice FullPayment)
 {
     InitWithDefaults();
     this.Email         = Email.Trim();
     this.Title         = Title;
     this.DisplayLines  = DisplayLines.MyClone();
     this.RequestedType = RequestedType;
     this.Numbers       = Numbers.Clone();
     this.Messages      = Messages.Clone();
     this.Month         = Month.Clone();
     this.Setup         = Setup.Clone();
     this.FullPayment   = FullPayment.Clone();
 }
Esempio n. 10
0
        public void UpdateAll(
            string Email,
            string Title,
            string[] DisplayLines,
            Data_AppUserFile.eUserStatus RequestedType,
            AmountAndPrice Numbers,
            AmountAndPrice Messages,
            AmountAndPrice Month,
            AmountAndPrice Setup,
            AmountAndPrice FullPayment,
            IMyLog log)
        {
            string filePath = getWalletFullPath(Email);

            using (Stream stream = OpenFile.ForRead(filePath, true, true, log))
            {
                Data_AppUserWallet r = Data_AppUserWallet.CreateBlank();

                //1) read it in
                BinaryReader br = new BinaryReader(stream);
                r.ReadFromStream(br);

                //2) update values
                r.Email         = Email;
                r.Title         = Title;
                r.DisplayLines  = DisplayLines.MyClone();
                r.RequestedType = RequestedType;
                r.Numbers       = Numbers.Clone();
                r.Messages      = Messages.Clone();
                r.Month         = Month.Clone();
                r.Setup         = Setup.Clone();
                r.FullPayment   = FullPayment.Clone();

                //3) write it back
                stream.Seek(0, SeekOrigin.Begin);
                BinaryWriter bw = new BinaryWriter(stream);
                r.WriteToStream(bw);
            }
        }
Esempio n. 11
0
        public void UpdateAll(
            string email,
            string userName,
            string password,
            string creationIp,
            string telNumbers,
            Data_AppUserFile.eUserStatus status,
            Int32 minDelayInSeconds,
            Int64 noOfQueuedMessages,
            Int64 noOfSentMessages,
            Int64 noOfBytesSent,
            Int64 remainingMsg,
            IMyLog log)
        {
            SqlCmdBuilder cmd = new SqlCmdBuilder(TABLE_NAME);

            cmd.Add("[UserName]", userName.Quote());
            cmd.Add("[Password]", password.Quote());
            cmd.Add("[CreationIp]", creationIp.Quote());
            cmd.Add("[MobileNumbers]", telNumbers.Quote());
            cmd.Add("[AccountStatus]", status.ToIntString());
            cmd.Add("[MinDelayInSeconds]", minDelayInSeconds.ToString());
            cmd.Add("[NoOfQueuedMessages]", noOfQueuedMessages.ToString());
            cmd.Add("[NoOfSentMessages]", noOfSentMessages.ToString());
            cmd.Add("[NoOfBytesSent]", noOfBytesSent.ToString());
            cmd.Add("[RemainingMessages]", remainingMsg.ToString());

            string strCmd = cmd.GetSql_Update(string.Format("WHERE [Email] like '{0}'", email));

            using (SqlDisposable s = new SqlDisposable(Db, strCmd))
            {
                if (s.Reader.RecordsAffected != 1)
                {
                    log.Error("UpdateAll: *** unexpected RecordsAffected != 1");
                }
            }
        }
Esempio n. 12
0
        public UpdateInfo(
            string title, Data_AppUserFile.eUserStatus type,
            string[] info,
            UpdateInfoSection number,
            UpdateInfoSection message,
            UpdateInfoSection month,
            UpdateInfoSection oneTimeSetup,
            UpdateInfoSection fullPayment)
        {
            Title        = title;
            Type         = type;
            Info         = info;
            Number       = number;
            Message      = message;
            Month        = month;
            OneTimeSetup = oneTimeSetup;
            FullPayment  = fullPayment;

            Number       = Number != null ? Number : new UpdateInfoSection("", 0M, null);
            Message      = Message != null ? Message : new UpdateInfoSection("", 0M, null);
            Month        = Month != null ? Month : new UpdateInfoSection("", 0M, null);
            OneTimeSetup = OneTimeSetup != null ? OneTimeSetup : new UpdateInfoSection("", 0M, null);
            FullPayment  = FullPayment != null ? FullPayment : new UpdateInfoSection("", 0M, null);
        }
Esempio n. 13
0
 public override void CommitOrThrow_Send(MobileNoHandler storedNumbers, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter)
 {
     sendFooter = false;
 }
Esempio n. 14
0
        public override void CommitOrThrow_Send(MobileNoHandler storedNumbers, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter)
        {
            sendFooter = false;

            //1)
            Data_AppUserFile_Checker_Free.VerifyAllMobileNumbers(storedNumbers, telList);

            if (isWelcomeMessage)
            {
                throw new ArgumentException("Wrong account");
            }
            else
            {
                // 0) checkTimeDelay()
                DateTime NotBefore = new DateTime(monthlyDifPrice.monthlyDifPrice_LastMsgQueued, DateTimeKind.Utc)
                                     .AddSeconds(monthlyDifPrice.monthlyDifPrice_MinDelayInSeconds);
                if (DateTime.UtcNow < NotBefore)
                {
                    throw new ArgumentException("wait");
                }

                PriceLevelHandler levelHandler = new PriceLevelHandler(monthlyDifPrice.monthlyDifPrice_LevelDefinitions);
                if (!levelHandler.Ok)
                {
                    throw new ArgumentException("Please check configuration. (NO)");
                }

                // 0) first initialisation
                if (monthlyDifPrice.monthlyDifPrice_Level == 0)
                {
                    Data_AppUserFile.niceMoney cost1 = levelHandler.Config.FirstOrDefault(_ => _.Level == 1).Cost;
                    if (!monthlyDifPrice.monthlyDifPrice_CurrentCredit.DeductIfEnoughFund(cost1))
                    {
                        throw new ArgumentException("Please arrange a top up. (L0)");
                    }
                    else
                    {
                        monthlyDifPrice.monthlDifPricey_PeriodeStart     = DateTime.UtcNow.Ticks;
                        monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent = 0;
                        monthlyDifPrice.monthlyDifPrice_TotalMsgSent++;
                        monthlyDifPrice.monthlyDifPrice_Level         = 1;
                        monthlyDifPrice.monthlyDifPrice_LastMsgQueued = DateTime.UtcNow.Ticks;
                        commentLog($"Deducted {cost1} for initialisation", true);
                    }
                }

                // 1) Check aktive, sonst eine Periode mehr und auf Level 1
                if (monthlyDifPrice.HasExpired())
                {
                    if (!monthlyDifPrice.monthlyDifPrice_AutoRenewMonthPayment)
                    {
                        throw new ArgumentException("Please arrange a top up. (AR)");
                    }
                    Data_AppUserFile.niceMoney cost1 = levelHandler.Config.FirstOrDefault(_ => _.Level == 1).Cost;
                    if (!monthlyDifPrice.monthlyDifPrice_CurrentCredit.DeductIfEnoughFund(cost1))
                    {
                        throw new ArgumentException("Please arrange a top up. (L1)");
                    }
                    else
                    {
                        monthlyDifPrice.monthlDifPricey_PeriodeStart     = DateTime.UtcNow.Ticks;
                        monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent = 0;
                        monthlyDifPrice.monthlyDifPrice_TotalMsgSent++;
                        monthlyDifPrice.monthlyDifPrice_Level         = 1;
                        monthlyDifPrice.monthlyDifPrice_LastMsgQueued = DateTime.UtcNow.Ticks;
                        commentLog($"Deducted {cost1} to renew Month", true);
                    }
                }

                // 2) Check messageCount and go a level up if needed
                var curLev = levelHandler.Config.FirstOrDefault(_ => _.Level == monthlyDifPrice.monthlyDifPrice_Level);
                if (curLev == null)
                {
                    // bad config
                    throw new ArgumentException($"Please check configuration. (BL) - {levelHandler}");
                }
                if (curLev.MaxMessages == monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent)
                {
                    // no more messages left
                    if (!monthlyDifPrice.monthlyDifPrice_AutoInceremntLevel)
                    {
                        throw new ArgumentException("Please arrange a top up. (AI)");
                    }
                    var nextLev = levelHandler.Config.FirstOrDefault(_ => _.Level == (monthlyDifPrice.monthlyDifPrice_Level + 1));
                    if (nextLev == null)
                    {
                        // no more levels
                        throw new ArgumentException("Please arrange a top up. (NL)");
                    }
                    Data_AppUserFile.niceMoney costDif = new Data_AppUserFile.niceMoney(nextLev.Cost.ValueInUsCent - curLev.Cost.ValueInUsCent);
                    if (!monthlyDifPrice.monthlyDifPrice_CurrentCredit.DeductIfEnoughFund(costDif))
                    {
                        throw new ArgumentException("Please arrange a top up. (LN)");
                    }
                    else
                    {
                        monthlyDifPrice.monthlyDifPrice_Level = nextLev.Level;
                        monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent++;
                        monthlyDifPrice.monthlyDifPrice_TotalMsgSent++;
                        monthlyDifPrice.monthlyDifPrice_LastMsgQueued = DateTime.UtcNow.Ticks;
                        commentLog($"Deducted {costDif} to enter level {nextLev.Level}", true);
                    }
                }
                else
                {
                    //ok to send one more message
                    monthlyDifPrice.monthlyDifPrice_LastMsgQueued = DateTime.UtcNow.Ticks;
                    monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent++;
                    monthlyDifPrice.monthlyDifPrice_TotalMsgSent++;
                }
            }
        }
Esempio n. 15
0
        public override void CommitOrThrow_Send(MobileNoHandler storedNumbers, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter)
        {
            sendFooter = false;

            //1)
            Data_AppUserFile_Checker_Free.VerifyAllMobileNumbers(storedNumbers, telList);

            if (isWelcomeMessage)
            {
                throw new ArgumentException("Wrong account");
            }
            else
            {
                //3) check still active
                DateTime NotAfter = new DateTime(duplicationAccount.systemDuplication_PaidUntil, DateTimeKind.Utc);
                if (DateTime.UtcNow > NotAfter)
                {
                    throw new ArgumentException("Please arrange a top up");
                }

                //4) update counters
                duplicationAccount.systemDuplication_MsgSent      += telList.Length;
                duplicationAccount.systemDuplication_LastMsgQueued = DateTime.UtcNow.Ticks;
            }
        }
Esempio n. 16
0
        public override void CommitOrThrow_Send(MobileNoHandler storedNumbers, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter)
        {
            sendFooter = false;

            //1)
            Data_AppUserFile_Checker_Free.VerifyAllMobileNumbers(storedNumbers, telList);

            if (isWelcomeMessage)
            {
                throw new ArgumentException("Wrong account");
            }
            else
            {
                //2) checkTimeDelay()
                DateTime NotBefore = new DateTime(payAsSent.payAsSent_LastMsgQueued, DateTimeKind.Utc).AddSeconds(payAsSent.payAsSent_MinDelayInSeconds);
                if (DateTime.UtcNow < NotBefore)
                {
                    throw new ArgumentException("wait");
                }

                //3) check fonds
                Data_AppUserFile.niceMoney totalCost = payAsSent.payAsSent_CostPerMessage.MultiplyBy(telList.Length);
                if (payAsSent.payAsSent_CurrentCredit.ValueInUsCent < totalCost.ValueInUsCent)
                {
                    throw new ArgumentException("Not enouth fonds on account");
                }
                payAsSent.payAsSent_CurrentCredit.ValueInUsCent -= totalCost.ValueInUsCent;

                //4) update counters
                payAsSent.payAsSent_MsgSent      += telList.Length;
                payAsSent.payAsSent_LastMsgQueued = DateTime.UtcNow.Ticks;
            }
        }
Esempio n. 17
0
        public override void CommitOrThrow_Send(MobileNoHandler storedNumbers, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter)
        {
            sendFooter = false;

            //1)
            Data_AppUserFile_Checker_Free.VerifyAllMobileNumbers(storedNumbers, telList);

            if (isWelcomeMessage)
            {
                throw new ArgumentException("Wrong account");
            }
            else
            {
                //2) checkTimeDelay()
                DateTime NotBefore = new DateTime(monthly.monthly_LastMsgQueued, DateTimeKind.Utc).AddSeconds(monthly.monthly_MinDelayInSeconds);
                if (DateTime.UtcNow < NotBefore)
                {
                    throw new ArgumentException("wait");
                }

                //3) check still active
                DateTime NotAfter = new DateTime(monthly.monthly_PaidUntil, DateTimeKind.Utc);
                if (DateTime.UtcNow > NotAfter)
                {
                    throw new ArgumentException("Please arrange a top up");
                }

                //4) update counters
                monthly.monthly_MsgSent      += telList.Length;
                monthly.monthly_LastMsgQueued = DateTime.UtcNow.Ticks;
            }
        }
Esempio n. 18
0
        public override void CommitOrThrow_Send(MobileNoHandler storedNumbers, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter)
        {
            sendFooter = free.free_SendFooter;

            //1)
            VerifyAllMobileNumbers(storedNumbers, telList);

            if (isWelcomeMessage)
            {
                if (accountStatus == Data_AppUserFile.eUserStatus.verified_welcome_No_sent)
                {
                    // the first welcome message
                    accountStatus            = Data_AppUserFile.eUserStatus.verified_welcome_queued;
                    free.free_WelcomeCounter = (Int16)telList.Length;
                }
                else if (accountStatus == Data_AppUserFile.eUserStatus.verified_welcome_queued)
                {
                    // not the first welcome messages
                    free.free_WelcomeCounter += (Int16)telList.Length;
                }
            }
            else
            {
                //2) checkTimeDelay()
                DateTime NotBefore = new DateTime(free.free_LastMsgQueued, DateTimeKind.Utc).AddSeconds(free.free_MinDelayInSeconds);
                if (DateTime.UtcNow < NotBefore)
                {
                    throw new ArgumentException("wait");
                }

                //3) checkRemainingCounter()
                long need = telList.Length;
                long _is_ = free.free_MsgLeft;
                if (_is_ != -1)
                {
                    if (need > _is_)
                    {
                        throw new ArgumentException("Please arrange an account upgrade");
                    }
                }

                //4) check max message length
                if (MessageLength > 10240)
                {
                    throw new ArgumentException("Message too big");
                }

                //5) update counters
                free.free_MsgLeft      -= need;
                free.free_MsgQueued    += need;
                free.free_LastMsgQueued = DateTime.UtcNow.Ticks;
            }
        }
Esempio n. 19
0
        public static void CommitOrThrow_Send(this Data_AppUserFile appUserFile, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter)
        {
            sendFooter = true;
            Data_AppUserFile_CheckerBase checker = appUserFile.GetCheckerBase();

            if (checker == null)
            {
                throw new ArgumentException("Account not active (5). " + appUserFile.AccountStatusExplained());
            }
            checker.CommitOrThrow_Send(appUserFile.MobileNumbers_AllConfirmed__, telList, isWelcomeMessage, MessageLength, ref appUserFile.AccountStatus, out sendFooter);
        }