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
 public static void ProcessQueuedItems(NiceSystemInfo niceSystem, dProcessOne processAction, IMyLog log)
 {
     DSSwitch.msgFile00().ForEach(niceSystem, Data_Net__00NormalMessage.eLocation.Queued, log,
                                  delegate(Data_Net__00NormalMessage msg)
     {
         processAction(msg);
     });
     DSSwitch.msgFile02().ForEach(niceSystem, log,
                                  delegate(Data_Net__02ScreenshotRequest msg)
     {
         processAction(msg);
     });
     DSSwitch.msgFile04().ForEach(niceSystem, log,
                                  delegate(Data_Net__04CheckTelNumbers msg)
     {
         processAction(msg);
     });
 }
Example #3
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 #4
0
        public string Process_Registration_JustVerified(NiceSystemInfo niceSystem, out bool ok, bool sendAdminNotification, bool sendAdminNotificationToWhatsapp, IMyLog log, LogForEmailSend log4Email)
        {
            StringBuilder sbInfo     = new StringBuilder();
            string        telToCheck = null;

            ok = false;
            string friendlyEmail = null;
            bool   okIntern      = false;

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

                // 2 load user file and check guid
                string email = Data_AppUserFile.API_IdToEmail(APIId);
                if (email == null)
                {
                    throw new ArgumentException("X-APIId unknown");
                }
                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.AccountStatus != Data_AppUserFile.eUserStatus.email_sent_for_verification)
                    {
                        throw new ArgumentException("AccountStatus is wrong");
                    }

                    // 3 action, produce telCheck file and update AccountStatus
                    user.AccountStatus = Data_AppUserFile.eUserStatus.verified_checkingTelNumbers;
                    telToCheck         = user.MobileNumbers_AllConfirmed__.getVal + user.MobileNumbers_AllUnConfirmed__.getVal;
                    friendlyEmail      = user.Email;
                    okIntern           = true;
                }, null, delegate(Object args)
                {
                    // post process
                    if (log != null)
                    {
                        log.Info(friendlyEmail + " just verified his email");
                    }
                    if (sendAdminNotification)
                    {
                        EMail.SendAdminNotification(friendlyEmail + " just verified his email", log4Email);
                    }
                    if (sendAdminNotificationToWhatsapp)
                    {
                        NotificationInfo notificationInfo = DSSwitch.full().GetNotificationInfo();
                        NiceSystemInfo notifyToUse        = DSSwitch.full().GetSystems(false).FirstOrDefault(s => s.Name == notificationInfo.Name);
                        if (notifyToUse != null)
                        {
                            Data_Net__00NormalMessage msg = new Data_Net__00NormalMessage(
                                Data_AppUserFile.API_IdToEmail(notifyToUse.APIId),
                                "zapi_" + notificationInfo.RxTel,
                                DateTime.UtcNow.Ticks,
                                friendlyEmail + " just verified his email",
                                0, 10, true);
                            DSSwitch.msgFile00().Store(notifyToUse, msg, Data_Net__00NormalMessage.eLocation.Queued, log);
                        }
                    }
                    Data_Net__04CheckTelNumbers _04 = new Data_Net__04CheckTelNumbers(friendlyEmail, timeNow.Ticks, telToCheck, "");
                    DSSwitch.msgFile04().Store(niceSystem, _04, log);
                }, log);
            }
            catch (ArgumentException ae)
            {
                sbInfo.Append(ae.Message);
            }
            catch (Exception)
            {
                sbInfo.Append("ERROR");
            }
            ok = okIntern;
            return(sbInfo.ToString());
        }
Example #5
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 #6
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());;
        }