public static void RunPipeClient() { MainScreenRedir MR = new MainScreenRedir(ProgramAgent.PipeGUID); MR.StartPipe(); LastCalled = DateTime.Now; do { if (LastCalled != null) { if ((DateTime.Now - LastCalled.Value).TotalMinutes > 10) { Timeout = true; } } Thread.Sleep(1000); } while (Timeout == false); Thread.Sleep(1000); }
static bool CheckConnection() { if (LastCalled != null) { if ((DateTime.Now - LastCalled.Value).TotalMinutes > 9) //timeout { LastCalled = null; } } if (LastCalled == null) { LastCalled = DateTime.Now; CurrentConsoleSessionID = -1; CurrentConnectionGUID = ""; } else { LastCalled = DateTime.Now; } lock (CheckConnectionLocker) { FullReset: Int64 Con = ProgramAgent.CPP.GetConsoleSessionID(); if (CurrentConsoleSessionID != Con) { if (CurrentConnectionGUID != "") { FoxEventLog.VerboseWriteEventLog("Console Session ID changed from " + CurrentConsoleSessionID.ToString() + " to " + Con.ToString() + " - Closing Pipe #" + CurrentConnectionGUID, EventLogEntryType.Information); try { if (Pipe != null) { Pipe.Pipe1.CloseSession(); } Pipe = null; } catch { } CurrentConnectionGUID = ""; } } CurrentConsoleSessionID = Con; if (CurrentConnectionGUID == "") { CurrentConnectionGUID = Guid.NewGuid().ToString(); FoxEventLog.VerboseWriteEventLog("Starting Screen Capture for Session ID " + CurrentConsoleSessionID.ToString() + " Pipe #" + CurrentConnectionGUID, EventLogEntryType.Information); if (StartApp(CurrentConnectionGUID, out PipeProcessID) == false) { return(false); } Pipe = new MainScreenRedir(CurrentConnectionGUID); Pipe.Pipe1 = new PipeScreenDataComm(CurrentConnectionGUID); Pipe.Pipe2 = new PipeScreenDataComm(CurrentConnectionGUID); } int Counter = 0; bool Connected = false; do { if (ProcessExists(PipeProcessID) == false) { FoxEventLog.VerboseWriteEventLog("Screen Capture Process ID " + PipeProcessID.ToString() + " for Session ID " + CurrentConsoleSessionID.ToString() + " Pipe #" + CurrentConnectionGUID + " gone", EventLogEntryType.Warning); Connected = false; if (ProgramAgent.CPP.GetConsoleSessionID() != CurrentConsoleSessionID) { goto FullReset; } break; } try { if (Pipe.Pipe1.Ping() == true) { Connected = true; break; } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } Thread.Sleep(100); Counter++; if (Counter > 10 * 30) { break; } Pipe.Pipe1 = new PipeScreenDataComm(CurrentConnectionGUID); Pipe.Pipe2 = new PipeScreenDataComm(CurrentConnectionGUID); } while (true); if (Connected == false) { //Restart the app CurrentConnectionGUID = Guid.NewGuid().ToString(); FoxEventLog.VerboseWriteEventLog("Starting Screen Capture for Session ID " + CurrentConsoleSessionID.ToString() + " (2nd try!) Pipe #" + CurrentConnectionGUID, EventLogEntryType.Information); if (StartApp(CurrentConnectionGUID, out PipeProcessID) == false) { return(false); } Pipe = new MainScreenRedir(CurrentConnectionGUID); Pipe.Pipe1 = new PipeScreenDataComm(CurrentConnectionGUID); Pipe.Pipe2 = new PipeScreenDataComm(CurrentConnectionGUID); Connected = false; do { if (ProcessExists(PipeProcessID) == false) { FoxEventLog.VerboseWriteEventLog("Screen Capture Process ID " + PipeProcessID.ToString() + " for Session ID " + CurrentConsoleSessionID.ToString() + " Pipe #" + CurrentConnectionGUID + " gone", EventLogEntryType.Warning); Connected = false; if (ProgramAgent.CPP.GetConsoleSessionID() != CurrentConsoleSessionID) { goto FullReset; } break; } try { if (Pipe.Pipe1.Ping() == true) { Connected = true; break; } } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } Thread.Sleep(100); Counter++; if (Counter > 10 * 30) { break; } Pipe.Pipe1 = new PipeScreenDataComm(CurrentConnectionGUID); Pipe.Pipe2 = new PipeScreenDataComm(CurrentConnectionGUID); } while (true); if (Connected == false) { FoxEventLog.WriteEventLog("Starting Screen Capture for Session ID " + CurrentConsoleSessionID.ToString() + " failed!", EventLogEntryType.Error); CurrentConnectionGUID = ""; return(false); } } return(true); } }