//private void CloseNotify(int sessionId) //{ // var process = Process.GetProcesses().FirstOrDefault(p => p.SessionId == sessionId && p.ProcessName == "csrss"); // if(process != null) // { // this.Log.WriteLine($"Close window of ({process.Id})"); // try // { // SafeUserApi.Close(process.MainWindowHandle); // } // catch (Exception ex) // { // this.Log.WriteLine($"Exception {ex.Message}"); // } // } //} private void Notify(int sessionId, Level level) { try { var textInfo = $"Connection reopened at {DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ffffff")}"; var textWarn = $"Connection broken at {DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ffffff")}"; var caption = $"{Process.GetCurrentProcess().ProcessName}"; var code = 0; switch (level) { case Level.Information: this.Log.WriteLine($"Notify information to session ({sessionId})"); code = ServiceNotifyDialog.ShowWTSMessageBox(sessionId, textInfo, caption, ServiceNotifyDialog.IconStyle.Information); break; case Level.Warning: this.Log.WriteLine($"Notify warning to session ({sessionId})"); code = ServiceNotifyDialog.ShowWTSMessageBox(sessionId, textWarn, caption, ServiceNotifyDialog.IconStyle.Warining); break; default: break; } if (code != 0) { this.Log.WriteLine($"Win32Error {code}"); } } catch (Exception ex) { this.Log.WriteLine(ex.ToString()); } }
public ConnectionWatcher(Log log) { this.Log = log; this.StopWatch = new Stopwatch(); this.Connection = new MockConnection(this.Log); this.CancellationTokenSource = new CancellationTokenSource(); this.Dialog = new ServiceNotifyDialog(); this.SessionId = Session.GetCurrentSessionId(); }