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()); }
public void ExchangeDataWithServer(I2_InfoDisplay d, I6_WhatsAppProcess p) { toASP.TrayType = "_3GetData.Server.TrayType".GetConfig(); ASPTray_ObjectList.Counters toASPCount = toASP.GetCounters(); if (toASPCount.Total_Results() > 0) { d.FileLog_Info(toASPCount.Total_ResultsString() + " up msg"); } d.AddLine(toASPCount.Total_ResultsString() + " up msg (b64)"); d.AddLine2(toASPCount.AddLineIFace_Send()); d.AddLine("ExchangeDataWithServer dummy"); }
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()); } }
public bool DoWeHaveDataToSend() { ASPTray_ObjectList.Counters c = toASP.GetCounters(); return(c.Total_Results() != 0); }