ReplaceCourse() public method

public ReplaceCourse ( Id id, Course course ) : void
id Id
course Course
return void
Exemplo n.º 1
0
        // Add a new course control to a course. Adds a new CourseControl referencing controlId into courseId. The place to insert is
        // given by courseControl1 and courseControl2. These control should have been gotten by calling FindControlInsertionPoint.
        public static Id<CourseControl> AddCourseControl(EventDB eventDB, Id<ControlPoint> controlId, Id<Course> courseId, Id<CourseControl> courseControl1, Id<CourseControl> courseControl2)
        {
            CourseControl newCourseControl;
            Id<CourseControl> newCourseControlId;

            // When adding a new course controls, they fit into variations fine because we are never adding or changing an split, just
            // fitting into existing splits.

            if (courseControl1.IsNone) {
                // Adding at start.
                Course course = (Course) eventDB.GetCourse(courseId).Clone();
                Debug.Assert(courseControl2 == course.firstCourseControl);
                newCourseControl = new CourseControl(controlId, course.firstCourseControl);
                newCourseControlId = eventDB.AddCourseControl(newCourseControl);
                course.firstCourseControl = newCourseControlId;
                eventDB.ReplaceCourse(courseId, course);
            }
            else {
                // Adding after courseControl1.
                CourseControl before = (CourseControl) eventDB.GetCourseControl(courseControl1).Clone();
                Debug.Assert(courseControl2 == before.nextCourseControl);
                newCourseControl = new CourseControl(controlId, before.nextCourseControl);
                newCourseControlId = eventDB.AddCourseControl(newCourseControl);
                before.nextCourseControl = newCourseControlId;
                eventDB.ReplaceCourseControl(courseControl1, before);
            }

            return newCourseControlId;
        }
Exemplo n.º 2
0
        // Change the course print area. If "removeParts" is true, and the course is an all parts,
        // then remove print descriptions for each part.
        public static void ChangePrintArea(EventDB eventDB, CourseDesignator courseDesignator, bool removeParts, PrintArea printArea)
        {
            printArea = (PrintArea) printArea.Clone();

            if (courseDesignator.IsAllControls) {
                Event e = eventDB.GetEvent();

                e = (Event) e.Clone();
                e.printArea = printArea;

                eventDB.ChangeEvent(e);
            }
            else {
                Course course = eventDB.GetCourse(courseDesignator.CourseId);

                course = (Course) course.Clone();

                if (courseDesignator.AllParts) {
                    course.printArea = printArea;

                    if (removeParts)
                        course.partPrintAreas = new Dictionary<int, PrintArea>();
                }
                else {
                    course.partPrintAreas[courseDesignator.Part] = printArea;
                }

                eventDB.ReplaceCourse(courseDesignator.CourseId, course);
            }
        }
Exemplo n.º 3
0
        public static void ChangePartOptions(EventDB eventDB, CourseDesignator courseDesignator, PartOptions partOptions)
        {
            Debug.Assert(courseDesignator.IsNotAllControls);

            Course course = eventDB.GetCourse(courseDesignator.CourseId);

            course = (Course)course.Clone();
            course.partOptions[courseDesignator.Part] = partOptions.Clone();
            eventDB.ReplaceCourse(courseDesignator.CourseId, course);
        }
Exemplo n.º 4
0
        // Change the sort order of a course.
        public static void ChangeCourseSortOrder(EventDB eventDB, Id<Course> courseId, int newSortOrder)
        {
            if (newSortOrder <= 0)
                throw new ApplicationException("Bad sort order");

            Course course = eventDB.GetCourse(courseId);

            course = (Course) course.Clone();
            course.sortOrder = newSortOrder;

            eventDB.ReplaceCourse(courseId, course);
        }
Exemplo n.º 5
0
        // Change the course secondary title. Use "" or null to remove the secondary title.
        public static void ChangeCourseSecondaryTitle(EventDB eventDB, Id<Course> courseId, string newTitle)
        {
            if (newTitle == "")
                newTitle = null;
            Course course = eventDB.GetCourse(courseId);

            course = (Course)course.Clone();
            course.secondaryTitle = newTitle;

            eventDB.ReplaceCourse(courseId, course);
        }
Exemplo n.º 6
0
        // Change the course override length.
        public static void ChangeCourseOverrideLength(EventDB eventDB, Id<Course> courseId, float? length)
        {
            Course course = eventDB.GetCourse(courseId);

            course = (Course)course.Clone();
            course.overrideCourseLength = length;

            eventDB.ReplaceCourse(courseId, course);
        }
Exemplo n.º 7
0
        // Change the attributes of a course.
        public static void ChangeCourseProperties(EventDB eventDB, Id<Course> courseId, CourseKind courseKind, string courseName, ControlLabelKind labelKind, int scoreColumn, string secondaryTitle, float printScale, float climb, float? length, DescriptionKind descriptionKind, int firstControlOrdinal)
        {
            Course course = eventDB.GetCourse(courseId);

            course = (Course) course.Clone();
            course.kind = courseKind;
            course.labelKind = labelKind;
            course.scoreColumn = scoreColumn;
            course.name = courseName;
            course.secondaryTitle = secondaryTitle;
            course.printScale = printScale;
            course.climb = climb;
            course.overrideCourseLength = length;
            course.descKind = descriptionKind;
            course.firstControlOrdinal = firstControlOrdinal;

            eventDB.ReplaceCourse(courseId, course);
        }
Exemplo n.º 8
0
        // Change the load of a course.
        public static void ChangeCourseLoad(EventDB eventDB, Id<Course> courseId, int newLoad)
        {
            Course course = eventDB.GetCourse(courseId);

            course = (Course) course.Clone();
            course.load = newLoad;

            eventDB.ReplaceCourse(courseId, course);
        }
Exemplo n.º 9
0
        // Change the course name.
        public static void ChangeCourseName(EventDB eventDB, Id<Course> courseId, string newName)
        {
            Course course = eventDB.GetCourse(courseId);

            course = (Course)course.Clone();
            course.name = newName;

            eventDB.ReplaceCourse(courseId, course);
        }
Exemplo n.º 10
0
        // Change the course climb.
        public static void ChangeCourseClimb(EventDB eventDB, Id<Course> courseId, float newClimb)
        {
            Course course = eventDB.GetCourse(courseId);

            course = (Course)course.Clone();
            course.climb = newClimb;

            eventDB.ReplaceCourse(courseId, course);
        }
Exemplo n.º 11
0
        // Add a start control to a given course. If the course already has a start control as the first control, replace it.
        // Otherwise add it as the new start control. The returned CourseControl may be new, or may be the first control with
        // a different control point.
        // If addToOtherCourses is true, the new start control is also added to all courses without an existing start control.
        public static Id<CourseControl> AddStartToCourse(EventDB eventDB, Id<ControlPoint> controlId, Id<Course> courseId, bool addToOtherCourses)
        {
            Course course = eventDB.GetCourse(courseId);
            Id<CourseControl> firstId = course.firstCourseControl;
            Id<CourseControl> newCourseControlId;
            if (firstId.IsNotNone && eventDB.GetControl(eventDB.GetCourseControl(firstId).control).kind == ControlPointKind.Start) {
                // First control exists and is a start control. Replace it.
                CourseControl first = (CourseControl) eventDB.GetCourseControl(firstId).Clone();
                first.control = controlId;
                eventDB.ReplaceCourseControl(firstId, first);
                newCourseControlId = firstId;
            }
            else {
                // Add the control as a new start control.
                newCourseControlId = eventDB.AddCourseControl(new CourseControl(controlId, firstId));
                course = (Course) course.Clone();
                course.firstCourseControl = newCourseControlId;
                eventDB.ReplaceCourse(courseId, course);
            }

            if (addToOtherCourses) {
                List<Id<Course>> courseModificationList = new List<Id<Course>>();

                // Check all courses to see if we should add the start to that course too.
                foreach (Id<Course> courseSearchId in eventDB.AllCourseIds) {
                    if (!QueryEvent.HasStartControl(eventDB, courseSearchId)) {
                        // This course does not have a start control.
                        courseModificationList.Add(courseSearchId);
                    }
                }

                // Add the start control to each of those courses.
                foreach (Id<Course> modifyCourseId in courseModificationList)
                    AddStartToCourse(eventDB, controlId, modifyCourseId, false);
            }

            return newCourseControlId;
        }
Exemplo n.º 12
0
        public static void SetRelayParameters(EventDB eventDB, Id<Course> courseId, int numberTeams, int numberLegs)
        {
            Course course = eventDB.GetCourse(courseId);

            course = (Course)course.Clone();
            course.relayTeams = numberTeams;
            course.relayLegs = numberLegs;
            eventDB.ReplaceCourse(courseId, course);
        }
Exemplo n.º 13
0
        // Remove a control from a course. Caller must ensure the current is actually in this course.
        // Returns a list of all control points that were deleted. This will include the one asked to remove,
        // but might also remove others if it starts a fork or loop.
        public static ICollection<Id<ControlPoint>> RemoveCourseControl(EventDB eventDB, Id<Course> courseId, Id<CourseControl> courseControlIdRemove)
        {
            Course course = eventDB.GetCourse(courseId);
            List<Id<CourseControl>> allCourseControls = QueryEvent.EnumCourseControlIds(eventDB, new CourseDesignator(courseId)).ToList();

            // This the course control to change to. Could be None.
            CourseControl courseControlRemove = eventDB.GetCourseControl(courseControlIdRemove);
            Id<CourseControl> afterRemove = courseControlRemove.nextCourseControl;
            if (courseControlRemove.split && !courseControlRemove.loop) {
                // Change next to another one of the split controls.
                if (courseControlRemove.splitCourseControls[0] == courseControlIdRemove)
                    afterRemove = courseControlRemove.splitCourseControls[1];
                else
                    afterRemove = courseControlRemove.splitCourseControls[0];
            }

            // For each course control, go throught and change referecnes to the subsequent control.
            foreach (Id<CourseControl> courseControlId in allCourseControls) {
                bool changed = false;
                CourseControl courseControl = eventDB.GetCourseControl(courseControlId);
                CourseControl clone = (CourseControl)courseControl.Clone();

                if (courseControl.nextCourseControl == courseControlIdRemove) {
                    changed = true;
                    clone.nextCourseControl = afterRemove;
                }
                if (courseControl.split && courseControl.splitEnd == courseControlIdRemove) {
                    changed = true;
                    clone.splitEnd = afterRemove;
                    if (afterRemove.IsNone) {
                        clone.split = false;  // No join control means we remove the split entirely.
                        clone.splitCourseControls = null;
                    }
                }
                if (clone.split && clone.splitCourseControls.Contains(courseControlIdRemove)) {
                    changed = true;
                    clone.splitCourseControls = clone.splitCourseControls.Where(id => id != courseControlIdRemove).ToArray();
                    if (clone.splitCourseControls.Length < 2) {
                        clone.split = false;
                        clone.loop = false;
                        clone.splitCourseControls = null;
                        clone.splitEnd = Id<CourseControl>.None;
                    }
                }
                if (changed) {
                    eventDB.ReplaceCourseControl(courseControlId, clone);
                }
            }

            if (course.firstCourseControl == courseControlIdRemove) {
                // Special case -- remove the first course control.
                course = (Course) course.Clone();
                course.firstCourseControl = afterRemove;
                eventDB.ReplaceCourse(courseId, course);
            }

            // Remove a split could orphan more than one control. Go through and find orphaned ones.
            HashSet<Id<CourseControl>> newCourseControls = new HashSet<Id<CourseControl>>(QueryEvent.EnumCourseControlIds(eventDB, new CourseDesignator(courseId)));
            List<Id<CourseControl>> removedCourseControls = new List<Id<CourseControl>>();
            HashSet<Id<ControlPoint>> removedControls = new HashSet<Id<ControlPoint>>();

            foreach (Id<CourseControl> courseControlId in allCourseControls) {
                if (!newCourseControls.Contains(courseControlId)) {
                    removedControls.Add(eventDB.GetCourseControl(courseControlId).control);
                    removedCourseControls.Add(courseControlId);
                    eventDB.RemoveCourseControl(courseControlId);
                }
            }

            if (! removedCourseControls.Contains(courseControlIdRemove)) {
                Debug.Fail("Did not remove the course control we were removing.");
            }

            return removedControls;
        }
Exemplo n.º 14
0
        // Add a finish control to a given course. If the course already has a finish control as the last control, replace it.
        // Otherwise add it as the new finish control. The returned CourseControl may be new, or may be the last control with
        // a different control point.
        // If addToOtherCourses is true, the new finish control is also added to all courses without an existing finish control.
        public static Id<CourseControl> AddFinishToCourse(EventDB eventDB, Id<ControlPoint> controlId, Id<Course> courseId, bool addToOtherCourses)
        {
            Course course = eventDB.GetCourse(courseId);
            Id<CourseControl> lastId = QueryEvent.LastCourseControl(eventDB, courseId, false);
            Id<CourseControl> newCourseControlId;

            if (lastId.IsNone) {
                // No controls in the course. add this as the only control in the course.
                newCourseControlId = eventDB.AddCourseControl(new CourseControl(controlId, Id<CourseControl>.None));
                course = (Course) course.Clone();
                course.firstCourseControl = newCourseControlId;
                eventDB.ReplaceCourse(courseId, course);
            }
            else if (eventDB.GetControl(eventDB.GetCourseControl(lastId).control).kind == ControlPointKind.Finish) {
                // Last control exists and is a finish control. Replace it.
                CourseControl last = (CourseControl) eventDB.GetCourseControl(lastId).Clone();
                last.control = controlId;
                eventDB.ReplaceCourseControl(lastId, last);
                newCourseControlId = lastId;
            }
            else {
                // Last control exist but is not a finish. Add the finish onto it.
                newCourseControlId = eventDB.AddCourseControl(new CourseControl(controlId, Id<CourseControl>.None));
                CourseControl last = (CourseControl) eventDB.GetCourseControl(lastId).Clone();
                last.nextCourseControl = newCourseControlId;
                eventDB.ReplaceCourseControl(lastId, last);
            }

            if (addToOtherCourses) {
                List<Id<Course>> courseModificationList = new List<Id<Course>>();

                // Check all courses to see if we should add the finish to that course too.
                foreach (Id<Course> courseSearchId in eventDB.AllCourseIds) {
                    if (!QueryEvent.HasFinishControl(eventDB, courseSearchId)) {
                        // This course does not have a finish control.
                        courseModificationList.Add(courseSearchId);
                    }
                }

                // Add the finish control to each of those courses.
                foreach (Id<Course> modifyCourseId in courseModificationList)
                    AddFinishToCourse(eventDB, controlId, modifyCourseId, false);
            }

            return newCourseControlId;
        }