private static bool IsInvalid(RepresentationForUser representationForUser) { Size size = representationForUser != null ? representationForUser.Size : null; bool result = representationForUser == null || string.IsNullOrEmpty(representationForUser.Title) || IsInvalidSize(size) || IsInvalidImage(representationForUser.Image) || !EnumerableValidator.IsNotNullAndNotEmpty(representationForUser.Areas); if (!result) { IWordsQuery wordsQuery = new WordsQuery(); //проверить области List <RepresentationAreaForUser> areas = representationForUser.Areas; foreach (RepresentationAreaForUser area in areas) { if (wordsQuery.IsInvalid(area.Source) || wordsQuery.IsInvalid(area.Translation) || IsInvalid(size, area.LeftUpperCorner) || IsInvalid(size, area.RightBottomCorner)) { result = true; break; } } } return(result); }
public void FillByCSV(string fileName, Action <int, string, string, bool> callBack) { var csvReader = new CsvReader(fileName); SetLanguages(); var wordsQuery = new WordsQuery(); int i = 0; do { string[] line = csvReader.ReadLine(); if (line == null) { break; } if (line.Length < 2) { continue; } string source = line[0].Trim(); string[] translations = line[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string translation in translations) { WordWithTranslation wordWithTranslation = wordsQuery.GetOrCreate( new PronunciationForUser(IdValidator.INVALID_ID, source, false, _englishLanguageId), new PronunciationForUser(IdValidator.INVALID_ID, translation, false, _russianLanguageId), null, WordType.PhrasalVerb); callBack(++i, source, translation, wordWithTranslation != null); } } while (true); }
public void UpdateDatabase([FromBody] dynamic wordsQuery) { var connection = DatabaseHelper.OpenConnection(); var json = wordsQuery.ToString(); WordsQuery deserialized = JsonConvert.DeserializeObject <WordsQuery>(json); var attempts = GetListAttemptUdts(deserialized.Words); var dataTable = GetDataTable(attempts); var command = GetCommandForAddOrUpdateUserWordProgress(connection, dataTable, deserialized.UserId); command.ExecuteNonQuery(); DatabaseHelper.CloseConnection(connection); }
private void Load() { if (_isLoaded) { return; } SetLanguages(); _words = new WordsQuery(); _counter = 0; _isLoaded = true; }
public static void Fill() { var languages = new LanguagesQuery(LanguageShortName.Unknown, LanguageShortName.Unknown); Language language = languages.GetByShortName(LanguageShortName.En); long englishLanguageId = language.Id; IPronunciationQuery pronunciationQuery = new SentencesQuery(); pronunciationQuery.FillSpeak(englishLanguageId); pronunciationQuery = new WordsQuery(); pronunciationQuery.FillSpeak(englishLanguageId); }
public JsonResult Check(long userId, string textToCheck, long sourceId) { if (IdValidator.IsInvalid(sourceId) || string.IsNullOrWhiteSpace(textToCheck)) { return(JsonResultHelper.Error()); } var wordsQuery = new WordsQuery(); var word = wordsQuery.GetById(sourceId) as Word; if (word == null) { return(JsonResultHelper.Error()); } textToCheck = textToCheck.Trim(); bool isEquals = string.Equals(word.Text, textToCheck, StringComparison.InvariantCultureIgnoreCase); return(JsonResultHelper.Success(isEquals)); }
private static byte[] GetPronunciation(long id, SpeakerDataType type) { IPronunciationQuery pronunciationQuery = null; if (type == SpeakerDataType.Word) { pronunciationQuery = new WordsQuery(); } else if (type == SpeakerDataType.Sentence) { pronunciationQuery = new SentencesQuery(); } if (pronunciationQuery == null) { LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat( "SpeakerController.GetPronunciation передан некорректный тип {0}", type); return(null); } IPronunciation pronunciationEntity = pronunciationQuery.GetById(id); return(pronunciationEntity != null ? pronunciationEntity.Pronunciation : null); }
public JsonResult Search(UserLanguages userLanguages, string query) { if (UserLanguages.IsInvalid(userLanguages)) { return(JsonResultHelper.Error()); } WordsByPattern result; if (!string.IsNullOrEmpty(query)) { var wordsQuery = new WordsQuery(); result = wordsQuery.GetLikeWords(userLanguages, query, WordType); if (EnumerableValidator.IsEmpty(result.Words)) { //попробовать перевести символы из латинских в русские, из русских в латинские result = GetKeyboardLayoutResult(userLanguages, query, wordsQuery); } } else { result = new WordsByPattern(); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public RepresentationForUser GetOrCreate(RepresentationForUser representationForUser) { if (IsInvalid(representationForUser)) { return(null); } bool isSuccess = true; RepresentationForUser result = null; Adapter.ActionByContext(c => { result = GetOrCreateRepresentation(representationForUser, c); if (result == null) { LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat( "RepresentationsQuery.GetOrCreate не удалось создать представление! Название: {0}, изображение: {1}", representationForUser.Title, representationForUser.Image != null ? representationForUser.Image.Length.ToString(CultureInfo.InvariantCulture) : "<NULL>"); isSuccess = false; return; } var wordsQuery = new WordsQuery(); foreach (RepresentationAreaForUser areaForUser in representationForUser.Areas) { long wordTranslationId = wordsQuery.GetIdByWordsForUser(areaForUser.Source, areaForUser.Translation); if (IdValidator.IsInvalid(wordTranslationId)) { LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat( "RepresentationsQuery.GetOrCreate не найти связку для слов!" + "Id представления: {0}, слово источник {1}, слово перевод {2}", result.Id, areaForUser.Source.Text, areaForUser.Translation.Text); isSuccess = false; continue; } RepresentationArea representationArea = GetOrCreateArea(c, result.Id, wordTranslationId, areaForUser); if (IdValidator.IsInvalid(representationArea.Id)) { LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat( "RepresentationsQuery.GetOrCreate не удалось создать область представления! " + "Id представления: {0}, левый верхний угол: {1}, правый нижний угол: {2}, исходное слово {3}, слово перевод {4}", result.Id, areaForUser.LeftUpperCorner, areaForUser.RightBottomCorner, areaForUser.Source.Text, areaForUser.Translation.Text); isSuccess = false; continue; } var newRepresentationArea = new RepresentationAreaForUser(representationArea) { Source = areaForUser.Source, Translation = areaForUser.Translation }; result.AddArea(newRepresentationArea); } if (isSuccess) { //удалить слова из группы, которые не были переданы в этот раз в группу DeleteOldVisualWords(c, result); } }); return(isSuccess ? result : null); }
private WordsByPattern GetKeyboardLayoutResult(UserLanguages userLanguages, string query, WordsQuery wordsQuery) { var keyboardLayoutConverter = new KeyboardLayoutConverter(); List <string> convertedQueries = keyboardLayoutConverter.Convert(query); foreach (string convertedQuery in convertedQueries) { WordsByPattern result = wordsQuery.GetLikeWords(userLanguages, convertedQuery, WordType); if (EnumerableValidator.IsNotEmpty(result.Words)) { result.NewPattern = convertedQuery; return(result); } } return(new WordsByPattern()); }
private List <PronunciationForUser> GetTranslationsByQuery(UserLanguages userLanguages, string query) { var wordsQuery = new WordsQuery(); return(wordsQuery.GetTranslations(userLanguages, query, WordType)); }