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); }
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); }
public static Stream ForRead(string path, bool doRetry, bool readAndWrite, IMyLog log) { Stopwatch watch = new Stopwatch(); watch.Start(); Stream r = null; while (r == null) { try { if (readAndWrite) { r = File.Open(path, FileMode.Open, FileAccess.ReadWrite); } else { r = File.OpenRead(path); } } catch (FileNotFoundException) { if (doRetry) { if (watch.ElapsedMilliseconds > 5000) { log.Error(String.Format("ForRead FileNotFoundException looped for 5sec {0}", path)); break; } Thread.Sleep(500); } else { if (!path.Contains("admin_at_niceapi_dot_net")) { log.Error(String.Format("ForRead FileNotFoundException no retry {0}", path)); } break; } } catch (IOException ioe) { if (doRetry) { if (watch.ElapsedMilliseconds > 5000) { log.Error(String.Format("ForRead {1} looped for 5sec {0}", path, ioe.ToString())); break; } Thread.Sleep(500); } else { log.Error(String.Format("ForRead {1} no retry {0}", path, ioe.ToString())); break; } } } return(r); }
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); } }
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); } }
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); } }
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); } }
public static Stream ForWrite(string path, IMyLog log) { Stopwatch watch = new Stopwatch(); watch.Start(); Stream r = null; while (r == null) { try { r = File.Create(path); } catch (IOException) { if (watch.ElapsedMilliseconds > 5000) { log.Error(String.Format("ForWrite failed on {0}", path)); break; } Thread.Sleep(50); } } return(r); }
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 }
/// <summary> /// 创建系统日志 /// </summary> /// <param name="level">级别</param> /// <param name="type">类名,可自定义</param> /// <param name="parasHashtable">自定义参数,目前固定三个{UserId;IP;FunName}</param> /// <param name="message">内容</param> public void Log(MsgLevel level, System.String type, Hashtable parasHashtable, object message) { switch (level) { case MsgLevel.DEBUG: MyLog.Debug(type, parasHashtable, message); break; case MsgLevel.INFO: MyLog.Info(type, parasHashtable, message); break; case MsgLevel.WARN: MyLog.Warn(type, parasHashtable, message); break; case MsgLevel.ERROR: MyLog.Error(type, parasHashtable, message); break; case MsgLevel.FATAL: MyLog.Fatal(type, parasHashtable, message); break; } }
/// <summary> /// 创建系统日志 /// </summary> /// <param name="level">级别</param> /// <param name="type">类名,可自定义</param> /// <param name="parasHashtable">自定义参数,目前固定三个{UserId;IP;FunName}</param> /// <param name="message">内容</param> public void Log(MsgLevel level, System.String type, Hashtable parasHashtable, object message) { switch (level) { case MsgLevel.Debug: MyLog.Debug(type, parasHashtable, message); break; case MsgLevel.Info: MyLog.Info(type, parasHashtable, message); break; case MsgLevel.Warn: MyLog.Warn(type, parasHashtable, message); break; case MsgLevel.Error: MyLog.Error(type, parasHashtable, message); break; case MsgLevel.Fatal: MyLog.Fatal(type, parasHashtable, message); break; } }
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); } }
public void UpdateStatus(string email, Data_AppUserFile.eUserStatus newStatus, IMyLog log) { SqlCmdBuilder cmd = new SqlCmdBuilder(TABLE_NAME); cmd.Add("[AccountStatus]", newStatus.ToIntString()); string strCmd = cmd.GetSql_Update(string.Format("WHERE [Email] like '{0}'", email)); using (SqlDisposable s = new SqlDisposable(Db, strCmd)) { if (s.Reader.RecordsAffected != 1) { log.Error("UpdateAll: *** unexpected RecordsAffected != 1"); } } }
public Student Add(Student student) { try { return(this.studentRepo.Add(student)); } catch (Exception ex) { logger.Error(ex); throw; } }
public void UpdateCounters_Queued(string email, long timeNow, int howMany, IMyLog log) { SqlCmdBuilder cmd = new SqlCmdBuilder(TABLE_NAME); cmd.Add("[LastMsgQueuedUtc]", SqlExtensions.SqlDateUtcNow().ToString()); cmd.AddInc("[NoOfQueuedMessages]", howMany); cmd.AddDec("[RemainingMessages]", howMany); cmd.Add("[AccountStatus]", String.Format("CASE WHEN {0}={1} THEN {2} ELSE {0} END", "[AccountStatus]", Data_AppUserFile.eUserStatus.verified_welcome_No_sent.ToIntString(), Data_AppUserFile.eUserStatus.verified_welcome_queued.ToIntString())); string strCmd = cmd.GetSql_Update(string.Format("WHERE [Email] like '{0}'", email)); using (SqlDisposable s = new SqlDisposable(Db, strCmd)) { if (s.Reader.RecordsAffected != 1) { log.Error("StoreNew: *** unexpected RecordsAffected != 1"); } } }
public void UpdateAll( string email, string userName, string password, string creationIp, string telNumbers, Data_AppUserFile.eUserStatus status, Int32 minDelayInSeconds, Int64 noOfQueuedMessages, Int64 noOfSentMessages, Int64 noOfBytesSent, Int64 remainingMsg, IMyLog log) { SqlCmdBuilder cmd = new SqlCmdBuilder(TABLE_NAME); cmd.Add("[UserName]", userName.Quote()); cmd.Add("[Password]", password.Quote()); cmd.Add("[CreationIp]", creationIp.Quote()); cmd.Add("[MobileNumbers]", telNumbers.Quote()); cmd.Add("[AccountStatus]", status.ToIntString()); cmd.Add("[MinDelayInSeconds]", minDelayInSeconds.ToString()); cmd.Add("[NoOfQueuedMessages]", noOfQueuedMessages.ToString()); cmd.Add("[NoOfSentMessages]", noOfSentMessages.ToString()); cmd.Add("[NoOfBytesSent]", noOfBytesSent.ToString()); cmd.Add("[RemainingMessages]", remainingMsg.ToString()); string strCmd = cmd.GetSql_Update(string.Format("WHERE [Email] like '{0}'", email)); using (SqlDisposable s = new SqlDisposable(Db, strCmd)) { if (s.Reader.RecordsAffected != 1) { log.Error("UpdateAll: *** unexpected RecordsAffected != 1"); } } }
public void StoreNew(Data_AppUserFile data, out bool fileArleadyUsed, IMyLog log) { fileArleadyUsed = false; if (HasAccount(data.Email, log)) { fileArleadyUsed = true; return; } SqlCmdBuilder cmd = new SqlCmdBuilder(TABLE_NAME); cmd.Add("[UserName]", data.UserName.Quote()); cmd.Add("[MobileNumbers]", data.MoblieAllNumbers.Quote()); cmd.Add("[Email]", data.Email.Quote()); cmd.Add("[Password]", data.Password.Quote()); cmd.Add("[CreationDateUtc]", data.CreationDate.SqlDate().ToString()); cmd.Add("[CreationIp]", data.CreationIp.Quote()); cmd.Add("[ApiGuId]", data.ApiGuId.Quote()); cmd.Add("[NoOfQueuedMessages]", data.NoOfQueuedMessages.ToString()); cmd.Add("[NoOfSentMessages]", data.NoOfSentMessages.ToString()); cmd.Add("[NoOfBytesSent]", data.NoOfBytesSent.ToString()); cmd.Add("[RemainingMessages]", data.RemainingMessages.ToString()); cmd.Add("[MinDelayInSeconds]", data.MinDelayInSeconds.ToString()); cmd.Add("[AccountStatus]", data.AccountStatus.ToIntString()); string strCmd = cmd.GetSql_InsertSelect(); //System.Diagnostics.Debug.WriteLine(strCmd);//mg remove using (SqlDisposable s = new SqlDisposable(Db, strCmd)) { if (s.Reader.RecordsAffected != 1) { log.Error("StoreNew: *** unexpected RecordsAffected != 1"); } } }
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()); } }
protected void Page_Load(object sender, EventArgs e) { // This comes from the Android direct IMyLog trayLog = MyLog.GetLogger("TrayApp"); trayLog.Info("Incoming 17:00"); string inBody = "notSet"; try { LogForEmailSend log4Email = new LogForEmailSend(MyLog.GetLogger("Email")); Stream inStream = Request.InputStream; if (inStream.Length == 0) { Response.ContentType = "text/plain"; Response.Write("DirectTel: Zero!"); return; } DirectTel_InJson inJson = null; using (var sr = new StreamReader(inStream)) { inBody = sr.ReadToEnd(); inJson = JsonConvert.DeserializeObject <DirectTel_InJson>(inBody); } trayLog.Debug("In Json: "); trayLog.Debug(JsonConvert.SerializeObject(inJson)); DirectTel_OutJson outJson = DirectTel_Processing.ProcessDirectTel(inJson, trayLog, log4Email, delegate(NiceSystemInfo subSystem) { //OnGet // 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.lastDirectTelGet = DateTime.UtcNow; } }, delegate(NiceSystemInfo subSystem) { //OnAck // 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.lastDirectTelAck = DateTime.UtcNow; } }); trayLog.Debug("Out Json: "); trayLog.Debug(JsonConvert.SerializeObject(outJson)); Tx(outJson); } catch (ThreadAbortException) { trayLog.Debug("ThreadAbortException"); } catch (Exception se) { trayLog.Error("DirectTel " + se.Message + " " + se.ToString()); trayLog.Error("DirectTel " + inBody); Response.ContentType = "text/plain"; Response.Write("Exception"); Response.Write(se.Message); Response.Write(se.ToString()); } }