Ejemplo n.º 1
0
        private void TimerTick(object sender, EventArgs e)
        {
            //double deltaTime = watch.ElapsedMilliseconds * 0.001;
            //watch.Reset(); watch.Start();

            Point  pt    = WindowHelper.GetCursorPos();
            double dx    = pt.X - lastPoint.X;
            double dy    = pt.Y - lastPoint.Y;
            double dl    = Math.Sqrt(dx * dx + dy * dy);
            bool   moved = dl > 0.3;

            if (moved)
            {
                MouseMove(pt);
            }
            lastPoint = pt;

            // Update current position
            CurrentPosition = pt;

            // Update current application (from window title)
            CurrentApplication = WindowHelper.GetForegroundWindowText();
            var ptr = WindowHelper.GetForegroundWindow();

            if (CurrentWindowPtr != ptr)
            {
                Statistics.RegisterWindowSwitch();
            }
            CurrentWindowPtr = ptr;

            // Update total recording time
            Recording.Update(double.MaxValue);

            RaisePropertyChanged("CurrentApplication");
            RaisePropertyChanged("CurrentPosition");
            RaisePropertyChanged("MouseDistanceText");

            RaisePropertyChanged("MouseActivity");
            RaisePropertyChanged("Activity");

            RaisePropertyChanged("ApplicationReport");

            RaisePropertyChanged("MouseStatistics");
            RaisePropertyChanged("KeyboardStatistics");
            RaisePropertyChanged("Statistics");
            RaisePropertyChanged("Report");

            bool saveReport;

            switch (Settings.ReportInterval)
            {
            case ReportInterval.Daily:
                // Check if we passed midnight
                saveReport = RecordingStarted.Day != DateTime.Now.Day;
                break;

            case ReportInterval.Hourly:
                saveReport = RecordingStarted.Hour != DateTime.Now.Hour;
                break;

            default:
                saveReport = false;
                break;
            }

            if (saveReport)
            {
                // Save report for today and reset
                try
                {
                    SaveReports();
                }
                catch (Exception ex)
                {
                    do
                    {
                        MessageBox.Show(ex.Message);
                        ex = ex.InnerException;
                    } while (ex != null);
                }

                InitStatistics();
            }
        }