public GeneratorModel(ControllerContext controllerContext, Dictionary <KnowledgeDataType, List <GeneratedKnowledgeItem> > items) { HtmlItems = new List <string>(); IEnumerable <GeneratedKnowledgeItem> generatedWords = GetGeneratedItems(KnowledgeDataType.WordTranslation, items); List <SourceWithTranslation> words = generatedWords.Select(e => (SourceWithTranslation)e.ParsedData).ToList(); if (EnumerableValidator.IsNotNullAndNotEmpty(words)) { HtmlItems.Add(GetHtml(controllerContext, KnowledgeDataType.WordTranslation, words)); } IEnumerable <GeneratedKnowledgeItem> generatedPhrases = GetGeneratedItems( KnowledgeDataType.PhraseTranslation, items); List <SourceWithTranslation> phrases = generatedPhrases.Select(e => (SourceWithTranslation)e.ParsedData).ToList(); if (EnumerableValidator.IsNotNullAndNotEmpty(phrases)) { HtmlItems.Add(GetHtml(controllerContext, KnowledgeDataType.PhraseTranslation, phrases)); } IEnumerable <GeneratedKnowledgeItem> generatedSentences = GetGeneratedItems(KnowledgeDataType.SentenceTranslation, items); List <SourceWithTranslation> sentences = generatedSentences.Select(e => (SourceWithTranslation)e.ParsedData).ToList(); if (EnumerableValidator.IsNotNullAndNotEmpty(sentences)) { HtmlItems.Add(GetHtml(controllerContext, KnowledgeDataType.SentenceTranslation, sentences)); } }
private void LoadLanguages() { if (EnumerableValidator.IsNotNullAndNotEmpty(_languages)) { //ранее уже загрузили языки return; } Adapter.ActionByContext(c => { _languages = c.Language.ToList(); _languagesByIds = new Dictionary <long, Language>(_languages.Count); _languagesByShortNames = new Dictionary <LanguageShortName, Language>(_languages.Count); foreach (Language language in _languages) { LanguageShortName parsedShortName = ParseShortName(language.ShortName); if (parsedShortName == LanguageShortName.Unknown) { continue; } _languagesByIds.Add(language.Id, language); _languagesByShortNames.Add(parsedShortName, language); } }); }
/// <summary> /// Конструктор /// </summary> /// <param name="video">данные о видео</param> internal VideoForUser(Data.Video.Video video) : this(video.Title, video.HtmlCode) { Id = video.Id; HasImage = EnumerableValidator.IsNotNullAndNotEmpty(video.Image); SortInfo = new SortInfo(video); }
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 List <ExternalInterview> GetQuestions() { List <Interview> interviews = Adapter.ReadByContext(c => c.Interview.OrderBy(e => e.ParentInterviewId).ToList()); var result = new Dictionary <long, ExternalInterview>(); foreach (Interview interview in interviews) { if (interview.ParentInterviewId == null) { result.Add(interview.Id, new ExternalInterview(interview.Id, interview.Text)); continue; } long parentId = interview.ParentInterviewId.Value; ExternalInterview question; if (!result.TryGetValue(parentId, out question)) { LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat( "InterviewsQuery.GetQuestions не найден родитель с идентификатором {0}!", parentId); continue; } question.AddAnswer(interview.Id, interview.Text); } return(result.Values.Where(e => EnumerableValidator.IsNotNullAndNotEmpty(e.Answers)).OrderBy(e => e.Id).ToList()); }
private void AddToResult <TElem>(SectionId sectionId, Func <List <TElem> > getterElements, Func <TElem, Tuple <long, string, DateTime> > converter, Dictionary <SectionId, List <Tuple <long, string, DateTime> > > result) { if (_forbiddenSectionsChecker(sectionId)) { return; } List <TElem> data = getterElements(); if (EnumerableValidator.IsNotNullAndNotEmpty(data)) { result.Add(sectionId, data.Select(converter).OrderBy(e => e.Item2).ToList()); } }
public GroupForUser(Group group) : this(group.Id, group.Name, EnumerableValidator.IsNotNullAndNotEmpty(group.Image)) { SortInfo = new SortInfo(group); }
internal PronunciationForUser(PronunciationEntity pronunciation) : this( pronunciation.Id, pronunciation.Text, EnumerableValidator.IsNotNullAndNotEmpty(pronunciation.Pronunciation), pronunciation.LanguageId) { }
/// <summary> /// Определяет есть ли подменю /// </summary> public bool HasChildren() { return(EnumerableValidator.IsNotNullAndNotEmpty(Children)); }