public ASPTrayBase To_MessageFile() { if (doScreenshot) { throw new NotImplementedException(); } else if (alreadyFormated != null) { return(alreadyFormated); } else { // // normal case Data_Net__00NormalMessage _0 = new Data_Net__00NormalMessage("*****@*****.**", "zapi_+" + tel, DateTime.UtcNow.Ticks, msg, 0, -1, false); return(_0); // f1.DestMobile = "zapi_+" + tel; } //return null; }
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); }
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); } } }
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()); }
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); } } }
private static int ComparisonWithPriority(ASPTrayBase x, ASPTrayBase y) { int ret = 0; if (ret == 0) { // consider file priority ret = (int)x.GetFilePriority() - (int)y.GetFilePriority(); } if ((ret == 0) && (x.GetType() != y.GetType())) { Data_Net__00NormalMessage n = null; Data_Net__04CheckTelNumbers t = null; if ((x.GetType() == typeof(Data_Net__00NormalMessage)) && (y.GetType() == typeof(Data_Net__04CheckTelNumbers))) { n = (Data_Net__00NormalMessage)x; t = (Data_Net__04CheckTelNumbers)y; if (t.GetFailedCount() > 5) { ret = 1; } else { ret = -1; } } if ((y.GetType() == typeof(Data_Net__00NormalMessage)) && (x.GetType() == typeof(Data_Net__04CheckTelNumbers))) { n = (Data_Net__00NormalMessage)y; t = (Data_Net__04CheckTelNumbers)x; if (t.GetFailedCount() > 5) { ret = -1; } else { ret = 1; } } } if (ret == 0) { // consider failed counter ret = x.GetFailedCount() - y.GetFailedCount(); } if (ret == 0) { // consider file time if ( (x.GetEnumType() == ASPTrayBase.eASPtrayType.NormalMessage) && (y.GetEnumType() == ASPTrayBase.eASPtrayType.NormalMessage)) { Data_Net__00NormalMessage xn = (Data_Net__00NormalMessage)x; Data_Net__00NormalMessage yn = (Data_Net__00NormalMessage)y; if (ret == 0) { // compare the FailedConter ret = xn.FailedCounter - yn.FailedCounter; } if (ret == 0) { // older message first ret = (int)(xn.MsgTicks - yn.MsgTicks); } } if ( (x.GetEnumType() == ASPTrayBase.eASPtrayType.CheckTelNumbers) && (y.GetEnumType() == ASPTrayBase.eASPtrayType.CheckTelNumbers)) { Data_Net__04CheckTelNumbers xt = (Data_Net__04CheckTelNumbers)x; Data_Net__04CheckTelNumbers yt = (Data_Net__04CheckTelNumbers)y; if (ret == 0) { // compare the FailedConter ret = xt.GetFailedCount() - yt.GetFailedCount(); } if (ret == 0) { // older message first ret = (int)(xt.MsgTicks - yt.MsgTicks); } } } return(ret); }