public override async Task <bool> Contains(Message message, ApplicationContext context) { if (message.Type != MessageType.Text) { return(false); } var chat = message.Chat; var user = context.Users.FirstOrDefault(usr => usr.TelegramId == chat.Id); // Finding user in database // If user not registered if (user == null) { return(false); } if (Name == null) { Name = await context.Lines.FindAsync("changeLanguage"); } if (Langs.Count == 0) { foreach (UserLang lang in Enum.GetValues(typeof(UserLang))) { Langs.Add(lang.ToString()); } } return(Name.Contains(message.Text) || Langs.Contains(message.Text)); }
public Model() { // Strona językowa var users = SetOfUsers.GetAllUsers(); foreach (var user in users) { Users.Add(user); } var langs = SetOfLanguages.GetAllLanguages(); foreach (var lang in langs) { Langs.Add(lang); } var words = SetOfWords.GetAllWords(); foreach (var word in words) { Words.Add(word); } var wordKnowledges = SetOfWordKnwoledges.GetAllWordKnowledges(); foreach (var wks in wordKnowledges) { WordKnowledges.Add(wks); } // Strona Fiszki var flipcards = SetOfFlipCards.GetAllFlipCards(); foreach (var flipcard in flipcards) { FlipCards.Add(flipcard); } var flipCardKnowledges = SetOfFlipCardKnowledges.GetAllFlipCardKnowledges(); foreach (var flipCardKwl in flipCardKnowledges) { FlipCardKnowledges.Add(flipCardKwl); } var decks = SetOfDecks.GetAllDecks(); foreach (var deck in decks) { Decks.Add(deck); } }
public Lang AddLang(string name) { if (Langs.Any(l => l.Name.ToLower() == name.ToLower())) { return(Langs.FirstOrDefault(l => l.Name.ToLower() == name.ToLower())); } Langs.Add(new Lang { Id = Langs.Count != 0 ? Langs.Last().Id + 1 : 1, Name = name }); return(Langs.Last()); }
public bool LoadFromXmlResource(string langFolder) { try { if (!Directory.Exists(langFolder)) { return(false); } if (int.TryParse(SerializerHelper.LoadText(Path.Combine(langFolder, CurrentLangFile)), out int landId)) { Langs.Clear(); Words.Clear(); foreach (string lang in Directory.GetDirectories(langFolder)) { string name = new DirectoryInfo(lang).Name; if (int.TryParse(name.Substring(0, name.IndexOf('.')), out int id)) { name = name.Substring(name.IndexOf('.') + 1); Langs.Add(new Lang { Id = id, Name = name }); string text = SerializerHelper.LoadText(Path.Combine(lang, WordsFile)); while (!string.IsNullOrEmpty(text)) { if (text[0] == '<') { string key = text.Substring(1, text.IndexOf('>') - 1); string value = text.Substring(text.IndexOf('>') + 1, text.IndexOf($"</{key}>") - $"</{key}>".Length + 1); Word word = Words.FirstOrDefault(w => w.Key == key); if (word == null) { word = new Word { Key = key, Values = new Dictionary <int, string>() }; Words.Add(word); } if (word.Values.ContainsKey(id)) { word.Values[id] = value; } else { word.Values.Add(id, value); } text = text.Substring(key.Length * 2 + value.Length + 5).TrimStart('\r', '\n'); } } } } CurrentLang = Langs.FirstOrDefault(l => l.Id == landId) ?? Langs.FirstOrDefault(); return(true); } } catch (Exception ex) { Logger.Log(ex); } return(false); }
public async Task OnGetAsync() { if (VideoId == null) { throw new ArgumentNullException(nameof(VideoId)); } if (!VideoId.IsAbsolutelySafe()) { throw new ArgumentException(nameof(VideoId)); } if (Lang == null) { throw new ArgumentNullException(nameof(Lang)); } if (!Lang.IsAbsolutelySafe()) { throw new ArgumentException(nameof(Lang)); } if (!Request.Cookies.TryGetValue($"vtt-{VideoId}-url", out var vttUrl) || !Request.Cookies.TryGetValue($"vtt-{VideoId}-langs", out var vttLangs)) { var(vtts, title) = await Helpers.GetManifestDataAsync(VideoId, HttpContext.RequestAborted); if (!vtts.TryGetValue(Lang, out vttUrl)) { throw new ArgumentOutOfRangeException(nameof(Lang)); } // set list of languages from vtts.Keys foreach (var item in Languages.Items) { if (vtts.ContainsKey(item.Value)) { Langs.Add(item); } } Title = title; AdjustVttCookies(vtts, VideoId, Lang, title); } else { // set list of languages from vttLangs foreach (var item in Languages.Items) { if (vttLangs.Contains(item.Value)) { Langs.Add(item); } } Title = Request.Cookies[$"vtt-{VideoId}-title"]; } if (Title == null) { Title = $"#{VideoId}"; } using (var client = new HttpClient()) using (HttpContext.RequestAborted.Register(client.CancelPendingRequests)) using (var stream = await client.GetStreamAsync(vttUrl)) using (var reader = new StreamReader(stream)) { Lines = new List <string> (); while (true) { var line = await reader.ReadLineAsync(); if (line == null) { return; } Lines.Add(line); } } }