Пример #1
0
        void HandleLock(object sender, SessionSwitchEventArgs e)
        {
            switch (e.Reason)
            {
            case SessionSwitchReason.SessionLock:
                _outputService.ShowInterface();
                _eventHandler.Invoke(this);
                break;

            case SessionSwitchReason.SessionUnlock:
                _outputService.HideInterface();
                break;
            }
        }
Пример #2
0
        public void Run()
        {
            _timeService.DailyTimeOperations();

            var askTime = DateTime.Now;

            _outputService.ShowInterface();
            _outputService.OutputSound();

            var runMiss        = 0;
            var lastTimeEntry  = _timeService.GetLastTimeEntry();
            var currentTask    = lastTimeEntry?.Task;
            var comment        = "";
            var associatedTask = (Task)null;

            if (currentTask != null)
            {
                var stillWorking = false;

                if (lastTimeEntry.HasComment)
                {
                    stillWorking =
                        _inputService.AskForBoolean($"Are you still working on {lastTimeEntry.Comment} ({currentTask.Name})?");

                    if (stillWorking)
                    {
                        comment        = lastTimeEntry.Comment;
                        associatedTask = lastTimeEntry.AssociatedTask;
                    }
                }

                if (!stillWorking)
                {
                    // attempt to log all time up to this point because tasks were switched
                    if (_settingsService.GetSetting <bool>("SyncOnTaskSwitch"))
                    {
                        _timeService.DailyTimeOperations(true);
                    }

                    stillWorking = _inputService.AskForBoolean($"Are you still working on {currentTask}?");
                }

                if (!stillWorking)
                {
                    currentTask = null;
                }
            }

            if (currentTask == null)
            {
                if (!_inputService.AskForBoolean("Are you working?"))
                {
                    runMiss = _timeService.IntervalsSinceLastRecord();
                    if (runMiss <= 1)
                    {
                        _timeService.RecordMarker(askTime);
                    }
                    else
                    {
                        var lastTime = _timeService.GetLastTimeEntry().TimeRecorded;
                        var minutes  = _timeService.GetIntervalMinutes(1).First();
                        lastTime = lastTime.AddMinutes(minutes);

                        // insert an internal time marker for ask time
                        _timeService.RecordMarker(lastTime);
                    }
                }
                else
                {
                    currentTask = _remoteRunner.AskForTask();
                }
            }

            if (currentTask == null)
            {
                _outputService.HideInterface();
                return;
            }

            if (string.IsNullOrWhiteSpace(comment))
            {
                var recentComments = _timeService.GetRecentlyRecordedCommentsForTask(5, currentTask).ToList();
                comment = _inputService.AskForSelectionOrInput("Choose from options or insert a new comment. (Leave Blank for no comment)", recentComments);
            }

            if (associatedTask == null)
            {
                associatedTask = _remoteRunner.AskForAssociatedTask(currentTask);
            }

            //todo: refactor the way runMiss is done
            runMiss = _timeService.IntervalsSinceLastRecord();
            // there will usually be 1 interval between the last time this ran and this time (it only makes sense)
            if (runMiss <= 1)
            {
                _timeService.RecordTime(currentTask, askTime, comment, associatedTask);
            }
            else
            {
                AskAboutBreak(currentTask, askTime, runMiss, comment, associatedTask);
            }
            _outputService.HideInterface();
        }