Exemple #1
0
        private string createMessageFile(NiceSystemInfo niceSystem, int telId, string telNumber, string cleanMessage, string email, DateTime utcNow, IMyLog log, bool noCounterUpdate, bool sendFooter, Int32 MaxFailBeforeDispose)
        {
            Data_Net__00NormalMessage msg = new Data_Net__00NormalMessage(
                Data_AppUserFile.EmailSaveChars(email),
                "zapi_" + telNumber,
                utcNow.Ticks + (Int64)telId,
                sendFooter ?
                cleanMessage + "\r\nSent via NiceApi.net\r\n" :
                cleanMessage + "\r\n",
                0,
                MaxFailBeforeDispose,
                noCounterUpdate);

            DSSwitch.msgFile00().Store(niceSystem, msg, Data_Net__00NormalMessage.eLocation.Queued, log);
            return(msg.GetFileName());
        }
Exemple #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);
     });
 }
Exemple #3
0
        private void processNormalMessageResult(Data_Net__01NormalMessageResult _01)
        {
            if (_01.Success)
            {
                // Normal Message, success
                // 1) read in and delete msg file
                Data_Net__00NormalMessage msg00 = DSSwitch.msgFile00().ReadOne(niceSystem, _01.FileName, Data_Net__00NormalMessage.eLocation.Queued, trayLog);
                DSSwitch.msgFile00().Delete(niceSystem, _01.FileName, Data_Net__00NormalMessage.eLocation.Queued, trayLog);

                // 2) update counters in user file (if needed)
                DSSwitch.appUser().Update_General(
                    msg00.UserId,
                    OnProcessedHandler.OnProcessed,
                    new OnProcessedHandler(msg00.Msg.Length, log4Email, !msg00.NoCounterUpdate),
                    OnProcessedHandler.PostProcess,
                    trayLog);

                // 3) write msg file to processed folder
                DSSwitch.msgFile00().Store(niceSystem, (Data_Net__00NormalMessage)msg00, Data_Net__00NormalMessage.eLocation.Processed, trayLog);
            }
            else
            {
                // Normal Message, failed
                // 1) read in and delete msg file
                Data_Net__00NormalMessage msg00 = DSSwitch.msgFile00().ReadOne(niceSystem, _01.FileName, Data_Net__00NormalMessage.eLocation.Queued, trayLog);
                DSSwitch.msgFile00().Delete(niceSystem, _01.FileName, Data_Net__00NormalMessage.eLocation.Queued, trayLog);

                // 2) Increas failed counter and see whether we dispose of it
                msg00.FailedCounter++;
                if ((msg00.DisposeAfterNFailed != -1) && (msg00.FailedCounter >= msg00.DisposeAfterNFailed))
                {
                    // take it off the running loop
                    // 2) update counters in user file (if needed)
                    DSSwitch.appUser().Update_General(
                        msg00.UserId,
                        OnProcessedHandler.OnProcessed,
                        new OnProcessedHandler(msg00.Msg.Length, log4Email, !msg00.NoCounterUpdate),
                        OnProcessedHandler.PostProcess,
                        trayLog);

                    // 3) write msg file to disposed folder
                    DSSwitch.msgFile00().Store(niceSystem, msg00, Data_Net__00NormalMessage.eLocation.Disposed, trayLog);
                }
                else if (msg00.AliveSince().TotalHours > 12)
                {
                    // take it off the running loop after 12 hours of failure
                    // 2) update counters in user file (if needed)
                    DSSwitch.appUser().Update_General(
                        msg00.UserId,
                        OnProcessedHandler.OnProcessed,
                        new OnProcessedHandler(msg00.Msg.Length, log4Email, !msg00.NoCounterUpdate),
                        OnProcessedHandler.PostProcess,
                        trayLog);

                    // 3) write msg file to disposed folder
                    DSSwitch.msgFile00().Store(niceSystem, msg00, Data_Net__00NormalMessage.eLocation.Disposed, trayLog);

                    // 4) Inform the administrator about it
                    StringBuilder sbBody = new StringBuilder();
                    sbBody.AppendLine("Message removed after 12 hours of failure");
                    foreach (var s in msg00.ToFullString())
                    {
                        sbBody.AppendLine(s);
                    }
                    sbBody.AppendLine("You might consider blocking this user.");
                    EMail.SendGeneralEmail(null, true, "12 hours of failure", sbBody.ToString(), log4Email);
                }
                else
                {
                    // keep in running
                    DSSwitch.msgFile00().Store(niceSystem, msg00, Data_Net__00NormalMessage.eLocation.Queued, trayLog);
                }
            }
        }
Exemple #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());
        }