Example #1
0
        public void Process_TrayFrom(Data_Net_Tray2ASP fromTray, bool sendEmails)
        {
            // Process each file from the incoming object
            foreach (ASPTrayBase o1 in fromTray.ObjectList)
            {
                try
                {
                    ASPTrayBase.eASPtrayType e1 = o1.GetEnumType();
                    switch (e1)
                    {
                    case ASPTrayBase.eASPtrayType.NormalMessageResult:
                        processNormalMessageResult((Data_Net__01NormalMessageResult)o1);
                        break;

                    case ASPTrayBase.eASPtrayType.ScreenShotResult:
                        processScreenShotResult((Data_Net__03ScreenshotResult)o1);
                        break;

                    case ASPTrayBase.eASPtrayType.CheckTelNumbersResult:
                        processCheckTelNumbersResult((Data_Net__05CheckTelNumbersResult)o1, sendEmails);
                        break;

                    default:
                        throw new IOException("Unknown file type in TrayApp response");
                    }
                }
                catch (SystemException se)
                {
                    trayLog.Error("Incoming file processing: Exception: " + se.Message + " " + se.ToString());
                }
            } // end of foreach
        }
Example #2
0
        public void ExchangeDataWithServer(I2_InfoDisplay d, I6_WhatsAppProcess p)
        {
            string url = p.Debug_AmendUrl(FolderNames.GetUrl(this.urlToUse), toASP.GetCounters().Total_ResultsString());

            toASP   = new Data_Net_Tray2ASP();
            fromASP = new Data_Net_ASP2Tray();
        }
Example #3
0
        public void ExchangeDataWithServer(I2_InfoDisplay d, I6_WhatsAppProcess p)
        {
            d.AddLine("exchangeDataWithASP");
            d.FileLog_Debug("exchangeDataWithASP");

            toASP.TrayType = ConfigurationManager.AppSettings["_3GetData.Server.TrayType"];
            d.AddLine2(new DetailedData_TypeAndAndroidEP()
            {
                TrayType = toASP.TrayType
            });
            d.AddLine2(new DetailedData_TypeAndAndroidEP()
            {
                LocalIPAddress = Extensions.GetLocalIPAddress()
            });

            if (String.IsNullOrEmpty(toASP.TrayType))
            {
                throw new ConfigurationException("_3GetData.Server.TrayType is missing!");
            }
            ASPTray_ObjectList.Counters toASPCount = toASP.GetCounters();
            if (toASPCount.Total_Results() > 0)
            {
                d.FileLog_Info(toASPCount.Total_ResultsString() + " up msg");
            }
            d.AddLine2(toASPCount.AddLineIFace_Send());

            string         url     = p.Debug_AmendUrl(FolderNames.GetUrl(this.urlToUse), toASP.GetCounters().Total_ResultsString());
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.ReadWriteTimeout = FolderNames.GetValue(MyValues.Tray_TcpTimeoutSec) * 1000;
            request.Method           = "POST";
            request.ContentType      = "application/x-www-form-urlencoded";
            Stream requestStream = request.GetRequestStream();

            BinBase64StreamHelper.Tray2ASP_ToB64Stream(ref toASP, requestStream);
            requestStream.Close();

            // GET RESPONSE ****************************************************
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            d.AddLine("GetResponse done");
            toASP   = new Data_Net_Tray2ASP();
            fromASP = new Data_Net_ASP2Tray();
            Stream stream = response.GetResponseStream();

            BinBase64StreamHelper.ASP2Tray_FromB64Stream(ref fromASP, stream);
            response.Close();
            ASPTray_ObjectList.Counters fromASPCount = fromASP.GetCounters();
            if (fromASPCount.Total_Requests() > 0)
            {
                d.FileLog_Info(fromASPCount.Total_RequestsString() + " down msg");
            }
            d.AddLine2(fromASPCount.AddLineIFace_Receive());
        }
Example #4
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());
        }
    }
Example #5
0
 public void Reset_toASP()
 {
     this.toASP = new Data_Net_Tray2ASP();
 }
Example #6
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);
        }