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); } } }