Пример #1
0
        private List <CharacterData> GetSuggestedCharacterData(string[] extractedCharacters)
        {
            var characters = new List <CharacterData>();

            foreach (var character in extractedCharacters)
            {
                var characterData = new CharacterData {
                    Tag = character
                };
                bool exists = false;
                using (CharacterRepository repo = new CharacterRepository())
                {
                    exists = repo.DoExistsByDanbooruName(character);
                }
                characterData.Exists = exists;

                string suggestedName, suggestedFamilyName, nameValue, bracketValue;
                suggestedName = suggestedFamilyName = nameValue = bracketValue = string.Empty;

                if (!exists)
                {
                    int openBracketIndex = character.IndexOf('(');
                    if (openBracketIndex != -1)
                    {
                        int closeBracketIndex = character.IndexOf(')');
                        int length            = closeBracketIndex - openBracketIndex - 1;
                        bracketValue = character.Substring(openBracketIndex + 1, length);
                        nameValue    = character.Substring(0, openBracketIndex - 1);
                    }
                    else
                    {
                        nameValue = character;
                    }

                    if (nameValue.Contains(' '))
                    {
                        int firstSpaceIndex = nameValue.IndexOf(' ');
                        suggestedFamilyName = nameValue.Substring(0, firstSpaceIndex);
                        suggestedName       = nameValue.Substring(firstSpaceIndex + 1);
                    }
                    else
                    {
                        suggestedName = nameValue;
                    }
                    suggestedName       = suggestedName.Capitalize();
                    suggestedFamilyName = suggestedFamilyName.Capitalize();
                }
                else
                {
                    using (CharacterRepository repo = new CharacterRepository())
                    {
                        Character charObj = repo.GetByDanbooruName(character);
                        suggestedName       = charObj.Name;
                        suggestedFamilyName = charObj.FamilyName;
                    }
                }

                characterData.SuggestedName       = suggestedName;
                characterData.SuggestedFamilyName = suggestedFamilyName;
                characters.Add(characterData);
            }
            return(characters);
        }