private HashSet <string> GetMatchingCharacterIds(string textToFind) { HashSet <string> matchingCharacterIds; if (!m_findTextToMatchingCharacterIds.TryGetValue(textToFind, out matchingCharacterIds)) { if (CharacterDetailData.Singleton.GetAll().Count() != CharacterVerseData.SingletonLocalizedCharacterIdToCharacterIdDictionary.Count) { // First time getting UI versions of character IDs (typically when running tests), so we need to force // population of CharacterVerseData.SingletonLocalizedCharacterIdToCharacterIdDictionary. foreach (var characterId in CharacterGroups.SelectMany(characterGroup => characterGroup.CharacterIds)) { CharacterVerseData.GetCharacterNameForUi(characterId); } } matchingCharacterIds = new HashSet <string>(); m_findTextToMatchingCharacterIds.Add(textToFind, matchingCharacterIds); foreach (var kvp in CharacterVerseData.SingletonLocalizedCharacterIdToCharacterIdDictionary) { if (kvp.Value.IndexOf(textToFind, StringComparison.OrdinalIgnoreCase) >= 0) { matchingCharacterIds.Add(kvp.Key); } } } return(matchingCharacterIds); }
/// <summary> /// Generates a password with the given length. /// </summary> /// <param name="length">The length of the password to be generated.</param> /// <returns>A randomly generated password.</returns> public string GeneratePassword(int length) { if (length < MinLength) { throw new ArgumentOutOfRangeException(nameof(length), $"The length of the generated password must be at least {MinLength} characters."); } // Create a collection of character groups the size of the password to be generated. // The number of times a character group appears in this collection is equal to the // minimum number of occurrences of that character group. An AllCharacters group is // created to fill in the characters not accounted for by the other character groups. List <CharacterGroup> characterGroups = CharacterGroups .SelectMany(characterGroup => Enumerable.Repeat(characterGroup, characterGroup.MinOccurrence)) .Concat(Enumerable.Repeat(new CharacterGroup(AllCharacters), length - MinLength)) .ToList(); char[] passwordChars = new char[length]; for (int i = 0; i < length; i++) { // Pull a random character from the character group into the password CharacterGroup characterGroup = characterGroups[i]; int index = Random.Int32Between(0, characterGroup.Characters.Length); passwordChars[i] = characterGroup.Characters[index]; } // Scramble the generated set of characters passwordChars.Scramble(); return(new string(passwordChars)); }