コード例 #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());
        }
コード例 #2
0
        public Data_Net__00NormalMessage ReadOne(NiceSystemInfo niceSystem, string fileName, Data_Net__00NormalMessage.eLocation location, IMyLog log)
        {
            try
            {
                WithAndWithoutUnderline ww = new WithAndWithoutUnderline(
                    FolderNames.GetFolder(niceSystem, eLocationToMyFolder(location)),
                    fileName);

                Data_Net__00NormalMessage o = null;

                Stream stream = OpenFile.ForRead(ww.Existing, false, false, log);
                if (stream == null)
                {
                    return(null);
                }
                using (BinaryReader br = new BinaryReader(stream))
                {
                    ASPTrayBase ox = ASPTrayBase.ReadOne(br);
                    if (ox.GetEnumType() == ASPTrayBase.eASPtrayType.NormalMessage)
                    {
                        o = (Data_Net__00NormalMessage)ox;
                    }
                }
                return(o);
            }
            catch (SystemException se)
            {
                log.Error("*** SystemException ***");
                log.Error(se.Message);
            }
            return(null);
        }
コード例 #3
0
        public static NiceSystemInfo GetSystemInfoFromTrayType(this string trayType)
        {
            // use null if not there
            NiceSystemInfo ret = DSSwitch.full().GetSystems(false).FirstOrDefault(_ => _.Name == trayType);

            return(ret);
        }
コード例 #4
0
        public Data_Net__02ScreenshotRequest ReadOne(NiceSystemInfo niceSystem, string fileName, IMyLog log)
        {
            try
            {
                WithAndWithoutUnderline ww = new WithAndWithoutUnderline(
                    FolderNames.GetFolder(niceSystem, MyFolders.ASP_QueuedMessages_),
                    fileName);
                Data_Net__02ScreenshotRequest o = null;

                Stream stream = OpenFile.ForRead(ww.Existing, false, false, log);
                if (stream == null)
                {
                    return(null);
                }
                using (BinaryReader br = new BinaryReader(stream))
                {
                    ASPTrayBase ox = ASPTrayBase.ReadOne(br);
                    if (ox.GetEnumType() == ASPTrayBase.eASPtrayType.ScreenShotRequest)
                    {
                        o = (Data_Net__02ScreenshotRequest)ox;
                    }
                }
                return(o);
            }
            catch (SystemException se)
            {
                log.Error("*** SystemException ***");
                log.Error(se.Message);
            }
            return(null);
        }
コード例 #5
0
        protected DataFile_Base(NiceSystemInfo niceSystem, OpenType openType)
        {
            this.niceSystem = niceSystem;
            switch (openType)
            {
            case OpenType.ForUpdate_CreateIfNotThere:
                _forUpdate = true;
                _stream    = AnyServerFile.GetForUpdate_CreateIfNeeded(GetFullPath(), this);
                break;

            case OpenType.ReadOnly_CreateIfNotThere:
                _forUpdate = false;
                _stream    = AnyServerFile.GetForReadOnly(GetFullPath());
                if (_stream == null)
                {
                    _forUpdate = true;
                    _stream    = AnyServerFile.GetForUpdate_CreateIfNeeded(GetFullPath(), this);
                }
                else
                {
                    NetFrom(new BinaryReader(_stream));
                }
                break;
            }
        }
コード例 #6
0
 public MessageProcessing_TrayFrom(NiceSystemInfo niceSystem, d_OnScreenShot onScreenshot, IMyLog trayLog, LogForEmailSend log4Email)
 {
     this.onScreenshot = onScreenshot;
     this.trayLog      = trayLog;
     this.log4Email    = log4Email;
     this.niceSystem   = niceSystem;
 }
コード例 #7
0
        public static void Update(NiceSystemInfo niceSystem, string b64In)
        {
            byte[]       baImg = Convert.FromBase64String(b64In);
            MemoryStream msImg = new MemoryStream(baImg);

            using (DataFile_ScreenShot ss = new DataFile_ScreenShot(niceSystem, OpenType.ForUpdate_CreateIfNotThere))
            {
                ss.imgScreen = Bitmap.FromStream(msImg);
            }
        }
コード例 #8
0
        public static NiceSystemInfo GetSystemInfoFromAPIId(this string apiId)
        {
            // use Default if not there
            NiceSystemInfo ret = DSSwitch.full().GetSystems(false).FirstOrDefault(_ => _.APIId == apiId);

            if (ret == null)
            {
                return(NiceSystemInfo.DEFAULT);
            }
            return(ret);
        }
コード例 #9
0
 public void Store(NiceSystemInfo niceSystem, Data_Net__02ScreenshotRequest msg, IMyLog log)
 {
     try
     {
         MyFolders.ASP_QueuedMessages_.WriteToFile(niceSystem, msg, log);
     }
     catch (SystemException se)
     {
         log.Error("*** SystemException ***");
         log.Error(se.Message);
     }
 }
コード例 #10
0
 public void Store(NiceSystemInfo niceSystem, Data_Net__00NormalMessage msg, Data_Net__00NormalMessage.eLocation location, IMyLog log)
 {
     try
     {
         eLocationToMyFolder(location).WriteToFile(niceSystem, msg, log);
     }
     catch (SystemException se)
     {
         log.Error("*** SystemException ***");
         log.Error(se.Message);
     }
 }
コード例 #11
0
 private void onScreenshot(string b64Data, NiceSystemInfo subSystem)
 {
     // 2) Update the loopback file
     //todo using (DataFile_Loopback ld = new DataFile_Loopback(DataFile_Base.OpenType.ForUpdate_CreateIfNotThere))
     //{
     //    ld.processedLoopbackStartTime =
     //    ld.processedLoopbackDoneTime = DateTime.UtcNow;
     //    ld.processedScreenshotStartTime =
     //    ld.processedScreenshotDoneTime = DateTime.UtcNow;
     //}
     if (!String.IsNullOrEmpty(b64Data))
     {
         DataFile_ScreenShot.Update(subSystem, b64Data);
     }
 }
コード例 #12
0
 public void Delete(NiceSystemInfo niceSystem, string fileName, Data_Net__00NormalMessage.eLocation location, IMyLog log)
 {
     try
     {
         WithAndWithoutUnderline ww = new WithAndWithoutUnderline(
             FolderNames.GetFolder(niceSystem, eLocationToMyFolder(location)),
             fileName);
         File.Delete(ww.Existing);
     }
     catch (SystemException se)
     {
         log.Error("*** SystemException ***");
         log.Error(se.Message);
     }
 }
コード例 #13
0
 public void Delete(NiceSystemInfo niceSystem, string fileName, IMyLog log)
 {
     try
     {
         WithAndWithoutUnderline ww = new WithAndWithoutUnderline(
             FolderNames.GetFolder(niceSystem, MyFolders.ASP_QueuedMessages_),
             fileName);
         File.Delete(ww.Existing);
     }
     catch (SystemException se)
     {
         log.Error("*** SystemException ***");
         log.Error(se.Message);
     }
 }
コード例 #14
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());
        }
コード例 #15
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);
     });
 }
コード例 #16
0
        public static List <ASPTrayBase> GetFilesToSendToTray_ConsiderPriority(NiceSystemInfo niceSystem, int limit, IMyLog log)
        {
            List <ASPTrayBase> FileListNormal   = new List <ASPTrayBase>();
            List <ASPTrayBase> FileListPriority = new List <ASPTrayBase>();

            MessageProcessing.ProcessQueuedItems(
                niceSystem,
                new dProcessOne(delegate(ASPTrayBase msg)
            {
                if (msg.IsPriority())
                {
                    FileListPriority.Add(msg);
                }
                else
                {
                    FileListNormal.Add(msg);
                }
            }),
                log);

            if (FileListPriority.Count > 0)
            {
                return(FileListPriority);
            }

            // 1) Sort
            FileListNormal.Sort(ComparisonWithPriority);

            // 2) Limit
            if (limit != -1)
            {
                while (FileListNormal.Count > limit)
                {
                    FileListNormal.RemoveAt(FileListNormal.Count - 1);
                }
            }

            return(FileListNormal);
        }
コード例 #17
0
 public void ForEach(NiceSystemInfo niceSystem, IMyLog log, dProcess_Data_Net__02ScreenshotRequest cb)
 {
     try
     {
         foreach (var f1 in Directory.GetFiles(FolderNames.GetFolder(niceSystem, MyFolders.ASP_QueuedMessages_)))
         {
             if (!ASPTrayBase.s_MsgFile_IsOld(f1))
             {
                 ASPTrayBase d1 = ASPTrayBase.ReadOne(f1, log);
                 if ((d1 != null) && (d1.GetEnumType() == ASPTrayBase.eASPtrayType.ScreenShotRequest))
                 {
                     cb((Data_Net__02ScreenshotRequest)d1);
                 }
             }
         }
     }
     catch (SystemException se)
     {
         log.Error("*** SystemException ***");
         log.Error(se.Message);
     }
 }
コード例 #18
0
        public string Process_Registration(NiceSystemInfo niceSystem, out bool fileArleadyUsed, bool sendActivationEmail, string UserName, string MoblieAllNumbers, string Email, string Password, string CreationIp, string WhereHeardText, IMyLog log, LogForEmailSend log4Email)
        {
            StringBuilder sbInfo = new StringBuilder();

            fileArleadyUsed = true;
            try
            {
                timeNow = DateTime.UtcNow;
                Data_AppUserFile ud = Data_AppUserFile.Create(
                    UserName, true, MoblieAllNumbers, Email, Password, CreationIp);
                sbInfo.Append(ud.ApiGuId);
                DSSwitch.appUser().StoreNew(ud, out fileArleadyUsed, log);
                if (!fileArleadyUsed)
                {
                    if (sendActivationEmail)
                    {
                        EMail.SendRegisterActivation(ud, log4Email);
                    }
                    if (log != null)
                    {
                        log.Info(ud.Email + " account created");
                    }
                    if (log != null)
                    {
                        log.Info("WhereHeard " + WhereHeardText);
                    }
                }
            }
            catch (ArgumentException ae)
            {
                sbInfo.Append(ae.Message);
            }
            catch (Exception)
            {
                sbInfo.Append("ERROR");
            }
            return(sbInfo.ToString());
        }
コード例 #19
0
        public List <NiceSystemInfo> GetSystems(bool createResources)
        {
            string fileSystems = "FileSystems".AppSettingsGet().Replace("\r", "").Replace("\n", "").Replace("\t", "");

            string[] systems          = fileSystems.Split('|');
            List <NiceSystemInfo> ret = new List <NiceSystemInfo>();

            foreach (var system in systems)
            {
                string[] systemSplit = system.Split(new char[] { ',' });
                if (systemSplit.Length != 2)
                {
                    throw new System.Configuration.ConfigurationErrorsException(system);
                }

                NiceSystemInfo a = new NiceSystemInfo();
                a.Name    = systemSplit[0];
                a.Default = a.Name == "Default";
                a.APIId   = systemSplit[1];
                ret.Add(a);
                if (createResources)
                {
                    NiceApiLibrary_low.FolderNames.CreateFoldersForAsp(a);
                }
            }
            if (ret.FirstOrDefault(_ => _.Default) == null)
            {
                throw new System.Configuration.ConfigurationErrorsException("GetSystems. No Default found.");
            }

            _appUser   = new Data_AppUserFileHandling_File();
            _appWallet = new Data_AppUserWalletHandling_File();
            _00        = new Data_Net__00NormalMessage_File();
            _02        = new Data_Net__02ScreenshotRequest_File();
            _04        = new Data_Net__04CheckTelNumbers_File();

            return(ret);
        }
コード例 #20
0
        private void forEach(NiceSystemInfo niceSystem, DateTime newerThan, string containsUser, MyFolders folder, IMyLog log, dProcess_Data_Net__00NormalMessage cb)
        {
            foreach (var f1 in Directory.GetFiles(FolderNames.GetFolder(niceSystem, folder)))
            {
                if ((containsUser != null) && (!f1.Contains(containsUser)))
                {
                    // wrong user
                    continue;
                }

                DateTime fileTime = ASPTrayBase.s_MsgFile_GetDateTimeOfMessageFile(f1);
                if (fileTime >= newerThan)
                {
                    if (!ASPTrayBase.s_MsgFile_IsOld(f1))
                    {
                        ASPTrayBase d1 = ASPTrayBase.ReadOne(f1, log);
                        if ((d1 != null) && (d1.GetEnumType() == ASPTrayBase.eASPtrayType.NormalMessage))
                        {
                            cb((Data_Net__00NormalMessage)d1);
                        }
                    }
                }
            }
        }
コード例 #21
0
        public string SendWhatsApp(NiceSystemInfo niceSystem, string XAPIMobile, string Message, IMyLog log)
        {
            string fileName;

            return(SendWhatsApp(niceSystem, XAPIMobile, Message, false, log, out fileName));
        }
コード例 #22
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());;
        }
コード例 #23
0
 public string Process_MGUseAddTelToFreeAccounts(NiceSystemInfo niceSystem, MobileNoHandler XTelList, IMyLog log)
 {
     return(Process_MGUseAddTelToFreeAccounts(niceSystem, XTelList, 5, log));
 }
コード例 #24
0
 public String GetInfo(NiceSystemInfo niceSystem)
 {
     return(FolderNames.GetFolder(niceSystem, MyFolders.ASP_ServerStateFolder) + " ScreenshotRequest");
 }
コード例 #25
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);
        }
コード例 #26
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());
        }
コード例 #27
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());
        }
コード例 #28
0
 public void AddSystem(NiceSystemInfo systemInfo)
 {
     throw new NotImplementedException();//todo AddSystem
 }
コード例 #29
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // This comes from the TrayApp

        IMyLog          trayLog   = MyLog.GetLogger("TrayApp");
        LogForEmailSend log4Email = new LogForEmailSend(MyLog.GetLogger("Email"));

        try
        {
            // 1) read in incoming object
            //log.Info("incoming msg");
            Data_Net_Tray2ASP fromTray  = new Data_Net_Tray2ASP();
            Stream            streamB64 = Request.InputStream;

            if (streamB64.Length == 0)
            {
                using (DataFile_Loopback ld = new DataFile_Loopback(DataFile_Base.OpenType.ForUpdate_CreateIfNotThere))
                {
                    ld.GetEntry_CreateIfNotThere(NiceSystemInfo.DEFAULT_STR).debugStr = "Zero is nice at " + DateTime.UtcNow.Ticks.ToUkTime(false);
                }
                Response.ContentType = "text/plain";
                Response.Write("Zero is nice!");
                return;
            }

            BinBase64StreamHelper.Tray2ASP_FromB64Stream(ref fromTray, streamB64);
            ASPTray_ObjectList.Counters fromTrayCounter = fromTray.GetCounters();
            if (fromTrayCounter.Total_Results() != 0)
            {
                trayLog.Debug("X " + fromTrayCounter.Total_ResultsString());
            }

            //trayLog.Debug("TrayApp request from " + fromTray.TrayType);
            NiceSystemInfo subSystem = fromTray.TrayType.GetSystemInfoFromTrayType();
            if (subSystem == null)
            {
                using (DataFile_Loopback ld = new DataFile_Loopback(DataFile_Base.OpenType.ForUpdate_CreateIfNotThere))
                {
                    ld.LastError = string.Format("incomming subSystem '{0}' not recognised. {1}",
                                                 fromTray.TrayType,
                                                 DateTime.UtcNow.Ticks.ToUkTime(false));
                }
                throw new SystemException("Unknown System: " + fromTray.TrayType);
            }
            //trayLog.Debug("TrayApp loaded " + subSystem.Name);

            // Update loopback file (with the data from the incoming object)
            using (DataFile_Loopback ld = new DataFile_Loopback(DataFile_Base.OpenType.ForUpdate_CreateIfNotThere))
            {
                DataFile_Loopback_Entry sub = ld.GetEntry_CreateIfNotThere(subSystem.Name);
                sub.lastTrayConnection = DateTime.UtcNow;
                sub.lastTrayId         = fromTrayCounter.Total_ResultsString();
                sub.trayTypeAndIp      = fromTray.TrayType + " - " + Request.UserHostAddress + " - " + (Request.IsSecureConnection ? "https" : "httpONLY");
            }

            // 3) Process each file from the incoming object
            MessageProcessing_TrayFrom proc = new MessageProcessing_TrayFrom(subSystem, onScreenshot, trayLog, log4Email);
            proc.Process_TrayFrom(fromTray, true);

            // 5) prepare the object to be sent
            Data_Net_ASP2Tray toTray = new Data_Net_ASP2Tray();
            DateTime          dtGo   = DateTime.UtcNow.AddSeconds(3);
            while ((toTray.ObjectList.Count == 0) && (dtGo > DateTime.UtcNow))
            {
                // no data yet to send and no timeout
                toTray.ObjectList = MessageProcessing_TrayTo.GetFilesToSendToTray_ConsiderPriority(subSystem, 5, trayLog);
                if (toTray.ObjectList.Count == 0)
                {
                    Thread.Sleep(500);
                }
            }

            // 6) update the loopback file with the sent date
            ASPTray_ObjectList.Counters toTrayCounter = toTray.GetCounters();
            using (DataFile_Loopback ld = new DataFile_Loopback(DataFile_Base.OpenType.ForUpdate_CreateIfNotThere))
            {
                DataFile_Loopback_Entry sub = ld.GetEntry_CreateIfNotThere(subSystem.Name);
                sub.lastToTray     = DateTime.UtcNow;
                sub.lastToTrayData = "FilesToProcess: " + toTrayCounter.Total_RequestsString();
            }

            // 7) send the object to be sent
            //            Response.ContentType = "application/octet-stream";
            Response.ContentType = "text/plain";
            BinBase64StreamHelper.ASP2Tray_ToB64Stream(ref toTray, Response.OutputStream);
        }
        catch (ThreadAbortException)
        {
            trayLog.Debug("ThreadAbortException");
        }
        catch (Exception se)
        {
            trayLog.Error("TrayApp " + se.Message + " " + se.ToString());
            Response.ContentType = "text/plain";
            Response.Write("Exception");
            Response.Write(se.Message);
            Response.Write(se.ToString());
        }
    }
コード例 #30
0
        public string SendWhatsApp(NiceSystemInfo niceSystem, string XAPIMobile, string Message, bool isWelcomeMessage, IMyLog log, out string fileName)
        {
            fileName = "";
            string[] requTelList    = null;
            string   cleanMessage   = null;
            bool     sendFooter     = true;
            bool     deleteOnFailed = false;

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

                if (string.IsNullOrEmpty(XAPIMobile))
                {
                    throw new ArgumentException("X-APIMobile missing");
                }

                requTelList = XAPIMobile.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < requTelList.Length; i++)
                {
                    requTelList[i] = "+" + requTelList[i];
                }

                cleanMessage = Message.Replace(":SE", ":  SE").Replace(": SE", ":  SE");
                if (string.IsNullOrEmpty(cleanMessage))
                {
                    throw new ArgumentException("No POST data");
                }
                #endregion

                // 2 load user file and check guid
                #region 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.IsAccountActive(cleanMessage))
                    {
                        throw new ArgumentException("Account not active (7). " + user.AccountStatusExplained());
                    }
                    if (user.ApiGuId != APIId)
                    {
                        throw new ArgumentException("X-APIId unknown");
                    }
                    #endregion

                    // 3 action
                    user.CommitOrThrow_Send(requTelList, isWelcomeMessage, cleanMessage.Length, ref user.AccountStatus, out sendFooter);
                    deleteOnFailed = user.DeleteOnFailed;
                }, null, null, log);

                // 5) createMessageFile
                bool noCounterUpdate = false;
                if (Message.StartsWith("__NoSend"))
                {
                    noCounterUpdate = true;
                }
                else if (Message == "Welcome\r\n")
                {
                    noCounterUpdate = true;
                }
                else if (Message == "Welcome to NiceApi.net\r\n")
                {
                    noCounterUpdate = true;
                }

                int telNoId = 0;
                foreach (string tel1 in requTelList)
                {
                    fileName +=
                        createMessageFile(
                            niceSystem,
                            telNoId,
                            requTelList[telNoId],
                            cleanMessage,
                            email,
                            timeNow,
                            log,
                            noCounterUpdate,
                            sendFooter,
                            deleteOnFailed ?
                            1 : -1) + ", ";
                    // move on
                    telNoId++;
                }

                if (telNoId == 1)
                {
                    return("queued");
                }
                else
                {
                    return("queued x" + telNoId.ToString());
                }
            }
            catch (ArgumentException ae)
            {
                return(ae.Message);
            }
        }