Пример #1
0
        public async Task DoActionOnTimer(string userId, string timerId, TimerAction action)
        {
            var currentTimer = await timerRepository.GetTimerAsync(timerId).ConfigureAwait(false);

            currentTimer = currentTimer ?? throw new ArgumentException($"Timer with {timerId} was not found!");
            ValidateUserHasAccessToTimer(userId, currentTimer);

            switch (action)
            {
            case TimerAction.Start:
                await RunTimerAsync(currentTimer).ConfigureAwait(false);

                break;

            case TimerAction.Repeat:
                await RerunTimerAsync(currentTimer).ConfigureAwait(false);

                break;

            case TimerAction.Stop:
                await StopTimerAsync(currentTimer).ConfigureAwait(false);

                break;

            case TimerAction.Pause:
                await PauseTimerAsync(currentTimer).ConfigureAwait(false);

                break;

            case TimerAction.Expire:
                await ExpireTimerAsync(currentTimer).ConfigureAwait(false);

                break;

            case TimerAction.Delete:
                await DeleteTimerAsync(currentTimer).ConfigureAwait(false);

                break;

            default:
                throw new ArgumentException("Handler for the given action was not found");
            }
        }