예제 #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            TrackingDataContext trackingDataContext = new TrackingDataContext();
            MouseTracker        mouseTracker        = new MouseTracker();
            KeyboardTracker     keyboardTracker     = new KeyboardTracker();


            //Set timer to record activity data every second
            DispatcherTimer timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(1000)
            };

            //Start tracking productivity and logging it
            timer.Tick += (o, e) =>
            {
                var newTrackingRecord = new TrackingRecord
                {
                    Active      = false,
                    ProcessName = ProcessTracker.GetActiveProcessName(),
                    Timestamp   = DateTime.Now
                };

                if (mouseTracker.HasMouseMoved() || keyboardTracker.GetTimeElapsedSinceLastKeyPress() < timer.Interval.TotalMilliseconds)
                {
                    newTrackingRecord.Active = true;
                    trackingDataContext.Add(newTrackingRecord);
                }
                else
                {
                    trackingDataContext.Add(newTrackingRecord);
                }

                trackingDataContext.SaveChanges();
            };
            timer.IsEnabled = true;

            //Code for setting up MVVM
            ViewNavigator viewNavigator    = new ViewNavigator();
            MainViewModel defaultViewModel = new MainViewModel(viewNavigator);

            viewNavigator.CurrentViewModel = defaultViewModel;
            Window window = new MainWindow();

            window.DataContext = defaultViewModel;
            window.Show();
            base.OnStartup(e);
        }