/// <summary> /// Fired whenever a component property's value gets changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComponentPropertyChanged(object sender, PropertyChangedEventArgs e) { //presently, we only care about selection change if (e.PropertyName.CompareTo("IsSelected") == 0) { IWizardBaseController component = sender as IWizardBaseController; if (component.IsSelected) { if (UnselectedComponents.Contains(component)) { UnselectedComponents.Remove(component); } if (!SelectedComponents.Contains(component)) { SelectedComponents.Add(component); } } else { if (SelectedComponents.Contains(component)) { SelectedComponents.Remove(component); } if (!UnselectedComponents.Contains(component)) { UnselectedComponents.Add(component); } } } }
public IWizardBaseController GetComponentByType(Type type) { IWizardBaseController component = (from c in AllComponents where c.GetType() == type select c).FirstOrDefault(); return(component); }
public IWizardBaseController GetComponentByName(string name) { IWizardBaseController component = (from c in AllComponents where c.ControllerName.CompareTo(name) == 0 select c).FirstOrDefault(); return(component); }
public bool Equals(IWizardBaseController other) { if (this.ControllerName.CompareTo(other.ControllerName) == 0) { return(true); } return(false); }
public ActionResult QuickNav() { string componentName = Request.Form["ComponentName"]; manager = new AssignmentWizardComponentManager(CurrentUser); IWizardBaseController componentToFind = manager.GetComponentByName(componentName); //start at the beginning while (manager.GetPreviousComponent() != null) { ; } //empty component name = start at the beginning (component selection) if (componentName.Length == 0) { return(RedirectToRoute(AssignmentWizardAreaRegistration.AssignmentWizardRoute, new { controller = "Home", action = "SelectComponent", assignmentId = manager.ActiveAssignmentId } )); } //from the beginning, find the component that we want to jump to bool found = false; while (!found) { if (manager.ActiveComponent == null) { found = true; } else if (manager.ActiveComponent.ControllerName.CompareTo(componentToFind.ControllerName) == 0) { found = true; } else { manager.GetNextComponent(); } } //redirect to the component return(RedirectToRoute(AssignmentWizardAreaRegistration.AssignmentWizardRoute, new { controller = componentToFind.ControllerName, action = "Index" } )); }
/// <summary> /// Converts a delimited string into a list of <see cref="IWizardBaseController"/> objects. /// </summary> /// <param name="itemString"></param> /// <param name="delimiter">The token used to delimit each entry</param> /// <returns></returns> private List <IWizardBaseController> ComponentsFromString(string itemString, string delimiter) { List <IWizardBaseController> components = new List <IWizardBaseController>(); string[] items = itemString.Split(delimiter.ToCharArray()); foreach (string item in items) { IWizardBaseController component = AllComponents.Find(c => c.ControllerName == item); if (component != null) { components.Add(component); } } return(components); }
public bool Equals(IWizardBaseController other) { return(string.Compare(ControllerName, other.ControllerName, StringComparison.Ordinal) == 0); }
protected ActionResult PostBack(dynamic model) { Manager = new AssessmentWizardComponentManager(CurrentUser); if (WasUpdateSuccessful) { //update the assignment ID. Probably not necessary when working //with existing assignments, but needed for new assignments. Manager.ActiveAssessmentId = Assessment.ID; //Check manager context. If for some reason the user lost their //SESSION context, we need to detect this and redirect them //to a safe place. Otherwise, they will get an error when we //try to redirect them to a non-existant page if (Manager.SelectedComponents.Count == 0) { return(RedirectToRoute(new { controller = "Home", action = "ContextLost", assignmentId = Assessment.ID })); } var errorPath = "Home"; var action = "ContextLost"; var id = Assessment.ID; IWizardBaseController comp = null; if (Request.Form.AllKeys.Contains(WizardNavButtons.PreviousButton.ToString())) { comp = Manager.GetPreviousComponent(); action = "SelectComponent"; } else if (Request.Form.AllKeys.Contains(WizardNavButtons.NextButton.ToString())) { comp = Manager.GetNextComponent(); action = "Summary"; } else if (Request.Form.AllKeys.Contains(WizardNavButtons.SaveAndExitButton.ToString())) { return(RedirectToRoute("Default", new { controller = "Assignment", action = "index" } )); } else { //not having any form keys means that we're using the QuickNav as it won't send back //any submit button data return(QuickNav()); } if (comp != null) { return(RedirectToRoute(AssessmentWizardAreaRegistration.AssessmentWizardRoute, new { controller = Manager.ActiveComponent.ControllerName } )); } return(RedirectToRoute(AssessmentWizardAreaRegistration.AssessmentWizardRoute, new { controller = errorPath, action = action, assignmentId = id } )); } try { SetUpViewBag(); } catch (Exception) { return(RedirectToRoute(new { controller = "Home", action = "ContextLost", assignmentId = Assessment.ID })); } return(View(model)); }
/// <summary> /// Registers all components with the component manager /// </summary> private void RegisterComponents() { //use reflection to find all available components string componentNamespace = WizardComponentNamespace; List <Type> componentObjects = (from type in Assembly.GetExecutingAssembly().GetTypes() where type.GetInterfaces().Contains(typeof(IWizardBaseController)) && !type.IsAbstract && type.Namespace.CompareTo(componentNamespace) == 0 select type).ToList(); foreach (Type component in componentObjects) { IWizardBaseController controller = Activator.CreateInstance(component) as IWizardBaseController; AllComponents.Add(controller); } //pull from the cache if possible FileCache cache = FileCacheHelper.GetGlobalCacheInstance(); bool loadedFromCache = false; string[] sorted = (string[])cache.Get(componentsCacheString, CacheRegion); if (sorted != null) { //set loaded to true for now loadedFromCache = true; //make sure that the sizes match up if (sorted.Length != AllComponents.Count) { loadedFromCache = false; } //make sure all components are represented in the cache foreach (IWizardBaseController component in AllComponents) { if (!sorted.Contains(component.ControllerName)) { loadedFromCache = false; break; } } //if we're still clear to load from the cache, then do so if (loadedFromCache) { IWizardBaseController[] tempComponentList = new IWizardBaseController[sorted.Length]; for (int i = 0; i < sorted.Length; i++) { IWizardBaseController component = AllComponents.Find(c => c.ControllerName == sorted[i]); if (component != null) { tempComponentList[i] = component; } } //reassign the sorted list AllComponents = tempComponentList.ToList(); } } //if caching failed, do it the long way if (!loadedFromCache) { List <IWizardBaseController> components = SortComponents(AllComponents); AllComponents = components; //save sorted component information to cache string[] sortedComponents = new string[AllComponents.Count]; for (int i = 0; i < sortedComponents.Length; i++) { sortedComponents[i] = AllComponents[i].ControllerName; } cache.Add(componentsCacheString, sortedComponents, cache.DefaultPolicy, CacheRegion); } //attach event listeners to selection change //and apply a sort order for faster sorting in the future int counter = 1; foreach (IWizardBaseController component in AllComponents) { component.SortOrder = counter; component.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ComponentPropertyChanged); counter++; } }
private void ActivateSelectedComponents() { manager.DeactivateAllComponents(); string componentPrefix = "component_"; foreach (string key in Request.Form.AllKeys) { if (key.Substring(0, componentPrefix.Length) == componentPrefix) { IWizardBaseController comp = manager.GetComponentByName(Request.Form[key]); comp.IsSelected = true; } } //if we're loading a previous assignment, we need to go through and //remove links to any unselected items if (manager.ActiveAssignmentId != 0) { Assignment assignment = db.Assignments.Find(manager.ActiveAssignmentId); //RUBRICS if (manager.UnselectedComponents.Contains(manager.GetComponentByType(typeof(RubricController)))) { if (assignment.HasRubric) { db.Rubrics.Remove(assignment.Rubric); } assignment.Rubric = null; assignment.RubricID = null; } //STUDENT RUBRICS if (manager.UnselectedComponents.Contains(manager.GetComponentByType(typeof(StudentRubricController)))) { if (assignment.HasStudentRubric) { db.Rubrics.Remove(assignment.StudentRubric); } assignment.StudentRubric = null; assignment.StudentRubricID = null; } //COMMENT CATEGORIES if (manager.UnselectedComponents.Contains(manager.GetComponentByType(typeof(CommentCategoryController)))) { assignment.CommentCategory = null; assignment.CommentCategoryID = null; } //DELIVERABLES if (manager.UnselectedComponents.Contains(manager.GetComponentByType(typeof(DeliverablesController)))) { assignment.Deliverables = null; } //ABET if (manager.UnselectedComponents.Contains(manager.GetComponentByType(typeof(ABETController)))) { assignment.ABETDepartment = null; } db.Entry(assignment).State = System.Data.EntityState.Modified; db.SaveChanges(); } }