public void OutOfRange() { SessionSwitchReason ssr = (SessionSwitchReason)Int32.MinValue; SessionSwitchEventArgs ssea = new SessionSwitchEventArgs(ssr); Assert.AreEqual(ssr, ssea.Reason, "Int32.MinValue"); // no validation is done on the enum value used }
public void BreakPeriodStopped_ForCorrectSystemEvents(SessionSwitchReason reason) { // Act var sessionSwitchEventArgs = new SessionSwitchEventArgs(reason); _MockSystemEvents.Raise(m => m.SessionSwitch += null, null, sessionSwitchEventArgs); // Verify _MockPeriodBetweenBreaks.Verify(m => m.Stop(), Times.Once()); }
void SessionSwitchMonitor_SessionSwitch(int sessionId, SessionSwitchReason reason) { if (reason == SessionSwitchReason.SessionLock || reason == SessionSwitchReason.SessionLogoff || reason == SessionSwitchReason.SessionLogon || reason == SessionSwitchReason.SessionUnlock) { _tcs.SetResult(new object()); } }
/// <summary>Handle the event to log</summary> /// <param name="source"></param> /// <param name="state"></param> /// <param name="includeInformationModel"></param> private void HandleEvent(string source, SessionSwitchReason state, bool includeInformationModel) { //make and Write the log entry string line = string.Format("{0} ({1}) - Git:{2}", state, source, GitRepositoryCurrentBranch()); if (includeInformationModel) { line += " " + JsonConvert.SerializeObject(new InformationModel()); } StorageFileManager.Write(line); }
public void BreakTakenEventInvoked_WhenSystemEventsOccur(SessionSwitchReason reason) { // Arrange var mockHandler = new Mock<BreakTakenEventHandler>(); _SessionTimer.BreakTaken += mockHandler.Object; // Act var sessionSwitchEventArgs = new SessionSwitchEventArgs(reason); _MockSystemEvents.Raise(m => m.SessionSwitch += null, null, sessionSwitchEventArgs); // Verify mockHandler.Verify(m => m(_SessionTimer, It.IsAny<EventArgs>()), Times.Once()); }
private void SetUserState(SessionSwitchReason newState) { string key = StorageFileManager.GetLoginUserName(); SessionSwitchReason val; if (_userState.TryGetValue(key, out val)) { _userState[key] = newState; } else { _userState.Add(key, newState); } }
async void SessionSwitchMonitor_SessionSwitch(int sessionId, SessionSwitchReason reason) { bool isLock = false; bool isUnlock = false; WorkstationEventType eventType; switch (reason) { case SessionSwitchReason.SessionLock: eventType = WorkstationEventType.ComputerLock; isLock = true; break; case SessionSwitchReason.SessionLogoff: eventType = WorkstationEventType.ComputerLogoff; isLock = true; break; case SessionSwitchReason.SessionUnlock: eventType = WorkstationEventType.ComputerUnlock; isUnlock = true; break; case SessionSwitchReason.SessionLogon: eventType = WorkstationEventType.ComputerLogon; isUnlock = true; break; default: return; // Ignore all events except lock/unlock and logoff/logon } try { if (isLock) { await OnWorkstationLock(sessionId, eventType); } else if (isUnlock) { await OnWorkstationUnlock(sessionId, eventType); } } catch (Exception ex) { WriteLine(ex); } }
public static void Insert(DateTime time, SessionSwitchReason reason, string user) { var queryString = string.Format(@"INSERT INTO LOG (Time, Type, User) VALUES (""{0}"", {1}, ""{2}""); ", time.ToString("dd.MM.yyyy HH:mm:ss"), (int)reason, user); using (var sqlite = new SQLiteConnection(CS)) { using (var command = new SQLiteCommand(queryString, sqlite)) { command.Connection.Open(); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } } }
private static void OnSessionSwitch(SessionSwitchReason reason) { try { var time = DateTime.Now; var user = WindowsIdentity.GetCurrent().Name; DBProvider.Insert(time, reason, user); } catch (Exception ex) { Logger.Log(ex); } }
void SessionSwitchMonitor_SessionSwitch(int sessionId, SessionSwitchReason reason) { if (_isRunning) { switch (reason) { case SessionSwitchReason.SessionLogon: case SessionSwitchReason.SessionUnlock: GenerateAndSaveUnlockToken(); break; default: break; } } }
void SessionSwitchMonitor_SessionSwitch(int sessionId, SessionSwitchReason reason) { switch (reason) { case SessionSwitchReason.SessionLock: case SessionSwitchReason.SessionLogoff: WriteLine($"Session state changed to: locked (reason: {reason});"); ClearSessionId(); break; case SessionSwitchReason.SessionLogon: case SessionSwitchReason.SessionUnlock: WriteLine($"Session state changed to: unlocked (reason: {reason});"); GenerateNewSessionId(); break; } }
public static void store(SessionSwitchReason reason, DateTime now) { List <Monitoring> ret = read(); if (ret == null || ret.Count == 0) { ret = new List <Monitoring>(); Monitoring x = new Monitoring() { Day = DateTime.Now.Date, Items = new List <MonitoringItem>() }; x.Items.Add(new MonitoringItem() { State = reason, When = now }); ret.Add(x); } else { Monitoring x = ret.Where(c => c.Day == DateTime.Now.Date).FirstOrDefault(); if (x == null) { x = new Monitoring() { Day = DateTime.Now.Date, Items = new List <MonitoringItem>() }; x.Items.Add(new MonitoringItem() { State = reason, When = now }); ret.Add(x); } else { x.Items.Add(new MonitoringItem() { State = reason, When = now }); } } write(ret); }
public static void SessionSwitchHandler(object sender, SessionSwitchEventArgs evt) { if (evt.Reason == SessionSwitchReason.ConsoleDisconnect) { Logger.Debug("Detected a disconnect from the console"); UserLocalSession = false; UserSessionSwitch(false); } else if (evt.Reason == SessionSwitchReason.ConsoleConnect) { Logger.Debug("Detected a connect to the console"); if (!UserLocalSession) { Logger.Debug("Session state switched to local"); UserLocalSession = true; UserSessionSwitch(true); } } LastSessionSwitchReason = evt.Reason; }
void SessionSwitchMonitor_SessionSwitch(int sessionId, SessionSwitchReason reason) { switch (reason) { case SessionSwitchReason.SessionLock: case SessionSwitchReason.SessionLogoff: ClearSavedTimestamp(); _timestampSaveTimer.Stop(); break; case SessionSwitchReason.SessionUnlock: case SessionSwitchReason.SessionLogon: _timestampSaveTimer.Stop(); var ts = CreateNewTimestamp(); // A workaround for race condition and incorrect order with unlock events on fast shutdown ts.Time = ts.Time + TimeSpan.FromSeconds(30); SaveOrUpdateTimestamp(ts); _timestampSaveTimer.Start(); break; default: return; } }
public void SignalsSessionSwitch(SessionSwitchReason reason) { bool signaled = false; SessionSwitchEventArgs args = null; SessionSwitchEventHandler switchHandler = (o, e) => { signaled = true; args = e; }; SystemEvents.SessionSwitch += switchHandler; try { SendMessage(reason); Assert.True(signaled); Assert.NotNull(args); Assert.Equal(reason, args.Reason); } finally { SystemEvents.SessionSwitch -= switchHandler; } }
private void SendMessage(SessionSwitchReason reason) { SendMessage(User32.WM_WTSSESSION_CHANGE, (IntPtr)reason, IntPtr.Zero); }
public EventEntry(DateTime date, SessionSwitchReason event_type) { this.date = date; this.event_type = event_type; }
public ConsoleSessionChangedArguments(SessionSwitchReason reason) { _reasonCode = (SessionChangeReasonCode)Enum.ToObject(typeof(SessionChangeReasonCode), (int)reason); _sessionId = Process.GetCurrentProcess().SessionId; }
void SessionSwitchMonitor_SessionSwitch(int sessionId, SessionSwitchReason reason) { // Cancel the workflow if session switches to an unlocked (or different one) // Keep in mind, that workflow can cancel itself due to successful workstation unlock Cancel("Session switched"); }
public static void SystemSessionSwitch(int sessionId, SessionSwitchReason reason) { SessionSwitch?.Invoke(sessionId, reason); }
/// <devdoc> /// <para>Initializes a new instance of the <see cref='Microsoft.Win32.SessionSwitchEventArgs'/> class.</para> /// </devdoc> public SessionSwitchEventArgs(SessionSwitchReason reason) { this.reason = reason; }
public SessionSwitchEventArgs(SessionSwitchReason reason) { }
public SessionSwitchedArgs(bool showDialog, SessionSwitchReason reason) { ShowDialog = showDialog; Reason = reason; }
protected virtual void TimerStart(SessionSwitchEventArgs e) { this._reason = e.Reason; TimerStart(); }
public ConsoleSessionChangedArguments(SessionSwitchReason reason) { _reasonCode = (SessionChangeReasonCode)Enum.ToObject(typeof(SessionChangeReasonCode), (int)reason); _sessionId = Process.GetCurrentProcess().SessionId; }
public SessionSwitchMessage(int sessionId, SessionSwitchReason reason) { SessionId = sessionId; Reason = reason; }
public ApplicationSessionChangedArguments(SessionSwitchReason reason) { ReasonCode = (SessionChangeReasonCode)Enum.ToObject(typeof(SessionChangeReasonCode), (int)reason); SessionId = Process.GetCurrentProcess().SessionId; }
private void RaiseSessionSwitch(SessionSwitchReason reason, int count) => _onSessionSwitch?.Invoke(new SessionSwitchCountEventArgs(reason, count));
// Constructors public SessionSwitchEventArgs(SessionSwitchReason reason) { }
public SessionSwitchEventArgs(SessionSwitchReason reason) { this.reason = reason; }
public SessionSwitchEventArgs(SessionSwitchReason reason) { throw new NotImplementedException(); }