Esempio n. 1
0
        public void CountParrot(string userId, string channelId, DateTime currentTime)
        {
            if (!Utils.IsInTimespan(currentTime, TimeSpan.FromHours(MorningBreak), Tolerance) &&
                !Utils.IsInTimespan(currentTime, TimeSpan.FromHours(AfternoonBreak), Tolerance))
            {
                return;
            }

            _coffeeRepository.ConfirmUserReady(userId);

            if (_coffeeRepository.GetMissingParticipants().Count == 0)
            {
                LaunchCoffeeBreak(channelId);
                return;
            }

            var remindJob = _channelRepository.GetRemindJob();

            if (!string.IsNullOrEmpty(remindJob))
            {
                _backgroundJobClient.Delete(remindJob);
            }

            var newRemindJob = _backgroundJobClient.Schedule(() => CoffeeRemind(channelId), TimeSpan.FromSeconds(CoffeeRemindDelaySeconds));

            _channelRepository.SetRemindJob(newRemindJob);
        }
Esempio n. 2
0
        public void CountParrot(string userId, string channelId, DateTime currentTime)
        {
            var coffeeBreak = _coffeeRepository.GetCoffeeBreak();

            var timeZoneInfo = TimeZoneInfo.GetSystemTimeZones().Any(x => x.Id == "Eastern Standard Time") ?
                               TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time") :
                               TimeZoneInfo.FindSystemTimeZoneById("America/New_York");

            var timezoneOffset = timeZoneInfo.GetUtcOffset(currentTime);
            var morningBreak   = TimeSpan.FromHours(MorningBreak) - timezoneOffset;
            var afternoonBreak = TimeSpan.FromHours(AfternoonBreak) - timezoneOffset;

            var morningBreakIsPossible   = IsInTimespan(currentTime, morningBreak, Tolerance);
            var afternoonBreakIsPossible = IsInTimespan(currentTime, afternoonBreak, Tolerance);
            var isTooCloseFromLastBreak  = currentTime < coffeeBreak.LastCoffee + TimeSpan.FromHours(1);

            if (!morningBreakIsPossible && !afternoonBreakIsPossible)
            {
                return;
            }

            if (isTooCloseFromLastBreak || coffeeBreak.IsCoffeeBreak)
            {
                return;
            }

            _coffeeRepository.ConfirmUserReady(userId);

            if (_coffeeRepository.GetMissingParticipants().Count == 0)
            {
                LaunchCoffeeBreak(channelId);
                return;
            }

            var remindJob = _coffeeRepository.GetRemindJob();

            if (!string.IsNullOrEmpty(remindJob))
            {
                _backgroundJobClient.Delete(remindJob);
            }

            var newRemindJob = _backgroundJobClient.Schedule(() => CoffeeRemind(channelId), TimeSpan.FromSeconds(CoffeeRemindDelaySeconds));

            _coffeeRepository.SetRemindJob(newRemindJob);
        }