Example #1
0
        private SourceWithTranslation Create(GroupForUser groupForUser,
                                             SourceWithTranslation sentenceWithTranslation,
                                             int?rating)
        {
            SourceWithTranslation result = null;

            Adapter.ActionByContext(context => {
                var groupSentence = new GroupSentence
                {
                    SentenceTranslationId = sentenceWithTranslation.Id, GroupId = groupForUser.Id, Rating = rating
                };
                context.GroupSentence.Add(groupSentence);
                context.SaveChanges();
                if (IdValidator.IsValid(groupSentence.Id))
                {
                    result = new SourceWithTranslation();
                    result.Set(groupSentence.Id, sentenceWithTranslation.Source, sentenceWithTranslation.Translation);
                }
                else
                {
                    LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                        "GroupSentencesQuery.Create can't add sentence with translation for sentence with id {0}, translation with id {1}, rating {2}",
                        sentenceWithTranslation.Source.Id, sentenceWithTranslation.Translation.Id,
                        rating);
                }
            });
            return(result);
        }
Example #2
0
        public SourceWithTranslation GetOrCreate(SentenceType type,
                                                 PronunciationForUser source,
                                                 PronunciationForUser translation,
                                                 byte[] image,
                                                 int?rating = null)
        {
            //TODO: проверять корректность параметров
            SourceWithTranslation result = null;

            Adapter.ActionByContext(context => {
                SentenceTranslation sentenceTranslation = GetSentenceTranslation(context, source, translation);
                if (sentenceTranslation != null)
                {
                    //обновить возможно изменившиеся поля
                    SetSentenceTranslation(sentenceTranslation, type, image, rating);
                    context.SaveChanges();
                    if (IdValidator.IsValid(sentenceTranslation.Id))
                    {
                        result = new SourceWithTranslation();
                        result.Set(sentenceTranslation.Id, source, translation);
                    }
                }
                else
                {
                    result = CreateSentencencesWithTranslation(type, source, translation, image, rating);
                }
            });
            return(result);
        }
Example #3
0
        private static SourceWithTranslation GetSource(string source, string translation = "translation bla-bla")
        {
            var result = new SourceWithTranslation();

            result.Set(84746, new PronunciationForUser(837, source, true, 31),
                       new PronunciationForUser(33, translation, false, 47));
            return(result);
        }
Example #4
0
        public static SourceWithTranslation ConvertToSourceWithTranslation(long id,
                                                                           byte[] image,
                                                                           PronunciationForUser pronunciation1,
                                                                           PronunciationForUser pronunciation2)
        {
            var result = new SourceWithTranslation();

            result.Set(id, pronunciation1, pronunciation2);
            result.HasImage = image != null && image.Length > 0;
            return(result);
        }
Example #5
0
        public void ConvertVisualDictionaries()
        {
            LoadLanguages();

            var representationsQuery = new RepresentationsQuery(_userLanguages.To.Id);
            Dictionary <long, string> visibleDictionaries =
                representationsQuery.GetVisibleWithoutAreas().ToDictionary(e => e.Id, e => e.Title);

            foreach (var visualDictionary in visibleDictionaries)
            {
                long id = visualDictionary.Key;
                if (!visibleDictionaries.ContainsKey(id))
                {
                    continue;
                }

                string title    = visibleDictionaries[id];
                string fileName =
                    string.Format(@"C:\Projects\StudyLanguages\Источники визуального словаря\{0}\Xml\{1}.xml",
                                  _languageTo, title);

                if (File.Exists(fileName))
                {
                    Console.WriteLine("Визуальный словарь \"{0}\" уже существует - пропустить", title);
                    continue;
                }

                Console.WriteLine("Начали обрабатывать визуальный словарь \"{0}\"", title);

                RepresentationForUser representation = representationsQuery.GetWithAreas(_userLanguages,
                                                                                         visualDictionary.Value);
                if (representation == null)
                {
                    Console.WriteLine(
                        "Не удалось получить данные из словаря \"{0}\" - пропустить. Нажмите enter для продолжения...",
                        title);
                    Console.ReadLine();
                    continue;
                }
                List <SourceWithTranslation> words =
                    representation.Areas.Select(e => {
                    var sourceWithTranslation = new SourceWithTranslation();
                    sourceWithTranslation.Set(e.WordTranslationId, e.Source, e.Translation);
                    return(sourceWithTranslation);
                }).ToList();

                SaveConvertedWords(fileName, words);
            }

            Console.WriteLine(
                "Переконвертировали визуальные словари. Воспользовались дополнительными словарями {0} раз",
                _translator.CountExtraCalls);
        }
Example #6
0
        private ComparisonRuleExampleForUser GetComparisonExampleForUser(XElement xExample)
        {
            string source             = GetChildElementValue(xExample, "source");
            string translation        = GetChildElementValue(xExample, "translation");
            string descriptionExample = GetChildElementValue(xExample, "description");

            var sourceWithTranslation = new SourceWithTranslation();

            sourceWithTranslation.Set(IdValidator.INVALID_ID,
                                      new PronunciationForUser(IdValidator.INVALID_ID,
                                                               TextFormatter.FirstUpperCharAndTrim(source), false,
                                                               _englishId),
                                      new PronunciationForUser(IdValidator.INVALID_ID,
                                                               TextFormatter.FirstUpperCharAndTrim(translation), false,
                                                               _russianId));
            return(new ComparisonRuleExampleForUser(sourceWithTranslation,
                                                    TextFormatter.FirstUpperCharAndTrim(descriptionExample)));
        }
Example #7
0
        private SourceWithTranslation Create(WordWithTranslation wordWithTranslation, int type)
        {
            SourceWithTranslation result = null;

            Adapter.ActionByContext(context => {
                var popularWord = new PopularWord
                {
                    WordTranslationId = wordWithTranslation.Id, Type = type
                };
                context.PopularWord.Add(popularWord);
                context.SaveChanges();
                if (IdValidator.IsValid(popularWord.Id))
                {
                    result = new SourceWithTranslation();
                    result.Set(popularWord.Id, wordWithTranslation.Source, wordWithTranslation.Translations[0]);
                }
            });
            return(result);
        }
Example #8
0
        private SourceWithTranslation Create(GroupForUser groupForUser,
                                             WordWithTranslation wordWithTranslation,
                                             int?rating)
        {
            SourceWithTranslation result = null;

            Adapter.ActionByContext(context => {
                var groupWord = new GroupWord
                {
                    WordTranslationId = wordWithTranslation.Id, GroupId = groupForUser.Id, Rating = rating
                };
                context.GroupWord.Add(groupWord);
                context.SaveChanges();
                if (IdValidator.IsValid(groupWord.Id))
                {
                    result = new SourceWithTranslation();
                    result.Set(groupWord.Id, wordWithTranslation.Source, wordWithTranslation.Translations[0]);
                }
            });
            return(result);
        }
Example #9
0
        /// <summary>
        /// Из двух энтитей создает энтити с переводом
        /// </summary>
        /// <param name="id">уникальный идентификатор энтити с переводом</param>
        /// <param name="image">изображение, если есть</param>
        /// <param name="sourceLanguageId">язык, с которого нужно переводить</param>
        /// <param name="pronunciation1">первая энтити</param>
        /// <param name="pronunciation2">втора энтити</param>
        /// <returns>энтити с переводом</returns>
        public static SourceWithTranslation ConvertToSourceWithTranslation(long id,
                                                                           byte[] image,
                                                                           long sourceLanguageId,
                                                                           PronunciationEntity pronunciation1,
                                                                           PronunciationEntity pronunciation2)
        {
            var result = new SourceWithTranslation();
            PronunciationEntity source;
            PronunciationEntity translation;

            if (pronunciation1.LanguageId == sourceLanguageId)
            {
                source      = pronunciation1;
                translation = pronunciation2;
            }
            else
            {
                source      = pronunciation2;
                translation = pronunciation1;
            }
            result.Set(id, source, translation);
            result.HasImage = image != null && image.Length > 0;
            return(result);
        }