예제 #1
0
        private bool IsValid(OfferedCourse offeredCourse, ReductionStepAction action, OfferedCourseRow offeredCourseRow = null)
        {
            if (action == ReductionStepAction.WHITE_ONE_RED_ROW)
            {
                return true;
            }
            else if (action == ReductionStepAction.WHITE_ALL_COURSES_ROWS)
            {
                return true;
            }
            else if (action == ReductionStepAction.RED_ALL_COURSES_ROWS)
            {
                if (offeredCourse.Color == ReductionStep2ColorStatus.Green)
                {
                    return false;
                }
                else if (offeredCourse.Color == ReductionStep2ColorStatus.WHITE)
                {
                    return true;
                }
                else throw new Exception();
            }
            else if (action == ReductionStepAction.UNCHECK_COURSE_MUST_BE_TAKE)
            {
                List<int> lst = new List<int>();
                foreach (var o in greenCourses)
                    if (o != offeredCourse)
                        lst.Add(o.Course.Id);
                //is valid state must be checked
                return MainCurriculumSateValidator.IsValidState(mainCurriculum, lst);
            }
            else if (action == ReductionStepAction.RED_ONE_WHITE_ROW)
            {
                if (offeredCourse.Color == ReductionStep2ColorStatus.WHITE)
                {
                    return true;
                }
                else if (offeredCourse.Color == ReductionStep2ColorStatus.Green)
                {
                    //temorary change the actual current value
                    offeredCourseRow.Color = ReductionStep2ColorStatus.RED;

                    List<Box> boxes = new List<Box>
                    {
                        ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(offeredCourse)
                    };

                    //restore actual value
                    offeredCourseRow.Color = ReductionStep2ColorStatus.WHITE;

                    foreach (var item in greenCourses)
                    {
                        if (item != offeredCourse)
                            boxes.Add(ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(item));
                    }

                    List<Box> res = null;
                    var task = Task.Run(() => ReductionStep2ServiceProvider.Validate(boxes, exampCollideChecking));
                    if (task.Wait(TimeSpan.FromMilliseconds(timeoutMs)))
                        res = task.Result;
                    else
                    {
                        res = null;
                    }



                    if (res == null) return false;
                    return true;

                }
                else
                    throw new Exception();
            }
            else if (action == ReductionStepAction.CHECK_COURSE_MUST_BE_TAKE)
            {
                if (offeredCourse.Course.Units + currentMustUnits > maxUnits)
                {
                    return false;
                }

                List<int> lst = new List<int>();
                foreach (var o in greenCourses)
                    lst.Add(o.Course.Id);
                lst.Add(offeredCourse.Course.Id);
                //is valid state must be checked
                bool output = MainCurriculumSateValidator.IsValidState(mainCurriculum, lst);
                if (!output) return false;

                output = false;
                for (int a = 0; a < offeredCourse.OfferedCourseRows.Count; a++)
                {
                    if (offeredCourse.OfferedCourseRows[a].Color == ReductionStep2ColorStatus.WHITE)
                    {
                        output = true;
                        break;
                    }
                }
                if (!output) return false;

                Box b1 = ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(offeredCourse);

                List<Box> boxes = new List<Box>
                {
                    b1
                };
                foreach (var item in greenCourses)
                {
                    boxes.Add(ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(item));
                }

                List<Box> res = null;
                var task = Task.Run(() => ReductionStep2ServiceProvider.Validate(boxes, exampCollideChecking));
                if (task.Wait(TimeSpan.FromMilliseconds(timeoutMs)))
                    res = task.Result;
                else
                {
                    res = null;
                }

                if (res == null) return false;

                return true;
            }

            throw new Exception();
            //return false;
        }
예제 #2
0
 private Task<bool> IsValidAsync(OfferedCourse offeredCourse, ReductionStepAction action, OfferedCourseRow offeredCourseRow = null)
 {
     return Task.Run<bool>(() => IsValid(offeredCourse, action, offeredCourseRow));
 }