コード例 #1
0
        private void ApplyOlc()
        {
            _logger.Debug("Apply OLC");
            List <Course> plannedCourses = _coursePlanning.PlannedCourses.OrderBy(course => course.PlannedImplementation.StartDay).ToList();

            int daysAfterLastCourseEmployable = _managementPropertiesDataMapper.FindManagementProperties().PeriodAfterLastCourseEmployableInDays;

            DateTime dateEmployableFrom = StartDate.AddDays(daysAfterLastCourseEmployable);

            DateTime?lastDayOfPlanning = plannedCourses.LastOrDefault()?.PlannedImplementation.Days.Last();

            if (lastDayOfPlanning != null)
            {
                dateEmployableFrom = lastDayOfPlanning.Value
                                     .AddDays(daysAfterLastCourseEmployable);
            }

            var datesOfPeriod = Enumerable.Range(0, 1 + dateEmployableFrom.Subtract(StartDate).Days)
                                .Select(offset => StartDate.AddDays(offset))
                                .ToList();

            _logger.Debug(string.Format(_culture, "{0} dates in periode found", datesOfPeriod.Count));


            List <DateTime> olcDates          = new List <DateTime>();
            Course          previousCourse    = new Course();
            Course          previousDayCourse = new Course();

            foreach (var date in datesOfPeriod)
            {
                _logger.Debug(string.Format(_culture, "Check date {0} for applying OLC", date.ToString("dd-MM-yyyy")));
                if (IsWeekend(date))
                {
                    _logger.Debug(string.Format(_culture, "Date {0} is weekend", date.ToString("dd-MM-yyyy")));
                    if (olcDates.Any())
                    {
                        _logger.Debug(string.Format(_culture, "OLC dates is not empty at date {0}", date.ToString("dd-MM-yyyy")));
                        AddOlc(olcDates);
                        olcDates = new List <DateTime>();
                    }
                    continue;
                }

                Course selectedCourse = plannedCourses.FirstOrDefault(c => c.CourseImplementations.Any(ci => ci.Days.Contains(date) && ci.Status == Status.PLANNED));

                if (selectedCourse == null && !BlockedDates.Contains(date))
                {
                    _logger.Debug(string.Format(_culture, "Add date {0} to OLC dates", date.ToString("dd-MM-yyyy")));
                    olcDates.Add(date);
                }

                bool newCourse = previousCourse != selectedCourse && previousDayCourse == null && selectedCourse != null;
                if ((newCourse || BlockedDates.Contains(date)) && olcDates.Any())
                {
                    _logger.Debug(string.Format(_culture, "OLC dates is not empty at date {0}", date.ToString("dd-MM-yyyy")));
                    AddOlc(olcDates);
                    olcDates = new List <DateTime>();
                }

                if (selectedCourse != null)
                {
                    _logger.Debug(string.Format(_culture, "Selected course {0} is not null", selectedCourse.Code));
                    previousCourse = selectedCourse;
                }
                previousDayCourse = selectedCourse;
            }

            if (olcDates.Any())
            {
                _logger.Debug("Add last OLC to planning");
                AddOlc(olcDates);
            }
        }
コード例 #2
0
        private Generator.Course RemoveBlockedAndOutsidePeriodImplementations(Generator.Course course)
        {
            _logger.Debug(string.Format(_culture, "Remove blocked implementations and implementations outside the period from course {0}", course.Code));

            if (BlockedDates != null)
            {
                _logger.Debug(string.Format(_culture, "Remove {0} blocked implementations from course {1}", BlockedDates.Count, course.Code));

                int periodEducationPlanDays       = _managementPropertiesDataMapper.FindManagementProperties().PeriodEducationPlanInDays;
                int daysAfterLastCourseEmployable = _managementPropertiesDataMapper.FindManagementProperties().PeriodAfterLastCourseEmployableInDays;

                DateTime endDate = StartDate.GetEndDay(periodEducationPlanDays);

                if (EndDate != null)
                {
                    endDate = EndDate.Value.AddDays(-daysAfterLastCourseEmployable);
                    _logger.Debug(string.Format(_culture, "Period for education plan is {0} days", endDate - StartDate));
                }
                else
                {
                    _logger.Debug(string.Format(_culture, "Period for education plan is {0} days", periodEducationPlanDays));
                }

                var blockedImplementations = course.CourseImplementations.Where(ci => ci.StartDay <StartDate || ci.StartDay.GetEndDay(ci.Days.Count())> endDate || ci.Days.Any(day => BlockedDates.Contains(day)));

                _logger.Debug("Set status of blocked implementations and implementations outside the period on unplannable");
                foreach (var implementation in blockedImplementations)
                {
                    implementation.Status = Status.UNPLANNABLE;
                }
            }

            return(course);
        }