/// <summary> /// Prepare our level for questions. /// </summary> private void PrepareLevel() { MM_KVLevel KVLevel = null; MM_Boundary County = null; MM_Element_Type ElemType = null; if (CurrentLevel.KVLevel != null) { MM_Repository.KVLevels.TryGetValue(CurrentLevel.KVLevel, out KVLevel); } if (CurrentLevel.County != null) { MM_Repository.Counties.TryGetValue(CurrentLevel.County, out County); } if (CurrentLevel.ElemType != null) { MM_Repository.ElemTypes.TryGetValue(CurrentLevel.ElemType, out ElemType); } List <MM_Element> Elements = new List <MM_Element>(); foreach (MM_Element Elem in MM_Repository.TEIDs.Values) { bool Include = true; if (ElemType != null && Elem.ElemType != null && !Elem.ElemType.Equals(ElemType)) { Include = false; } if (Include && CurrentLevel.KVLevel != null) { if (Elem is MM_Substation) { if (((MM_Substation)Elem).KVLevels.IndexOf(KVLevel) == -1) { Include = false; } } else if (Elem.KVLevel != KVLevel) { Include = false; } } if (Include && CurrentLevel.County != null) { if (Elem is MM_Substation && (Elem as MM_Substation).County != County) { Include = false; } else if (Elem is MM_Line && (Elem as MM_Line).Substation1.County != County && (Elem as MM_Line).Substation2.County != County) { Include = false; } } if (Include && !string.IsNullOrEmpty(CurrentLevel.BooleanToCheck)) { MemberInfo[] mI = Elem.GetType().GetMember(CurrentLevel.BooleanToCheck); if (mI.Length != 1) { Include = false;//throw new InvalidOperationException("Unable to locate member " + CurrentLevel.BooleanToCheck); } else if (mI[0] is PropertyInfo) { if (!(bool)((PropertyInfo)mI[0]).GetValue(Elem, null)) { Include = false; } } else if (mI[0] is FieldInfo) { if (!(bool)((FieldInfo)mI[0]).GetValue(Elem)) { Include = false; } } } if (Include) { Elements.Add(Elem); } } QuestionsWrong = 0; QuestionsRight = 0; QuestionsAnswered = 0; PriorLevel = CurrentLevel; AvailableElements = Elements.ToArray(); StartLevel(); }