private void CalculateNumberOfRemainingPhases(Stage selected_stage, StageSegment current_segment) { int s = 0; int t = 0; //Get the current stage segment var segment_order = CurrentSubject.SegmentOrder; for (int i = CurrentSegmentIndex; i < CurrentSubject.SegmentOrder.Count; i++) { var this_segment_name = segment_order[i]; var this_segment = selected_stage.StageSegments.Where(x => x.SegmentName.Equals(this_segment_name)).FirstOrDefault(); if (this_segment == current_segment) { try { var remaining_phases = this_segment.Phases.GetRange(CurrentPhaseIndex + 1, this_segment.Phases.Count - CurrentPhaseIndex - 1).ToList(); s += remaining_phases.Where(x => x is Phase_Study).ToList().Count; t += remaining_phases.Where(x => x is Phase_Test).ToList().Count; } catch (Exception) { //empty } } else { try { s += this_segment.Phases.Where(x => x is Phase_Study).ToList().Count; t += this_segment.Phases.Where(x => x is Phase_Test).ToList().Count; } catch (Exception) { //empty } } } RemainingStudyPhases = s; RemainingTestPhases = t; }
private static void ExpandPhaseNodes(List <StageSegment> segments, StageSegment current_segment, PhaseNode parent) { //Check to see if the parent node is a loop. If so, we potentially need to iterate over all the children multiple times. int loop_count = 1; if (parent.Command.Equals("loop")) { bool success = Int32.TryParse(parent.Parameters[0].Item2, out int lc); if (success) { loop_count = lc; } } for (int c = 0; c < loop_count; c++) { //Iterate over all children for (int i = 0; i < parent.Children.Count; i++) { var this_child = parent.Children[i]; if (this_child.Command.Equals("loop")) { //If this is a loop node, expand its children ExpandPhaseNodes(segments, current_segment, this_child); } else if (this_child.Command.Equals("segment")) { //Initialize a new segment current_segment = new StageSegment(); current_segment.InitializeSegmentFromParameters(this_child.Parameters); //Add this new segment to the list of all segments segments.Add(current_segment); //Expand the children of this segment ExpandPhaseNodes(segments, current_segment, this_child); } else { //Distinguish what kind of phase we are parsing Phase new_phase = null; if (this_child.Command.Equals("instructions")) { new_phase = new Phase_Instructions(); } else if (this_child.Command.Equals("block")) { new_phase = new Phase_Block(); } else if (this_child.Command.Equals("distraction")) { new_phase = new Phase_Distraction(); } else if (this_child.Command.Equals("study")) { new_phase = new Phase_Study(); } else if (this_child.Command.Equals("test")) { new_phase = new Phase_Test(); } else if (this_child.Command.Equals("objectlocation_study")) { new_phase = new Phase_ObjectLocationStudy(); } else if (this_child.Command.Equals("objectlocation_test")) { new_phase = new Phase_ObjectLocationTest(); } if (new_phase != null) { //Initialize the phase based on the input parameters new_phase.InitializePhaseFromParameters(this_child.Parameters, c + 1); //Add the new phase to the current segment if (current_segment != null) { current_segment.Phases.Add(new_phase); } } } } } }