Exemplo n.º 1
0
        public static void Init()
        {
            CacheTimer = new System.Windows.Forms.Timer
            {
                Enabled  = false,
                Interval = 30
            };

            Globals.WinEventQueue   = new Queue <BusinessObjects.WinEventProcesss>();
            Globals.FileChangeQueue = new Queue <FileChange>();
            Globals.SyncLockObject  = new DummyLockObject();
            Globals.FilesLockObject = new DummyLockObject();

            // Load cached data which is expected to be in memory for fast access
            SetupCachedDatabaseData();

            // start up window change event tracking
            var o = Globals.ConfigOptions.Find(x => x.Name == AppWrapper.AppWrapper.WindowTypeEvents);

            Globals.WinEventType = int.Parse(o.Value) == 0 ? AppWrapper.AppWrapper.WindowEventType.EventHook : AppWrapper.AppWrapper.WindowEventType.Polling;

            if (Globals.WinEventType == AppWrapper.AppWrapper.WindowEventType.EventHook)
            {
                Globals.WindowChangeEventHandler = new WindowChangeEvents();
            }
            else
            {
                Globals.WindowChangeEventHandler = new WindowChangeEvents(true);
                WindowPolling.StartPolling();
            }

            // dont start filewatcher until window watcher is running
            Globals.FileWatchr = new FileWatcher();
        }
Exemplo n.º 2
0
 public static void ShutDown()
 {
     CacheTimer.Stop();
     CacheTimer.Enabled = false;
     CacheTimer.Dispose();
     Globals.WindowChangeEventHandler.Dispose();
     //Globals.workLock.Dispose();
     Globals.FileWatchr.Dispose();
     WindowPolling.SuspendWindowPolling();
     WindowPolling.Timer.Dispose();
 }
Exemplo n.º 3
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.º 4
0
        private void Locked()
        {
            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 Classes.CheckForProjectName();
            Tuple <string, IDEMatch, bool, string> cfpObject = cfp.GetProjectName(Globals.LastWindowEvent.WindowTitle, accessDenied, Globals.LastWindowEvent.AppName, writeDB);
            string devProjectName = cfpObject.Item1;

            writeDB        = cfpObject.Item3;
            ideMatchObject = cfpObject.Item2;

            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
#if DEBUG
                Console.WriteLine($"     ** Locked Writing Time: {LockStartTime} AppName: {Globals.LastWindowEvent.AppName} Title: {Globals.LastWindowEvent.WindowTitle} Project: {Globals.LastWindowEvent.DevProjectName}");
#endif
                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;
            }
        }