internal RepresentationAreaForUser(RepresentationArea representationArea)
     : this(
         representationArea.Id, new Point(representationArea.LeftUpperX, representationArea.LeftUpperY),
         new Point(representationArea.RightBottomX, representationArea.RightBottomY))
 {
     WordTranslationId = representationArea.WordTranslationId;
 }
Esempio n. 2
0
        private static RepresentationArea GetOrCreateArea(StudyLanguageContext c,
                                                          long representationId,
                                                          long wordTranslationId,
                                                          RepresentationAreaForUser areaForUser)
        {
            RepresentationArea representationArea = c.RepresentationArea
                                                    .FirstOrDefault(e => e.RepresentationId == representationId && e.WordTranslationId == wordTranslationId);

            if (representationArea == null)
            {
                representationArea = new RepresentationArea {
                    RepresentationId  = representationId,
                    WordTranslationId = wordTranslationId
                };
                c.RepresentationArea.Add(representationArea);
            }

            representationArea.LeftUpperX   = areaForUser.LeftUpperCorner.X;
            representationArea.LeftUpperY   = areaForUser.LeftUpperCorner.Y;
            representationArea.RightBottomX = areaForUser.RightBottomCorner.X;
            representationArea.RightBottomY = areaForUser.RightBottomCorner.Y;
            c.SaveChanges();

            return(representationArea);
        }
Esempio n. 3
0
        /// <summary>
        /// Получает представление по названию
        /// </summary>
        /// <param name="userLanguages">языковые настройки пользователя</param>
        /// <param name="title">название представления</param>
        /// <returns>представление или null если не найдено</returns>
        public RepresentationForUser GetWithAreas(UserLanguages userLanguages, string title)
        {
            long sourceLanguageId      = userLanguages.From.Id;
            long translationLanguageId = userLanguages.To.Id;

            RepresentationForUser result = Adapter.ReadByContext(c => {
                var representationsQuery = (from r in c.Representation
                                            join ra in c.RepresentationArea on r.Id equals
                                            ra.RepresentationId
                                            join wt in c.WordTranslation on ra.WordTranslationId equals wt.Id
                                            join w1 in c.Word on wt.WordId1 equals w1.Id
                                            join w2 in c.Word on wt.WordId2 equals w2.Id
                                            where r.Title == title && r.LanguageId == _languageId &&
                                            ((w1.LanguageId == sourceLanguageId &&
                                              w2.LanguageId == translationLanguageId)
                                             ||
                                             (w1.LanguageId == translationLanguageId &&
                                              w2.LanguageId == sourceLanguageId))
                                            orderby ra.Rating descending
                                            select new { r, ra, w1, w2 });
                var representationsInfos = representationsQuery.AsEnumerable();
                var firstRepresentation  = representationsInfos.FirstOrDefault();
                if (firstRepresentation == null)
                {
                    return(null);
                }
                var innerResult = new RepresentationForUser(firstRepresentation.r);
                foreach (var representationsInfo in representationsInfos)
                {
                    RepresentationArea repArea = representationsInfo.ra;

                    Tuple <PronunciationForUser, PronunciationForUser> tuple =
                        GroupingHelper.GroupByLanguages(sourceLanguageId,
                                                        representationsInfo.w1,
                                                        representationsInfo.w2);

                    var area = new RepresentationAreaForUser(repArea)
                    {
                        Source = tuple.Item1, Translation = tuple.Item2
                    };
                    innerResult.AddArea(area);
                }
                return(innerResult);
            });

            return(result);
        }
        private Tuple <UserKnowledge, UserRepetitionInterval> ConvertRow(RepresentationArea area,
                                                                         UserRepetitionInterval userRepetitionInterval)
        {
            DateTime minDateTime   = new DateTime().GetDbDateTime();
            var      userKnowledge = new UserKnowledge {
                Id           = area.Id,
                DataId       = area.WordTranslationId,
                DataType     = _dataType,
                Data         = null,
                UserId       = _userId,
                LanguageId   = _languageId,
                CreationDate = minDateTime,
                DeletedDate  = minDateTime,
                Hash         = null,
                Tip          = null,
                SystemData   = null,
                Status       = (int)KnowledgeStatus.Unknown
            };

            return(new Tuple <UserKnowledge, UserRepetitionInterval>(userKnowledge, userRepetitionInterval));
        }
Esempio n. 5
0
        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);
        }