Example #1
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 #2
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);
            }
        }