/// <summary> /// Re-create the linked list to reflect the new "workflow." /// </summary> /// <param name="routeModifier">The route modifier.</param> private void ReorganizeLinkedList(RouteModifier routeModifier) { WizardStepViewModel cacheCurrentStep = this.CurrentLinkedListStep.Value; IEnumerable <WizardStepViewModel> newSubList = this.CreateNewStepList(routeModifier); this.LinkedSteps = new LinkedList <WizardStepViewModel>(newSubList); this.ResetCurrentLinkedListStepTo(cacheCurrentStep); }
/// <summary> /// OMG, if the user chooses an option that changes the route through the wizard, then goes back and chooses a different option, /// we need to add the appropriate step(s) back into the workflow. /// </summary> /// <param name="workingStepList">The working step list.</param> /// <param name="viewTypes">The view types.</param> private void AddBack( List <WizardStepViewModel> workingStepList, IEnumerable <Type> viewTypes) { foreach (Type vt in viewTypes) { //// Find the step to add back in the main list of steps. WizardStepViewModel stepToAddBack = this.steps.FirstOrDefault(s => s.ViewType == vt); if (!workingStepList.Contains(stepToAddBack)) { //// Re-insert the step into our working list (which will become the wizard's new linked list). if (stepToAddBack != null) { int indexOfStepToAddBack = this.steps.IndexOf(stepToAddBack); //// If it belongs at the head of the list, add it there. if (indexOfStepToAddBack == 0) { workingStepList.Insert(0, stepToAddBack); } else { //// Otherwise we have to find the previous step in the main list, find that step in our working list and add in //// the step after that step. bool stepReinserted = false; int countOfStepsToPreviousFoundStep = 1; while (!stepReinserted) { WizardStepViewModel previousStep = this.steps[indexOfStepToAddBack - countOfStepsToPreviousFoundStep]; for (int i = 0; i < workingStepList.Count; i++) { if (workingStepList[i].ViewType == previousStep.ViewType) { workingStepList.Insert(i + 1, stepToAddBack); stepReinserted = true; } } //// The previous step wasn't found; continue to the next previous step. countOfStepsToPreviousFoundStep++; } } } } } }
/// <summary> /// Must maintain the current step reference (this re-creating of the linked list happens when the user makes a selection on /// the current step). /// After recreating the list, our CurrentLinkedListStep reference would be referring to an item in the old linked list. /// </summary> /// <param name="cacheCurrentStep">The cache current step.</param> private void ResetCurrentLinkedListStepTo(WizardStepViewModel cacheCurrentStep) { this.CurrentLinkedListStep = this.LinkedSteps.First; while (this.CurrentLinkedListStep.Value != cacheCurrentStep) { if (this.CurrentLinkedListStep.Next != null) { this.CurrentLinkedListStep = this.CurrentLinkedListStep.Next; } } }
/// <summary> /// Must maintain the current step reference (this re-creating of the linked list happens when the user makes a selection on /// the current step). /// After recreating the list, our CurrentLinkedListStep reference would be referring to an item in the old linked list. /// </summary> /// <param name="cacheCurrentStep"></param> private void ResetCurrentLinkedListStepTo(WizardStepViewModel cacheCurrentStep) { this.CurrentLinkedListStep = this.LinkedSteps.First; while (this.CurrentLinkedListStep.Value != cacheCurrentStep) { if (this.CurrentLinkedListStep.Next != null) { this.CurrentLinkedListStep = this.CurrentLinkedListStep.Next; } } }