Beispiel #1
0
        public void SessionChange(HostControl hostControl, SessionChangedArguments args)
        {
            var sid  = (uint)args.SessionId;
            var kind = Kind.Unknown;

            switch (args.ReasonCode)
            {
            // Kind.Active to store latest active time span when user ends work
            case SessionChangeReasonCode.ConsoleDisconnect:
            case SessionChangeReasonCode.RemoteDisconnect:
            case SessionChangeReasonCode.SessionLock:
            case SessionChangeReasonCode.SessionLogoff:
                kind = Kind.Active;
                break;

            // Kind.Connected to reset Accounter and start watching for user time since connected state
            case SessionChangeReasonCode.ConsoleConnect:
            case SessionChangeReasonCode.RemoteConnect:
            case SessionChangeReasonCode.SessionLogon:
            case SessionChangeReasonCode.SessionUnlock:
                kind = Kind.Connected;
                break;
            }
            if (kind != Kind.Unknown)
            {
                _accounter.Changed(new SessionData(sid, kind, this)
                {
                    User = SessionInformation.GetUsernameBySessionId(sid, false)
                });
            }
        }
Beispiel #2
0
        public void Add(SessionData data)
        {
            var quit = data.Spent == TimeSpan.Zero;

            if (data.Reason == Kind.Locked)
            {
                quit |= LogOnce(_marker, "loggerLocked", () => Log.TraceFormat("session is locked, ignoring. sender:{0}", data.Sender));
            }
            if (data.Reason == Kind.Connected)
            {
                quit |= true;
                Log.TraceFormat("session was connected, ignoring. sender:{0}", data.Sender);
            }

            if (!quit && data.User.IsEmpty())
            {
                data.User = SessionInformation.GetUsernameBySessionId(data.SessionID, false);
            }

            if ("SYSTEM".Equals(data.User, StringComparison.OrdinalIgnoreCase) || data.User.IsEmpty())
            {
                quit |= LogOnce(_marker, "systemLocked", () => Log.TraceFormat("no user data (system), ignoring. sender:{0}", data.Sender));
            }

            if (quit)
            {
                return;
            }

            _marker.Clear();
            if (data.Reason != Kind.Active)             // like Connected
            {
                Log.DebugFormat("adding session data reason:{0} spent:{1}", data.Reason, data.Spent);
            }
            _items.Enqueue(data);
        }