public ActionResult Index(UserLanguages userLanguages) { const int COUNT = 5; if (UserLanguages.IsInvalid(userLanguages)) { return(RedirectToAction("Unknown", "Errors")); } var model = new MainModel(); long languageId = WebSettingsConfig.Instance.GetLanguageFromId(); //слова по темам AddSectionIfNeed(SectionId.GroupByWords, model, () => { IGroupsQuery groupsQuery = new GroupsQuery(languageId); List <GroupForUser> groups = groupsQuery.GetVisibleGroups(GroupType.ByWord, COUNT); return(new DescriptionSection { Title = new DescriptionTitle { Title = "Слова по темам", Url = Url.Action("Index", RouteConfig.GROUPS_BY_WORDS_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти ко всем темам" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.GroupByWordsDescription), MostPopularTitle = "5 наиболее популярных тем:", Items = ConvertToItems(groups, e => e.Name), TitleItemGetter = item => WebSettingsConfig.Instance.GetTemplateText(SectionId.GroupByWords, PageId.Index, TemplateId.ItemTipOnMainPage, item.Title), UrlItemGetter = item => @Url.Action("Index", RouteConfig.GROUP_WORD_CONTROLLER, new { group = item.Title + "/" }, Request.Url.Scheme), UrlImageItemGetter = item => Url.Action("GetImageByName", RouteConfig.GROUP_WORD_CONTROLLER, new { group = item.Title }, Request.Url.Scheme), //Btn = BtnModel.CreateBuyAllMaterials(Url, "btn btn-danger btn-xs buy-btn-main") }); }); //почувствуй разницу AddSectionIfNeed(SectionId.FillDifference, model, () => { IComparisonsQuery comparisonsQuery = new ComparisonsQuery(languageId); List <ComparisonForUser> comparisons = comparisonsQuery.GetVisibleWithoutRules(COUNT); return(new DescriptionSection { Title = new DescriptionTitle { Title = "Почувствуй разницу", Url = Url.Action("Index", RouteConfig.GROUPS_BY_COMPARISONS_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти ко всем правилам употребления" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.FillDifferenceDescription), MostPopularTitle = "5 наиболее популярных тем сравнения:", Items = ConvertToItems(comparisons, e => e.Title), TitleItemGetter = item => WebSettingsConfig.Instance.GetTemplateText(SectionId.FillDifference, PageId.Index, TemplateId.ItemTipOnMainPage, item.Title), UrlItemGetter = item => Url.Action("Index", RouteConfig.COMPARISON_CONTROLLER, new { group = item.Title + "/" }, Request.Url.Scheme) }); }); //минилекс слов AddSectionIfNeed(SectionId.PopularWord, model, () => { return(new DescriptionSection { Title = new DescriptionTitle { Title = "Минилекс слов", Url = Url.Action("Index", RouteConfig.POPULAR_WORDS_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти к минилексу слов Гуннемарка" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.PopularWordDescription) }); }); //визуальные словари AddSectionIfNeed(SectionId.VisualDictionary, model, () => { IRepresentationsQuery representationsQuery = new RepresentationsQuery(languageId); List <RepresentationForUser> visibleDictionaries = representationsQuery.GetVisibleWithoutAreas(COUNT); return(new DescriptionSection { Title = new DescriptionTitle { Title = "Визуальные словари", Url = Url.Action("Index", RouteConfig.VISUAL_DICTIONARIES_CONTROLLER_NAME, null, Request.Url.Scheme), Description = "Перейти ко всем визуальным словарям" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.VisualDictionaryDescription), MostPopularTitle = "5 наиболее популярных визуальных словарей:", Items = ConvertToItems(visibleDictionaries, e => e.Title), TitleItemGetter = item => WebSettingsConfig.Instance.GetTemplateText(SectionId.VisualDictionary, PageId.Index, TemplateId.ItemTipOnMainPage, item.Title), UrlItemGetter = item => Url.Action("Index", RouteConfig.VISUAL_DICTIONARY_CONTROLLER, new { group = item.Title + "/" }, Request.Url.Scheme), UrlImageItemGetter = item => Url.Action("GetImageByName", RouteConfig.VISUAL_DICTIONARY_CONTROLLER, new { group = item.Title }, Request.Url.Scheme), //Btn = BtnModel.CreateBuyVisualDictionaries(Url, "btn btn-danger btn-xs buy-btn-main") }); }); AddSectionIfNeed(SectionId.GroupByPhrases, model, () => { //фразы по темам IGroupsQuery groupsQuery = new GroupsQuery(languageId); List <GroupForUser> groups = groupsQuery.GetVisibleGroups(GroupType.BySentence, COUNT); return(new DescriptionSection { Title = new DescriptionTitle { Title = "Фразы по темам", Url = Url.Action("Index", RouteConfig.GROUPS_BY_SENTENCES_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти ко всем темам" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.GroupByPhrasesDescription), MostPopularTitle = "5 наиболее популярных тем:", Items = ConvertToItems(groups, e => e.Name), TitleItemGetter = item => WebSettingsConfig.Instance.GetTemplateText(SectionId.GroupByPhrases, PageId.Index, TemplateId.ItemTipOnMainPage, item.Title), UrlItemGetter = item => @Url.Action("Index", RouteConfig.GROUP_SENTENCE_CONTROLLER, new { group = item.Title + "/" }, Request.Url.Scheme), UrlImageItemGetter = item => Url.Action("GetImageByName", RouteConfig.GROUP_SENTENCE_CONTROLLER, new { group = item.Title }, Request.Url.Scheme), }); }); //стена знания AddSectionIfNeed(SectionId.MyKnowledge, model, () => new DescriptionSection { Title = new DescriptionTitle { Title = "Стена знаний", Url = Url.Action("Index", RouteConfig.USER_KNOWLEDGE_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти к стене с Вашими знаниями" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.MyKnowledgeDescription), Items = null, }); //генератор знаний AddSectionIfNeed(SectionId.KnowledgeGenerator, model, () => new DescriptionSection { Title = new DescriptionTitle { Title = "Генератор знаний", Url = Url.Action("Index", RouteConfig.KNOWLEDGE_GENERATOR_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти к генератору знаний" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.KnowledgeGeneratorDescription), Items = null, }); //видео AddSectionIfNeed(SectionId.Video, model, () => { IVideosQuery videosQuery = new VideosQuery(languageId); List <VideoForUser> videos = videosQuery.GetVisible(VideoType.Clip, COUNT); return(new DescriptionSection { Title = new DescriptionTitle { Title = "Видеоролики", Url = Url.Action("Index", RouteConfig.VIDEO_CONTROLLER, new { type = VideoType.Clip }, Request.Url.Scheme), Description = "Перейти ко всем видеороликам" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.VideoDescription), MostPopularTitle = "5 наиболее популярных видеороликов:", Items = ConvertToItems(videos, e => e.Title), TitleItemGetter = item => WebSettingsConfig.Instance.GetTemplateText(SectionId.Video, PageId.Index, TemplateId.ItemTipOnMainPage, item.Title), UrlItemGetter = item => @Url.Action("Detail", RouteConfig.VIDEO_CONTROLLER, new { group = item.Title + "/" }, Request.Url.Scheme), UrlImageItemGetter = item => Url.Action("GetImageByName", RouteConfig.VIDEO_CONTROLLER, new { group = item.Title }, Request.Url.Scheme), }); }); //задания AddSectionIfNeed(SectionId.UserTasks, model, () => { return(new DescriptionSection { Title = new DescriptionTitle { Title = "Задания", Url = Url.Action("Index", RouteConfig.USER_TASKS_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти к заданиям пользователей" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.UserTasksDescription) }); }); //предложения AddSectionIfNeed(SectionId.Sentences, model, () => new DescriptionSection { Title = new DescriptionTitle { Title = "Предложения", Url = Url.Action("Index", RouteConfig.HOME_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти к предложениям" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.SentencesDescription), Items = null, }); //аудирование AddSectionIfNeed(SectionId.Audio, model, () => new DescriptionSection { Title = new DescriptionTitle { Title = "Аудирование", Url = Url.Action("Index", RouteConfig.AUDIO_WORDS_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти к аудированию" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.AudioDescription), Items = null, }); //перевод слов AddSectionIfNeed(SectionId.WordTranslation, model, () => new DescriptionSection { Title = new DescriptionTitle { Title = "Перевод слов", Url = Url.Action("Index", RouteConfig.WORDS_TRANSLATION_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти к переводу слов" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.WordTranslationDescription), Items = null, }); //перевод фразовых глаголов AddSectionIfNeed(SectionId.PhraseVerbTranslation, model, () => new DescriptionSection { Title = new DescriptionTitle { Title = "Перевод фразовых глаголов", Url = Url.Action("Index", RouteConfig.PHRASAL_VERBS_TRANLATION_CONTROLLER, null, Request.Url.Scheme), Description = "Перейти к переводу фразовых глаголов" }, Description = WebSettingsConfig.Instance.GetTemplateText(SectionId.Main, TemplateId.PhrasalVerbsTranslationDescription), Items = null, }); return(View(model)); }
public VisualDictionaryModel(UserLanguages userLanguages, RepresentationForUser representation) : base(userLanguages) { Representation = representation; }
public SearchesService(DiscordSocketClient client, IGoogleApiService google, DbService db, NadekoBot bot, IDataCache cache, FontProvider fonts) { Http = new HttpClient(); Http.AddFakeHeaders(); _client = client; _google = google; _db = db; _log = LogManager.GetCurrentClassLogger(); _imgs = cache.LocalImages; _cache = cache; _fonts = fonts; _blacklistedTags = new ConcurrentDictionary <ulong, HashSet <string> >( bot.AllGuildConfigs.ToDictionary( x => x.GuildId, x => new HashSet <string>(x.NsfwBlacklistedTags.Select(y => y.Tag)))); //translate commands _client.MessageReceived += (msg) => { var _ = Task.Run(async() => { try { var umsg = msg as SocketUserMessage; if (umsg == null) { return; } if (!TranslatedChannels.TryGetValue(umsg.Channel.Id, out var autoDelete)) { return; } var key = new UserChannelPair() { UserId = umsg.Author.Id, ChannelId = umsg.Channel.Id, }; if (!UserLanguages.TryGetValue(key, out string langs)) { return; } var text = await Translate(langs, umsg.Resolve(TagHandling.Ignore)) .ConfigureAwait(false); if (autoDelete) { try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { } } await umsg.Channel.SendConfirmAsync($"{umsg.Author.Mention} `:` " + text.Replace("<@ ", "<@").Replace("<@! ", "<@!")).ConfigureAwait(false); } catch { } }); return(Task.CompletedTask); }; //joke commands if (File.Exists("data/wowjokes.json")) { WowJokes = JsonConvert.DeserializeObject <List <WoWJoke> >(File.ReadAllText("data/wowjokes.json")); } else { _log.Warn("data/wowjokes.json is missing. WOW Jokes are not loaded."); } if (File.Exists("data/magicitems.json")) { MagicItems = JsonConvert.DeserializeObject <List <MagicItem> >(File.ReadAllText("data/magicitems.json")); } else { _log.Warn("data/magicitems.json is missing. Magic items are not loaded."); } }
protected abstract List <SourceWithTranslation> GetSourceWithTranslations(UserLanguages userLanguages, GroupForUser group);
public ActionResult Index(long userId, UserLanguages userLanguages, string group) { long representationId = GetRepresentationId(group); return(GetIndex(userId, userLanguages, representationId, model => SetModel(group, model))); }
public ActionResult Trainer(UserLanguages userLanguages, GroupForUser group) { return(GetTrainer(userLanguages, group)); }
protected abstract GroupModel GetModel(UserLanguages userLanguages, GroupForUser group);
public ActionResult Download(UserLanguages userLanguages, GroupForUser group, DocumentType type) { string fileName = string.Format("Слова на тему {0}", group.LowerName.ToLowerInvariant()); return(GetFile(userLanguages, group, type, fileName)); }
public ActionResult Index(UserLanguages userLanguages, GroupForUser group) { return(ShowAll(userLanguages, group, CrossReferenceType.GroupWord)); }
private static bool IsInvalid(long userId, UserLanguages userLanguages) { return(IdValidator.IsInvalid(userId) || UserLanguages.IsInvalid(userLanguages)); }
public abstract bool MarkAsShowed(long userId, UserLanguages userLanguages, long id);
protected BaseGroupsWriter(UserLanguages userLanguages, long languageId) { _userLanguages = userLanguages; _languageId = languageId; }
private List <PronunciationForUser> GetTranslationsByQuery(UserLanguages userLanguages, string query) { var wordsQuery = new WordsQuery(); return(wordsQuery.GetTranslations(userLanguages, query, WordType)); }
public void Configure() { string fullConfigName = Path.Combine(BasePathToWriteData, "WebSettings.xml"); if (_repositoryFactory != null) { try { _repositoryFactory.Reload(); } catch (Exception e) { LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat( "WebSettingsConfig.Configure при попытке перегрузить репозитории возникло исключение {0}", e); } } else { _repositoryFactory = new RepositoryFactory(new RepositoryCache(BasePathToWriteData)); } if (SalesPicturesCache != null) { SalesPicturesCache.ClearMemory(); } else { string salesPicturesPath = Path.Combine(BasePathToWriteData, "Caches", "Sales"); SalesPicturesCache = new DiskCache(salesPicturesPath); } if (CommonDiskCache != null) { CommonDiskCache.ClearMemory(); } else { string commonDiskPath = Path.Combine(BasePathToWriteData, "Caches", "Common"); CommonDiskCache = new DiskCache(commonDiskPath, false); } DefaultUserLanguages = null; var stream = new StreamReader(fullConfigName, Encoding.UTF8); XDocument document = XDocument.Load(stream); XElement root = document.Root; if (root == null) { //TODO: ругаться return; } Domain = XmlParseHelper.Get <string>(root, "Domain"); Logo = XmlParseHelper.Get <string>(root, "Logo"); CookieWideDomain = XmlParseHelper.Get <string>(root, "CookieWideDomain"); CanPronounce = XmlParseHelper.Get <bool>(root, "CanPronounce"); XElement defaultLanguages = root.Element("DefaultLanguages"); DefaultLanguageFrom = GetLanguage(defaultLanguages, "From"); DefaultLanguageTo = GetLanguage(defaultLanguages, "To"); AvailableSections = new HashSet <SectionId>(XmlParseHelper.GetList <SectionId>(root, "AvailableSections", "SectionId")); //TODO: проверить корректность конфига, если что-то не так, то ругаться LoadKeyboardKeys(root); YandexMetrikaId = XmlParseHelper.Get <string>(root, "YandexMetrikaId"); Counters = XmlParseHelper.Get <string>(root, "Counters"); //подгружаем другие домены, а также удаляем текущий домен LoadAnotherDomains(root); LoadSalesSettings(root); PathToTopBanner = XmlParseHelper.Get <string>(root, "Banners", "TopPath"); _templates.Load(root.Element("Patterns")); SetDeferredSettings(_deferredActions); MaxIDUserForTopMessage = XmlParseHelper.Get <long>(root, "MaxIDUserForTopMessage"); WebPath = HttpContext.Current != null?HttpContext.Current.Server.MapPath("~/") : null; _fullRightUserIds = new HashSet <long>(XmlParseHelper.GetList <long>(root, "FullRightUserId")); }
public JsonResult GetNextPortion(long userId, long id, UserLanguages userLanguages) { return(GetPortion(userId, id, userUnique => _query.GetNextPortion(userUnique, id, userLanguages))); }
public GroupWordsWriter(UserLanguages userLanguages, long languageId) : base(userLanguages, languageId) { }