/// <summary> /// Filters a set of name entries into subsets of dictionaries based on origin, subcategory, and category. /// </summary> /// <param name="entries"> The set of name entries. </param> /// <returns> The filtered set of name entries. </returns> private static FilteredEntries Filter(NameEntry [] entries) { // Declare data structure FilteredEntries data = new FilteredEntries { OriginEntries = new Dictionary <int, List <NameEntry> > ( ), //SubcategoryEntries = new Dictionary<Origin.SubcategoryType, List<NameEntry>> ( ), //CategoryEntries = new Dictionary<Origin.CategoryType, List<NameEntry>> ( ), AllEntries = entries }; // Add each origin for (int i = 0; i < origins.Length; i++) { data.OriginEntries.Add(origins [i].ID, new List <NameEntry> ( )); } // Filter each entry for (int i = 0; i < entries.Length; i++) { // Filter each origin for (int j = 0; j < entries [i].Origins.Length; j++) { // Add value to origin key if (data.OriginEntries.ContainsKey(entries [i].Origins [j].ID)) { data.OriginEntries [entries [i].Origins [j].ID].Add(entries [i]); } } } // Return filtered entries return(data); }
public void UpdateFilteredEntries(string filter) { if (String.IsNullOrEmpty(filter)) { // Filter entries FilteredEntries.Clear(); foreach (var item in Entries) { FilteredEntries.Add(item); } } else { string lowcaseFilter = filter.ToLower(); // Take all elements FilteredEntries.Clear(); foreach (var item in Entries.Where(e => e.Title.ToLower().Contains(lowcaseFilter))) { FilteredEntries.Add(item); } } NotifyPropertyChanged("FilteredEntriesEmpty"); }
/// <summary> /// Loads the name data for the generator. /// </summary> public static void LoadNameData( ) { // Track performance System.Diagnostics.Stopwatch performanceTracker = System.Diagnostics.Stopwatch.StartNew( ); // Load origins string originsJson = JsonManager.GetJsonFromResources(ORIGIN_JSON_FILE); OriginWrapper [] originWrapper = JsonManager.FromJson <OriginWrapper> (originsJson); origins = ConvertWrapper(originWrapper); // Load given names string givenNamesJson = JsonManager.GetJsonFromResources(GIVEN_NAME_JSON_FILE); GenderedNonTypedEntryWrapper [] givenNamesWrapper = JsonManager.FromJson <GenderedNonTypedEntryWrapper> (givenNamesJson); givenNames = Filter(ConvertWrapper(givenNamesWrapper)); //// Load family names string familyNamesJson = JsonManager.GetJsonFromResources(FAMILY_NAME_JSON_FILE); NonGenderedNonTypedEntryWrapper [] familyNamesWrapper = JsonManager.FromJson <NonGenderedNonTypedEntryWrapper> (familyNamesJson); familyNames = Filter(ConvertWrapper(familyNamesWrapper)); //// Load nicknames string nicknamesJson = JsonManager.GetJsonFromResources(NICKNAME_JSON_FILE); GenderedTypedEntryWrapper [] nicknamesWrapper = JsonManager.FromJson <GenderedTypedEntryWrapper> (nicknamesJson); nicknames = Filter(ConvertWrapper(nicknamesWrapper)); //// Load name prefixes string prefixesJson = JsonManager.GetJsonFromResources(NAME_PREFIX_JSON_FILE); GenderedNonTypedEntryWrapper [] prefixesWrapper = JsonManager.FromJson <GenderedNonTypedEntryWrapper> (prefixesJson); namePrefixes = Filter(ConvertWrapper(prefixesWrapper)); //// Load name suffixes string suffixesJson = JsonManager.GetJsonFromResources(NAME_SUFFIX_JSON_FILE); NonGenderedNonTypedEntryWrapper [] suffixesWrapper = JsonManager.FromJson <NonGenderedNonTypedEntryWrapper> (suffixesJson); nameSuffixes = Filter(ConvertWrapper(suffixesWrapper)); // Store that the data is loaded isLoaded = true; // Output performance performanceTracker.Stop( ); if (Settings.OutputPerformance) { Debug.Log("Name Data loaded in " + performanceTracker.ElapsedMilliseconds + " ms"); } }
public void TriggerSearch() { FilteredEntries.Refresh(); NotifyPropertyChanged(nameof(FilteredEntries)); }
public IEnumerable <CacheEntry> Page(int pageIndex, int pageSize) { return(FilteredEntries.Skip(pageIndex * pageSize).Take(pageSize)); }