예제 #1
0
        private void CalculateBreaksAvailsForUtcDate(
            string salesAreaName,
            ImmutableList <IProgrammeForBreakAvailCalculation> programmes,
            IReadOnlyList <ISpotForBreakAvailCalculation> spots,
            IReadOnlyList <Break> breaks,
            Schedule scheduleForUtcDate,
            IBreakRepository breakRepository,
            IScheduleRepository scheduleRepository)
        {
            var breakUpdateHandler = new BreakAvailabilityUpdateHandler(
                _logger,
                breakRepository,
                scheduleForUtcDate);

            new BreakAndOptimiserAvailabilityCalculator <Break>(_logger, breakUpdateHandler)
            .Calculate(
                salesAreaName,
                programmes,
                breaks,
                spots
                );

            if (scheduleForUtcDate is null || !breakUpdateHandler.ScheduleBreaksHaveChanges)
            {
                return;
            }

            scheduleRepository.Update(scheduleForUtcDate);
        }
예제 #2
0
        /// <summary>
        /// These breaks have already been calculated. The schedule breaks for
        /// the following day need updating as they're in a different Schedule.
        /// </summary>
        /// <param name="salesAreaName"></param>
        /// <param name="date"></param>
        /// <param name="programmesSpanningMidnight"></param>
        /// <param name="breaksForUtcDate"></param>
        /// <param name="breakRepository"></param>
        /// <param name="scheduleRepository"></param>
        private void CopyUpdatedPostMidnightBreakAvails(
            string salesAreaName,
            DateTime date,
            IReadOnlyList <IProgrammeForBreakAvailCalculation> programmesSpanningMidnight,
            IReadOnlyList <Break> breaksForUtcDate,
            IBreakRepository breakRepository,
            IScheduleRepository scheduleRepository)
        {
            if (programmesSpanningMidnight.Count == 0)
            {
                return;
            }

            var scheduleForUtcDatePlusOne = GetScheduleForUtcDate(
                salesAreaName,
                date,
                scheduleRepository);

            if (scheduleForUtcDatePlusOne is null)
            {
                return;
            }

            var breakUpdateHandler = new BreakAvailabilityUpdateHandler(
                _logger,
                breakRepository,
                scheduleForUtcDatePlusOne);

            foreach (var programme in programmesSpanningMidnight)
            {
                var breaksAfterMidnight = breaksForUtcDate
                                          .Where(theBreak => programme.DateTimeIsInProgramme(theBreak.ScheduledDate));

                if (!breaksAfterMidnight.Any())
                {
                    continue;
                }

                foreach (var oneBreak in breaksAfterMidnight)
                {
                    breakUpdateHandler.UpdateAvailability(oneBreak);
                    breakUpdateHandler.UpdateOptimizerAvailability(oneBreak);
                    scheduleRepository.Update(scheduleForUtcDatePlusOne);
                }
            }
        }