Exemplo n.º 1
0
        private void Unlocked()
        {
            LockEndTime = DateTime.Now;
            //_locked = false;
            //_lastWinState = WinEvntState.Unknown;
            TimeSpan lockedInterval = LockEndTime - LockStartTime;

#if DEBUG
            Console.WriteLine($"     ** UnLocked Writing Time: {LockEndTime} AppName: {Globals.LastWindowEvent.AppName} Title: {Globals.LastWindowEvent.WindowTitle} Project: {Globals.LastWindowEvent.DevProjectName}");
#endif

            var hlpr = new DHWindowEvents(AppWrapper.AppWrapper.DevTrkrConnectionString);
            lock (Globals.SyncLockObject)
            {
                Globals.LastWindowEvent.EndTime = LockEndTime;
                var row = hlpr.InsertWindowEvent(Globals.LastWindowEvent);

                //next, create a new LastWindowEvent
                // 2) create a locked window event in database
                string displayName;
                try
                {
                    displayName = UserPrincipal.Current.DisplayName;
                }
                catch (Exception ex)
                {
                    displayName = Environment.UserName;
                }
                var item = new WindowEvent
                {
                    ID          = Guid.NewGuid().ToString(),
                    StartTime   = LockStartTime,
                    WindowTitle = AppWrapper.AppWrapper.AppName,
                    AppName     = AppWrapper.AppWrapper.AppName,
                    ModuleName  = AppWrapper.AppWrapper.AppName,
                    //EndTime = LockEndTime,
                    DevProjectName  = AppWrapper.AppWrapper.AppName,
                    ITProjectID     = string.Empty,
                    UserName        = Environment.UserName,
                    MachineName     = Environment.MachineName,
                    UserDisplayName = displayName
                };
                Globals.LastWindowEvent = item;
                //var rows = hlpr.InsertWindowEvent(item);
            }
            WindowPolling.ResumeWindowPolling();
        }
Exemplo n.º 2
0
        private void Locked()
        {
            LockStartTime = DateTime.Now;
            var      accessDenied   = false;
            var      _currentApp    = Globals.LastWindowEvent.AppName;
            IDEMatch ideMatchObject = null;
            bool     writeDB        = false;

            //_locked = true;

            // turn off polling while locked, so we will not see any window change while locked
            // therefore LastWindowEvent should be the one created below when we detect unlock
            WindowPolling.SuspendWindowPolling();

            // Try to get the project name for the Globals.LastWindowEvent
            var cfp = new CheckForProjectName();
            Tuple <string, IDEMatch, bool, string> cfpObject = cfp.GetProjectName(Globals.LastWindowEvent.WindowTitle, accessDenied, Globals.LastWindowEvent.AppName, writeDB);
            string devProjectName = cfpObject.Item1;

            ideMatchObject = cfpObject.Item2;
            writeDB        = cfpObject.Item3;
            if (string.IsNullOrWhiteSpace(Globals.LastWindowEvent.DevProjectName))
            {
                Globals.LastWindowEvent.DevProjectName = devProjectName;
            }

            var hlpr = new DHWindowEvents(AppWrapper.AppWrapper.DevTrkrConnectionString);

            lock (Globals.SyncLockObject)
            {
                // now, make it look like the current window when the lock occurs is being moved away from
                // by writing it to database
                Globals.LastWindowEvent.EndTime = LockStartTime;
                hlpr.InsertWindowEvent(Globals.LastWindowEvent);

                // next, start a new LastWindowEvent called ComputerLocked
                // and put it in Globals.LastWindowEvent
                string displayName;
                try
                {
                    displayName = UserPrincipal.Current.DisplayName;
                }
                catch (Exception ex)
                {
                    displayName = Environment.UserName;
                }

                var item = new WindowEvent
                {
                    ID              = Guid.NewGuid().ToString(),
                    StartTime       = LockStartTime,
                    WindowTitle     = locked,
                    AppName         = locked,
                    ModuleName      = locked,
                    EndTime         = LockEndTime,
                    DevProjectName  = locked,
                    ITProjectID     = string.Empty,
                    UserName        = Environment.UserName,
                    MachineName     = Environment.MachineName,
                    UserDisplayName = displayName
                };
                Globals.LastWindowEvent = item;
            }
        }