Example #1
0
        public string Process_CreateCheckTelFileForTestAccount(NiceSystemInfo niceSystem, MobileNoHandler XTelList, IMyLog log)
        {
            APIId = null;
            StringBuilder   sbInfo          = new StringBuilder();
            MobileNoHandler telForCheckFile = XTelList;

            try
            {
                timeNow = DateTime.UtcNow;

                string email = throw new NotImplementedException("not suitable for publication!");
                Data_Net__04CheckTelNumbers _04 = new Data_Net__04CheckTelNumbers(email, timeNow.Ticks, telForCheckFile.getVal, "");
                DSSwitch.msgFile04().Store(niceSystem, _04, log);
                sbInfo.AppendFormat("File {0} created\r\n", _04.GetFileName());
            }
            catch (ArgumentException ae)
            {
                sbInfo.Append(ae.Message);
            }
            catch (Exception)
            {
                sbInfo.Append("ERROR");
            }
            return(sbInfo.ToString());
        }
Example #2
0
    // This comes from the AdminTool

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            MobileNoHandler XTelList = new MobileNoHandler(Request.Headers["X-TelList"]
                                                           .Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace("\n", ""));
            if (!string.IsNullOrEmpty(Request.Headers["X-EmailB64"]))
            {
                doAddTel(
                    XTelList,
                    Encoding.ASCII.GetString(Convert.FromBase64String(Request.Headers["X-EmailB64"])));
            }
            else if (!string.IsNullOrEmpty(Request.Headers["X-CheckTel"]))
            {
                doCheckTel(XTelList);
            }
            else
            {
                throw new ArgumentException("Wrong request");
            }
        }
        catch (Exception se)
        {
            Response.ContentType = "text/plain";
            Response.Write(se.Message);
        }
    }
Example #3
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;
            }
        }
Example #4
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;
            }
        }
Example #5
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;
            }
        }
Example #6
0
 private void UpdateIfChanged_Mob(CheckBox cbChanged, TextBox val, ref MobileNoHandler res)
 {
     if (cbChanged.Checked)
     {
         res = new MobileNoHandler(val.Text);
     }
 }
Example #7
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;
            }
        }
Example #8
0
        public static void VerifyAllMobileNumbers(MobileNoHandler storedNumbers, string[] telList)
        {
            MobileHandleConfUnconfList list = new MobileHandleConfUnconfList();

            list.Add(storedNumbers.getVal, true);
            foreach (string reqTel in telList)
            {
                if (!list.Conrtains(reqTel))
                {
                    throw new ArgumentException("X-APIMobile not configured");
                }
            }
        }
Example #9
0
    private void doCheckTel(MobileNoHandler XTelList)
    {
        string Message = "";
        IMyLog log     = MyLog.GetLogger("API");

        using (StreamReader sr = new StreamReader(Request.InputStream))
        {
            Message = sr.ReadToEnd();
        }
        Response.ContentType = "text/plain";
        MessageProcessing_API api = new MessageProcessing_API(null);
        string result             = api.Process_CreateCheckTelFileForTestAccount(NiceSystemInfo.DEFAULT, XTelList, log);

        Response.Write(result);
    }
Example #10
0
        public static string CommitOrThrow_TelNumberRemove(this Data_AppUserFile appUserFile, string TelList)
        {
            Data_AppUserFile_CheckerBase checker = appUserFile.GetCheckerBase();

            if (checker == null)
            {
                throw new ArgumentException("Account not active (4). " + appUserFile.AccountStatusExplained());
            }
            MobileNoHandler            noToRemove = new MobileNoHandler(TelList);
            MobileHandleConfUnconfList existing   = new MobileHandleConfUnconfList();

            existing.Add(appUserFile.MobileNumbers_AllConfirmed__.getVal, true);
            existing.Add(appUserFile.MobileNumbers_AllUnConfirmed__.getVal, false);
            checker.CommitOrThrow_TelNumberRemove(existing, noToRemove);

            existing.Remove(TelList);
            string retString;

            existing.SortAndReturn(out appUserFile.MobileNumbers_AllConfirmed__, out appUserFile.MobileNumbers_AllUnConfirmed__, out retString);
            return(retString);
        }
Example #11
0
    private void doAddTel(MobileNoHandler XTelList, string XEmail)
    {
        string Message = "";
        IMyLog log     = MyLog.GetLogger("API");

        using (StreamReader sr = new StreamReader(Request.InputStream))
        {
            Message = sr.ReadToEnd();
        }
        Response.ContentType = "text/plain";

        // see if the numbers are already used
        TelListController currentList = DSSwitch.appUser().GetCurrentTelList(log);

        Response.Write("currentList loaded. Checking...\r\n");
        bool okToAdd = true;

        using (TelListController.Locker currentListLock = currentList.GetLock())
        {
            foreach (string tel1 in XTelList.MobileNumberArray)
            {
                if (currentListLock.Locked.GetEntry(tel1) == null)
                {
                    Response.Write(String.Format("Tel {0} OK\r\n", tel1));
                }
                else
                {
                    Response.Write(String.Format("*** Tel {0} ALREADY REGISTRED\r\n", tel1));
                    okToAdd = false;
                }
            }
        }

        if (okToAdd)
        {
            MessageProcessing_API api = new MessageProcessing_API(XEmail, true);
            string result             = api.Process_MGUseAddTelToFreeAccounts(NiceSystemInfo.DEFAULT, XTelList, log);
            Response.Write(result);
        }
    }
Example #12
0
 public abstract void CommitOrThrow_TelNumberRemove(MobileHandleConfUnconfList existing, MobileNoHandler noToRemove);
Example #13
0
 public abstract void CommitOrThrow_TelNumberAdd(MobileHandleConfUnconfList existing, MobileNoHandler noToAdd);
Example #14
0
        public static DirectTel_OutJson ProcessDirectTel(DirectTel_InJson inJson, IMyLog trayLog, LogForEmailSend log4Email, dOnAction onGet, dOnAction onAck)
        {
            trayLog.Debug("DirectTel: Loading " + inJson.SubSystem);
            NiceSystemInfo subSystem = inJson.SubSystem.GetSystemInfoFromTrayType();

            if (subSystem == null)
            {
                throw new Exception("subSystem == null");
            }

            switch (inJson.Inst)
            {
            case "Get":
            {
                // Update loopback file (with the data from the incoming object)
                if (onGet != null)
                {
                    onGet(subSystem);
                }

                // Prepare the object to be sent
                ASPTrayBase trayBase = MessageProcessing_TrayTo.GetFilesToSendToTray_ConsiderPriority(subSystem, 1, trayLog).FirstOrDefault();
                if (trayBase == null)
                {
                    // nothing, so just wait
                    return(new DirectTel_OutJson()
                        {
                            WaitSec = 10,
                        });
                }
                if (trayBase is Data_Net__00NormalMessage)
                {
                    Data_Net__00NormalMessage _00 = trayBase as Data_Net__00NormalMessage;
                    return(new DirectTel_OutJson()
                        {
                            Id = "00" + _00.GetFileName(),
                            Zapi = _00.DestMobile.Replace("+", ""),
                            Text = _00.Msg,
                            IsAddTelOnly = false,
                            WaitSec = 1,
                        });
                }
                if (trayBase is Data_Net__04CheckTelNumbers)
                {
                    Data_Net__04CheckTelNumbers _04 = trayBase as Data_Net__04CheckTelNumbers;
                    MobileNoHandler             h   = new MobileNoHandler(_04.TelList);
                    string firstTel = h.MobileNumberX_AsZapi(0);
                    return(new DirectTel_OutJson()
                        {
                            Id = "04" + _04.GetFileName(),
                            Zapi = firstTel,
                            Text = null,
                            IsAddTelOnly = true,
                            WaitSec = 1,
                        });
                }
            }
            break;

            case "Ack":
                // Update loopback file (with the data from the incoming object)
                if (onAck != null)
                {
                    onAck(subSystem);
                }

                MessageProcessing_TrayFrom proc   = new MessageProcessing_TrayFrom(subSystem, null, trayLog, log4Email);
                Data_Net_Tray2ASP          helper = new Data_Net_Tray2ASP();
                if (inJson.Id.StartsWith("00"))
                {
                    inJson.Id = inJson.Id.Substring(2);
                    Data_Net__01NormalMessageResult _01 = new Data_Net__01NormalMessageResult(inJson.Id, true);
                    helper.ObjectList.Add(_01);
                    proc.Process_TrayFrom(helper, true);
                    return(new DirectTel_OutJson());
                }
                else if (inJson.Id.StartsWith("04"))
                {
                    inJson.Id = inJson.Id.Substring(2);
                    Data_Net__05CheckTelNumbersResult _05 = new Data_Net__05CheckTelNumbersResult(inJson.Id, null, null, null);
                    helper.ObjectList.Add(_05);
                    proc.Process_TrayFrom(helper, true);
                    return(new DirectTel_OutJson());
                }
                else
                {
                }


                break;

            default:
                throw new Exception("Unknown inst");
            }

            return(null);
        }
Example #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
            {
                // 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++;
                }
            }
        }
Example #16
0
 public override void CommitOrThrow_TelNumberAdd(MobileHandleConfUnconfList existing, MobileNoHandler noToAdd)
 {
     Data_AppUserFile.niceMoney totalCost = monthly.monthly_CostPerNumber.MultiplyBy(noToAdd.MobileNumbersCount);
     if (monthly.monthly_CurrentCredit.ValueInUsCent < totalCost.ValueInUsCent)
     {
         throw new ArgumentException("Not enouth fonds on account");
     }
     monthly.monthly_CurrentCredit.ValueInUsCent -= totalCost.ValueInUsCent;
 }
Example #17
0
        void internalThread()
        {
            m_2iInfoDisplay.FileLog_Debug("internalThread start");
            m_2iInfoDisplay.FileLog_Debug(Assembly.GetAssembly(typeof(IMyLog)).WriteAssemblyVersion());

            m_2iInfoDisplay.ReturnWhenReady();

            Ix iAll = new Ix(m_2iInfoDisplay, m_4Screen, m_5Mouse, m_6Process, m_8Updater, new C9_CPUSlowdown());

            iAll.iSlowdown.Slowdown(iAll);

            processEmptyWakeUpTrigger(iAll);

            while (m_wantToStop.WaitOne(10, false) == false)
            {
                try
                {
                    iAll.iSlowdown.Slowdown(iAll);
                    m_2iInfoDisplay.LoopStart();
                    m_3iGetData.ExchangeDataWithServer(m_2iInfoDisplay, m_6Process);
                    List <ASPTrayBase> serverFiles = m_3iGetData.GetServerFiles(iAll);
                    if (serverFiles.Count == 0)
                    {
                        processEmptyWakeUpTrigger(iAll);
                    }
                    else
                    {
                        foreach (ASPTrayBase f1 in serverFiles)
                        {
                            m_2iInfoDisplay.FileLog_Info("".PadRight(50, '*'));
                            m_2iInfoDisplay.FileLog_Info("processing start : " + f1.GetFileName());
                            iAll.iSlowdown.Slowdown(iAll);
                            ASPTrayBase.eASPtrayType f1e = f1.GetEnumType();
                            switch (f1e)
                            {
                            case ASPTrayBase.eASPtrayType.ScreenShotRequest:
                            {
                                Data_Net__02ScreenshotRequest _02 = (Data_Net__02ScreenshotRequest)f1;
                                m_2iInfoDisplay.FileLog_Info("processing screenshot start: " + _02.MsgTicks.ToString());
                                Bitmap bAll = ImageCapture.GetAll();

                                m_3iGetData.AddResultFile(
                                    new Data_Net__03ScreenshotResult(
                                        bAll.BmpToB64_Png(),
                                        _02.GetFileName()));
                                m_2iInfoDisplay.FileLog_Info("processing done screenshot: " + _02.MsgTicks.ToString());
                            }
                            break;

                            case ASPTrayBase.eASPtrayType.NormalMessage:
                            {
                                Data_Net__00NormalMessage _00 = (Data_Net__00NormalMessage)f1;
                                m_2iInfoDisplay.AddLine(_00.DestMobile);
                                m_2iInfoDisplay.FileLog_Info(_00.DestMobile);
                                if (_00.FailedCounter != 0)
                                {
                                    m_2iInfoDisplay.FileLog_Info(String.Format("FailedCounter: {0} / {1}", _00.FailedCounter, _00.DisposeAfterNFailed));
                                }
                                m_2iInfoDisplay.FileLog_Info("MSG: " + _00.Msg.MsgForLogFile());
                                int  processId;
                                bool use;
                                m_3iGetData.Debug_GetProcessIdOfFile(f1, out processId, out use);
                                if (use)
                                {
                                    m_6Process.Debug_AmendProcessId(processId);
                                }

                                iAll.TypeOfProcess = Ix.eTypeOfProcess.Normal;
                                eI6Error whatsAppRes = m_6Process.Process(
                                    _00.DestMobile,
                                    _00.Msg,
                                    iAll);
                                m_2iInfoDisplay.AddLine(whatsAppRes.ToString());
                                switch (whatsAppRes)
                                {
                                case eI6Error.Success:
                                    m_3iGetData.AddResultFile(new Data_Net__01NormalMessageResult(
                                                                  _00.GetFileName(),
                                                                  true));
                                    m_2iInfoDisplay.FileLog_Debug("processing done: " + _00.UniqueId());
                                    break;

                                case eI6Error.FailedButNoLettingHostKnow_TelNotActive:
                                    m_2iInfoDisplay.AddLine("No Tel in Android yet");
                                    m_2iInfoDisplay.FileLog_Info("No Tel in Android yet");
                                    break;

                                default:
                                    // failed
                                    m_3iGetData.AddResultFile(new Data_Net__01NormalMessageResult(
                                                                  _00.GetFileName(),
                                                                  false));
                                    m_2iInfoDisplay.FileLog_Debug("processing failed (interaction): " + _00.UniqueId() + " " + whatsAppRes.ToString());
                                    break;
                                }
                            }
                            break;

                            case ASPTrayBase.eASPtrayType.CheckTelNumbers:
                            {
                                Data_Net__04CheckTelNumbers _04 = (Data_Net__04CheckTelNumbers)f1;
                                m_2iInfoDisplay.AddLine("CheckTelNumbers:" + _04.GetFileName());
                                MobileNoHandler handleOk          = new MobileNoHandler(_04.TelListChecked);
                                MobileNoHandler handleRetryPlease = new MobileNoHandler("");
                                MobileNoHandler handleNotWorking  = new MobileNoHandler("");
                                foreach (string toBeCheckedNoZap in new MobileNoHandler(_04.TelList).MobileNumberArray)
                                {
                                    string toBeChecked = toBeCheckedNoZap.Zapi_Add();
                                    m_2iInfoDisplay.AddLine("Checking " + toBeChecked);
                                    m_2iInfoDisplay.FileLog_Info("Checking " + toBeChecked);

                                    int  processId;
                                    bool use;
                                    m_3iGetData.Debug_GetProcessIdOfFile(f1, out processId, out use);
                                    if (use)
                                    {
                                        m_6Process.Debug_AmendProcessId(processId);
                                    }
                                    iAll.TypeOfProcess = Ix.eTypeOfProcess.TelNumberChecking;
                                    eI6Error whatsAppRes = m_6Process.Process(
                                        toBeChecked, null, iAll);
                                    m_2iInfoDisplay.AddLine(whatsAppRes.ToString());
                                    switch (whatsAppRes)
                                    {
                                    case eI6Error.Success:
                                        handleOk.Add(toBeCheckedNoZap);
                                        break;

                                    case eI6Error.FailedButNoLettingHostKnow_TelNotActive:
                                        handleRetryPlease.Add(toBeCheckedNoZap);
                                        break;

                                    default:
                                        // failed
                                        handleNotWorking.Add(toBeCheckedNoZap);
                                        break;
                                    }
                                }
                                m_3iGetData.AddResultFile(
                                    new Data_Net__05CheckTelNumbersResult(
                                        _04.GetFileName(),
                                        handleOk.getVal,
                                        handleRetryPlease.getVal,
                                        handleNotWorking.getVal));
                            }
                            break;

                            default:
                                m_2iInfoDisplay.AddLine("UNKOWN FILE TYPE");
                                m_2iInfoDisplay.FileLog_Error("UNKOWN FILE TYPE");
                                break;
                            }
                        }
                    }

                    // delay
                    if (m_3iGetData.DoWeHaveDataToSend())
                    {
                        // we have data to send, so dont wait too long
                        m_2iInfoDisplay.Delay(500);
                    }
                    else
                    {
                        m_2iInfoDisplay.Delay(2 * 1000);
                    }
                }
                catch (SystemException se)
                {
                    m_2iInfoDisplay.AddLine("SystemException");
                    m_2iInfoDisplay.AddLine(se.Message);
                    m_2iInfoDisplay.AddLine(se.ToString());
                    if (!se.ToString().Contains("System.Net.WebException: The operation has timed out"))
                    {
                        m_2iInfoDisplay.FileLog_Error(se.Message + " - " + se.ToString());
                    }
                    m_3iGetData.Reset_toASP();
                    m_2iInfoDisplay.Delay(5 * 1000);
                }
            }
        }
Example #18
0
        private void processCheckTelNumbersResult(Data_Net__05CheckTelNumbersResult _05, bool sendEmails)
        {
            // 1) delete the triggering file
            ASPTrayBase.MsgFileParts    info  = ASPTrayBase.s_MsgFile_GetPartsFromMessageFile(_05.RequestFileName);//mg check this
            Data_Net__04CheckTelNumbers msg04 = DSSwitch.msgFile04().ReadOne(niceSystem, _05.RequestFileName, trayLog);

            DSSwitch.msgFile04().Delete(niceSystem, _05.RequestFileName, trayLog);

            string niceEmail                   = null;
            bool   sendWelcomeMessages         = false;
            string sendWelcomeMessages_GUID    = null;
            string sendWelcomeMessages_TelList = null;

            if ((_05.TelListOk == null) && (_05.TelListDoRetry == null) && (_05.TelListNotWorking == null))
            {
                // this is from directTel, so the first checked is not ok
                MobileNoHandler hOk   = new MobileNoHandler(msg04.TelListChecked);
                MobileNoHandler hToDo = new MobileNoHandler(msg04.TelList);
                hOk.AddIfNew(hToDo.RemoveAndReturnFirst());

                _05.TelListOk         = hOk.getVal;
                _05.TelListDoRetry    = hToDo.getVal;
                _05.TelListNotWorking = "";
            }

            // 2) do retry if not all worked and non failed
            if ((_05.TelListDoRetry.Length > 0) && (_05.TelListNotWorking.Length == 0))
            {
                // early retry
                Data_Net__04CheckTelNumbers _04 = new Data_Net__04CheckTelNumbers(info.Email, DateTime.UtcNow.Ticks, _05.TelListDoRetry, _05.TelListOk);
                DSSwitch.msgFile04().Store(niceSystem, _04, trayLog);
            }
            else
            {
                // open the userfile and merge
                MobileNoHandler doAgain = new MobileNoHandler(_05.TelListDoRetry);
                DSSwitch.appUser().Update_General(info.Email, delegate(Data_AppUserFile user, Object args)
                {
                    //  action
                    niceEmail = user.Email;
                    foreach (string telGood in (new MobileNoHandler(_05.TelListOk)).MobileNumberArray)
                    {
                        user.MobileNumbers_AllConfirmed__.AddIfNew(telGood);
                        user.MobileNumbers_AllUnConfirmed__.Remove(telGood);
                    }
                    foreach (string telNotWorking in (new MobileNoHandler(_05.TelListNotWorking)).MobileNumberArray)
                    {
                        user.AddCommentLine(telNotWorking + " not working", true);
                        user.MobileNumbers_AllUnConfirmed__.Remove(telNotWorking);
                        user.MobileNumbers_AllConfirmed__.Remove(telNotWorking);
                    }
                    foreach (string telAgain in user.MobileNumbers_AllUnConfirmed__.MobileNumberArray)
                    {
                        doAgain.AddIfNew(telAgain);
                    }

                    if (doAgain.MobileNumbersCount == 0)
                    {
                        // nothing elso to check, so make a desision
                        if (user.AccountStatus == Data_AppUserFile.eUserStatus.verified_checkingTelNumbers)
                        {
                            if (user.MobileNumbers_AllConfirmed__.MobileNumbersCount > 0)
                            {
                                // we have good numbers, so upgrade
                                user.AccountStatus = Data_AppUserFile.eUserStatus.free_account;
                                if (sendEmails)
                                {
                                    EMail.SendJustActivated(user, log4Email);
                                }
                                sendWelcomeMessages         = true;
                                sendWelcomeMessages_GUID    = user.ApiGuId;
                                sendWelcomeMessages_TelList = user.MobileNumbers_AllConfirmed__.getVal;
                            }
                            else
                            {
                                // we have no valid numbers, so block
                                user.AccountStatus = Data_AppUserFile.eUserStatus.blocked;
                                if (sendEmails)
                                {
                                    EMail.SendWrongTelRegistered(user, log4Email);
                                }
                            }
                        }
                        else if (user.AccountStatus == Data_AppUserFile.eUserStatus.free_account)
                        {
                            // this could be a free account number adding
                            if (sendEmails)
                            {
                                EMail.SendJustActivated(user, log4Email);
                            }
                            sendWelcomeMessages         = true;
                            sendWelcomeMessages_GUID    = user.ApiGuId;
                            sendWelcomeMessages_TelList = user.MobileNumbers_AllConfirmed__.getVal;
                        }
                    }
                }, null, delegate(Object args)
                {
                    // post user file processing
                    if (doAgain.MobileNumbersCount != 0)
                    {
                        // still unprocessed numbers
                        Data_Net__04CheckTelNumbers _04 = new Data_Net__04CheckTelNumbers(info.Email, DateTime.UtcNow.Ticks, doAgain.getVal, "");
                        DSSwitch.msgFile04().Store(niceSystem, _04, trayLog);
                    }
                    if (sendWelcomeMessages)
                    {
                        MessageProcessing_API api = new MessageProcessing_API(sendWelcomeMessages_GUID);
                        string additionalInfo;
                        api.SendWhatsApp(
                            niceSystem,
                            sendWelcomeMessages_TelList,
                            "Welcome to NiceApi.net\r\n",
                            true,
                            trayLog,
                            out additionalInfo);
                    }
                }, trayLog);
            }
        }
Example #19
0
        public string Process_MGUseAddTelToFreeAccounts(NiceSystemInfo niceSystem, MobileNoHandler XTelList, int maxNumbers, IMyLog log)
        {
            StringBuilder   sbInfo          = new StringBuilder();
            MobileNoHandler telForCheckFile = new MobileNoHandler("");

            try
            {
                timeNow = DateTime.UtcNow;
                // 1 extract (check) input data
                #region 1 extract (check) input data
                if (string.IsNullOrEmpty(Email))
                {
                    throw new ArgumentException("X-APIId missing");
                }
                #endregion

                // 2 load user file and check guid
                #region 2 load user file and check guid
                DSSwitch.appUser().Update_General(Email, delegate(Data_AppUserFile user, Object args)
                {
                    if (user == null)
                    {
                        throw new ArgumentException("X-APIId unknown");
                    }
                    #endregion

                    // 3 action, add up to 5 numbers and produce telCheck file
                    #region 3 action, add up to 5 numbers and produce telCheck file
                    if (user.AccountStatus == Data_AppUserFile.eUserStatus.blocked)
                    {
                        // unblock, as this is an instraction from the admin
                        user.AccountStatus = Data_AppUserFile.eUserStatus.free_account;
                    }

                    if (user.AccountStatus != Data_AppUserFile.eUserStatus.free_account)
                    {
                        throw new ArgumentException("This applies only to free_account. Not to " + user.AccountStatus.ToString());
                    }
                    if ((
                            user.MobileNumbers_AllConfirmed__.MobileNumbersCount +
                            user.MobileNumbers_AllUnConfirmed__.MobileNumbersCount +
                            XTelList.MobileNumbersCount) > maxNumbers)
                    {
                        throw new ArgumentException("Only up to 5 numbers allowed");
                    }
                    foreach (string tel1 in XTelList.MobileNumberArray)
                    {
                        user.MobileNumbers_AllUnConfirmed__.Add(tel1);
                        telForCheckFile.Add(tel1);
                        sbInfo.AppendFormat("Added {0}\r\n", tel1);
                    }
                    sbInfo.AppendFormat("Now {0} # registered\r\n", (user.MobileNumbers_AllConfirmed__.MobileNumbersCount + user.MobileNumbers_AllUnConfirmed__.MobileNumbersCount));
                    #endregion
                }, null, delegate(Object args)
                                                  // 4 post user file handling, create telCheck file
                {
                    Data_Net__04CheckTelNumbers _04 = new Data_Net__04CheckTelNumbers(Email, timeNow.Ticks, telForCheckFile.getVal, "");
                    DSSwitch.msgFile04().Store(niceSystem, _04, log);
                    sbInfo.AppendFormat("File {0} created\r\n", _04.GetFileName());
                }, log);
            }
            catch (ArgumentException ae)
            {
                sbInfo.Append(ae.Message);
            }
            catch (Exception)
            {
                sbInfo.Append("ERROR");
            }
            return(sbInfo.ToString());
        }
Example #20
0
 public string Process_MGUseAddTelToFreeAccounts(NiceSystemInfo niceSystem, MobileNoHandler XTelList, IMyLog log)
 {
     return(Process_MGUseAddTelToFreeAccounts(niceSystem, XTelList, 5, log));
 }
Example #21
0
 public override void CommitOrThrow_TelNumberAdd(MobileHandleConfUnconfList existing, MobileNoHandler noToAdd)
 {
     Data_AppUserFile.niceMoney totalCost = monthlyDifPrice.monthlyDifPrice_CostPerNumber.MultiplyBy(noToAdd.MobileNumbersCount);
     if (!monthlyDifPrice.monthlyDifPrice_CurrentCredit.DeductIfEnoughFund(totalCost))
     {
         throw new ArgumentException("Not enouth fonds on account");
     }
 }
Example #22
0
 public override void CommitOrThrow_Send(MobileNoHandler storedNumbers, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter)
 {
     sendFooter = false;
 }
Example #23
0
 public override void CommitOrThrow_TelNumberRemove(MobileHandleConfUnconfList existing, MobileNoHandler noToRemove)
 {
     throw new ArgumentException("Tel number manipulation not allowed");
 }
Example #24
0
 public override void CommitOrThrow_TelNumberRemove(MobileHandleConfUnconfList existing, MobileNoHandler noToRemove)
 {
 }
Example #25
0
        public string Process_TelNumAPI(NiceSystemInfo niceSystem, string XAPIInstruction, string Message, IMyLog log)
        {
            StringBuilder sbRet = new StringBuilder();

            try
            {
                timeNow = DateTime.UtcNow;
                // 1 extract (check) input data
                #region 1 extract input data
                if (string.IsNullOrEmpty(APIId))
                {
                    throw new ArgumentException("X-APIId missing");
                }
                eTelNum_Instruction telNum_Instruction = castInstractionOrThrow(XAPIInstruction);
                MobileNoHandler     telNum_Handler     = new MobileNoHandler(Message.Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace("\n", ""));
                #endregion

                // 2 load user file and check guid
                #region 2 load user file and check guid
                if (Email == null)
                {
                    throw new ArgumentException("X-APIId unknown");
                }
                MobileNoHandler telAddToCheckingFile = new MobileNoHandler("");
                DSSwitch.appUser().Update_General(Email, delegate(Data_AppUserFile user, Object args)
                {
                    if (user == null)
                    {
                        throw new ArgumentException("X-APIId unknown");
                    }
                    if (user.ApiGuId != APIId)
                    {
                        throw new ArgumentException("X-APIId unknown");
                    }
                    if (!user.IsAccountActive(""))
                    {
                        throw new ArgumentException("Account not active (8). " + user.AccountStatusExplained());
                    }
                    if (!user.AddNumber_AllowedWithAPI)
                    {
                        throw new ArgumentException("Not allowed for this account");
                    }
                    #endregion

                    // 3 action format retString according to telNum_Instruction
                    #region 3 action format retString according to telNum_Instruction
                    switch (telNum_Instruction)
                    {
                    case eTelNum_Instruction.ShowConfirmed:
                        sbRet.Append(user.MobileNumbers_AllConfirmed__.getVal);
                        break;

                    case eTelNum_Instruction.ShowUnconfirmed:
                        sbRet.Append(user.MobileNumbers_AllUnConfirmed__.getVal);
                        break;

                    case eTelNum_Instruction.Show:
                        sbRet.AppendLine("Plan: " + user.AccountStatus.ToString());
                        sbRet.AppendLine(String.Format("Counter: {0} / {1}", user.MobileNumbers_AllConfirmed__.MobileNumbersCount, user.MobileNumbers_AllUnConfirmed__.MobileNumbersCount));
                        sbRet.AppendLine("Confirmed: " + user.MobileNumbers_AllConfirmed__.getVal);
                        sbRet.AppendLine("Unconfirmed: " + user.MobileNumbers_AllUnConfirmed__.getVal);
                        break;

                    case eTelNum_Instruction.Add:
                        {
                            MobileNoHandler XTelList = new MobileNoHandler(Message, true);

                            foreach (string tel1 in XTelList.MobileNumberArray)
                            {
                                if (user.MobileNumbers_AllConfirmed__.Contains(tel1))
                                {
                                    sbRet.AppendLine(tel1 + " is already confirmed.");
                                }
                                else if (user.MobileNumbers_AllUnConfirmed__.Contains(tel1))
                                {
                                    sbRet.AppendLine(tel1 + " is already on the list.");
                                }
                                else if (!user.GetCheckerBase(true).FundManagement_CommitAddOneNumber(tel1))
                                {
                                    sbRet.AppendLine("Not enough funds to add " + tel1 + ".");
                                }
                                else
                                {
                                    sbRet.AppendLine(tel1 + " added.");
                                    user.MobileNumbers_AllUnConfirmed__.Add(tel1);
                                    telAddToCheckingFile.Add(tel1);
                                }
                            }
                        }
                        break;

                    case eTelNum_Instruction.Remove:
                        throw new ArgumentException("Remove not allowed for this account");
                    //break;

                    default:
                        throw new ArgumentException("Internel Error");
                    }
                    #endregion
                }, null, delegate(Object args)
                {
                    if (telAddToCheckingFile.MobileNumbersCount > 0)
                    {
                        Data_Net__04CheckTelNumbers _04 = new Data_Net__04CheckTelNumbers(Email, timeNow.Ticks, telAddToCheckingFile.getVal, "");
                        DSSwitch.msgFile04().Store(niceSystem, _04, log);
                    }
                }, log);
            }
            catch (ArgumentException ae)
            {
                sbRet = new StringBuilder();
                sbRet.Append(ae.Message);
            }
            catch (Exception)
            {
                sbRet = new StringBuilder();
                sbRet.Append("ERROR");
            }
            return(sbRet.ToString());;
        }