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
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
 void SessionSwitchMonitor_SessionSwitch(int sessionId, SessionSwitchReason reason)
 {
     if (reason == SessionSwitchReason.SessionLock ||
         reason == SessionSwitchReason.SessionLogoff ||
         reason == SessionSwitchReason.SessionLogon ||
         reason == SessionSwitchReason.SessionUnlock)
     {
         _tcs.SetResult(new object());
     }
 }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 8
0
        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();
                }
            }
        }
Exemplo n.º 9
0
        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;
                }
            }
        }
Exemplo n.º 11
0
        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;
            }
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 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;
            }
        }
Exemplo n.º 15
0
        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;
            }
        }
Exemplo n.º 16
0
 private void SendMessage(SessionSwitchReason reason)
 {
     SendMessage(User32.WM_WTSSESSION_CHANGE, (IntPtr)reason, IntPtr.Zero);
 }
Exemplo n.º 17
0
 public EventEntry(DateTime date, SessionSwitchReason event_type)
 {
     this.date = date; this.event_type = event_type;
 }
Exemplo n.º 18
0
 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");
 }
Exemplo n.º 20
0
 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)
 {
 }
Exemplo n.º 23
0
 public SessionSwitchedArgs(bool showDialog, SessionSwitchReason reason)
 {
     ShowDialog = showDialog;
     Reason = reason;
 }
Exemplo n.º 24
0
 protected virtual void TimerStart(SessionSwitchEventArgs e)
 {
     this._reason = e.Reason;
     TimerStart();
 }
Exemplo n.º 25
0
 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;
 }
Exemplo n.º 27
0
 public ApplicationSessionChangedArguments(SessionSwitchReason reason)
 {
     ReasonCode = (SessionChangeReasonCode)Enum.ToObject(typeof(SessionChangeReasonCode), (int)reason);
     SessionId  = Process.GetCurrentProcess().SessionId;
 }
Exemplo n.º 28
0
 private void RaiseSessionSwitch(SessionSwitchReason reason, int count) =>
 _onSessionSwitch?.Invoke(new SessionSwitchCountEventArgs(reason, count));
Exemplo n.º 29
0
 // Constructors
 public SessionSwitchEventArgs(SessionSwitchReason reason)
 {
 }
Exemplo n.º 30
0
 public SessionSwitchEventArgs(SessionSwitchReason reason)
 {
     this.reason = reason;
 }
Exemplo n.º 31
0
 public SessionSwitchEventArgs(SessionSwitchReason reason)
 {
     throw new NotImplementedException();
 }