private static void Main() { TaskScheduler.UnobservedTaskException += (sender, args) => Console.WriteLine($"Unobserved ex {args.Exception}"); _settings = ReadConfiguration(); var yandexDictionaryClient = new YandexDictionaryApiClient(_settings.YadicapiKey, _settings.YadicapiTimeout); var yandexTranslateApiClient = new YandexTranslateApiClient(_settings.YatransapiKey, _settings.YatransapiTimeout); var client = new MongoClient(_settings.MongoConnectionString); var db = client.GetDatabase("SayWhatDb"); var userWordRepo = new UserWordsRepo(db); var dictionaryRepo = new DictionaryRepo(db); var userRepo = new UsersRepo(db); var examplesRepo = new ExamplesRepo(db); userWordRepo.UpdateDb(); dictionaryRepo.UpdateDb(); userRepo.UpdateDb(); examplesRepo.UpdateDb(); _userWordService = new UsersWordsService(userWordRepo, examplesRepo); _dictionaryService = new DictionaryService(dictionaryRepo, examplesRepo); _userService = new UserService(userRepo); _addWordService = new AddWordService( _userWordService, yandexDictionaryClient, yandexTranslateApiClient, _dictionaryService, _userService); QuestionSelector.Singletone = new QuestionSelector(_dictionaryService); Console.WriteLine("Dic started"); _botClient = new TelegramBotClient(_settings.TelegramToken); var me = _botClient.GetMeAsync().Result; Console.WriteLine( $"Hello, World! I am user {me.Id} and my name is {me.FirstName}." ); _botClient.OnUpdate += BotClientOnOnUpdate; _botClient.OnMessage += Bot_OnMessage; _botClient.StartReceiving(); // workaround for infinity awaiting new TaskCompletionSource <bool>().Task.Wait(); // it will never happens _botClient.StopReceiving(); }
public UsersWordsService(UserWordsRepo repository, ExamplesRepo examplesRepo) { _userWordsRepository = repository; _examplesRepo = examplesRepo; }
static void Main(string[] args) { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false); IConfigurationRoot configuration = builder.Build(); var yadicapiKey = configuration.GetSection("yadicapi").GetSection("key").Value; var yadicapiTimeout = TimeSpan.FromSeconds(5); //Configuration.GetValue<TimeSpan>("yadicapi:timeout"); var dbFileName = configuration.GetSection("wordDb").Value; var yatransapiKey = configuration.GetSection("yatransapi").GetSection("key").Value; var yatransapiTimeout = TimeSpan.FromSeconds(5); //Configuration.GetValue<TimeSpan>("yatransapi:timeout"); var yapiDicClient = new YandexDictionaryApiClient(yadicapiKey, yadicapiTimeout); var yapiTransClient = new YandexTranslateApiClient(yatransapiKey, yatransapiTimeout); var dicRepo = new DictionaryRepository(dbFileName); var examsAndMetricRepo = new ExamsAndMetricsRepo(dbFileName); var userRepo = new UserRepo(dbFileName); var userWordRepo = new UserWordsRepo(dbFileName); var dictionaryService = new DictionaryService(dicRepo); var examsAndMetricService = new ExamsAndMetricService(examsAndMetricRepo); var userService = new UserService(userRepo); var userWordService = new UsersWordService(userWordRepo); DoMigration.ApplyMigrations(dbFileName); var modes = new IConsoleMode[] { // new ExamMode(userWordService,userService,examsAndMetricService), new WordAdditionMode(yapiTransClient, yapiDicClient, userWordService, dictionaryService), // new GraphsStatsMode(), // new RandomizeMode(), // new AddPhraseToWordsMode(yapiDicClient), }; // Console.Clear(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(@" ____ _ _ ____ ___ _ ____ _ _ ____ ___ ____ _ | |__| | | | | [__ |_/ |__| / |__| | |___ | | |__| | | ___] | \_ | | /__ | | |___ (test) "); Console.ResetColor(); //Registration user ConsoleKeyInfo val; int choice; User user = null; while (user == null) { Console.WriteLine(); Console.WriteLine("ESC: Quit"); Console.WriteLine("1: NewUser"); Console.WriteLine("2: Login"); Console.WriteLine(); Console.Write("Choose action:"); val = Console.ReadKey(); Console.WriteLine(); choice = ((int)val.Key - (int)ConsoleKey.D1) + 1; if (choice == 1) { user = Autorize.CreateNewUser(userService); if (user != null) { Console.WriteLine("New user has been added!"); Console.WriteLine($"Hello, {user.Name}. Press any key to continue."); } else { Console.WriteLine("Error in registration. Try again."); } } if (choice == 2) { user = Autorize.LoginUser(userService); if (user != null) { Console.WriteLine($"Hello, {user.Name}"); } else { Console.WriteLine("Wrong Password or Name. Try again."); } } Console.ReadKey(); } Console.Clear(); /* var users = userRepo.GetAllUsers(); * foreach(var us in users) * { * Console.WriteLine(us.Name + ":" + us.Login + ":" + us.Password); * } */ while (true) { Console.WriteLine(); Console.WriteLine("ESC: Quit"); for (int i = 0; i < modes.Length; i++) { Console.WriteLine($"{i + 1}: {modes[i].Name}"); } Console.WriteLine(); Console.Write("Choose mode:"); val = Console.ReadKey(); Console.WriteLine(); if (val.Key == ConsoleKey.Escape) { return; } choice = ((int)val.Key - (int)ConsoleKey.D1); if (choice > -1 && choice < modes.Length) { var selected = modes[choice]; Console.Clear(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("====== " + selected.Name + " ======"); Console.ResetColor(); modes[choice].Enter(user); } Console.WriteLine(); Console.WriteLine("==========================================="); } }
public void Intitalize() { MongoTestHelper.DropAllCollections(); _repo = new UserWordsRepo(MongoTestHelper.Database); _repo.UpdateDb().Wait(); }
public UsersWordsService(UserWordsRepo repository) => _userWordsRepository = repository;
private static void Main() { TaskScheduler.UnobservedTaskException += (sender, args) => Console.WriteLine($"Unobserved ex {args.Exception}"); _settings = ReadConfiguration(substitudeDebugConfig: false); var yandexDictionaryClient = new YandexDictionaryApiClient(_settings.YadicapiKey, _settings.YadicapiTimeout); var client = new MongoClient(_settings.MongoConnectionString); var db = client.GetDatabase(_settings.MongoDbName); //StatsMigrator.Do(db).Wait(); var userWordRepo = new UserWordsRepo(db); var dictionaryRepo = new LocalDictionaryRepo(db); var userRepo = new UsersRepo(db); var examplesRepo = new ExamplesRepo(db); var questionMetricsRepo = new QuestionMetricRepo(db); var learningSetsRepo = new LearningSetsRepo(db); userWordRepo.UpdateDb(); dictionaryRepo.UpdateDb(); userRepo.UpdateDb(); examplesRepo.UpdateDb(); questionMetricsRepo.UpdateDb(); learningSetsRepo.UpdateDb(); Botlog.QuestionMetricRepo = questionMetricsRepo; _userWordService = new UsersWordsService(userWordRepo, examplesRepo); _localDictionaryService = new LocalDictionaryService(dictionaryRepo, examplesRepo); _userService = new UserService(userRepo); _learningSetService = new LearningSetService(learningSetsRepo); _addWordService = new AddWordService( _userWordService, yandexDictionaryClient, _localDictionaryService, _userService); QuestionSelector.Singletone = new QuestionSelector(_localDictionaryService); _botClient = new TelegramBotClient(_settings.TelegramToken); Botlog.CreateTelegramLogger(_settings.BotHelperToken, _settings.ControlPanelChatId); var me = _botClient.GetMeAsync().Result; Botlog.WriteInfo($"Waking up. I am {me.Id}:{me.Username} ", true); _botClient.SetMyCommandsAsync(new[] { new BotCommand { Command = BotCommands.Help, Description = "Help and instructions (Помощь и инстркции)" }, new BotCommand { Command = BotCommands.Start, Description = "Main menu (Главное меню)" }, new BotCommand { Command = BotCommands.Translate, Description = "Translator (Переводчик)" }, new BotCommand { Command = BotCommands.Learn, Description = "Learning translated words (Учить слова)" }, new BotCommand { Command = BotCommands.New, Description = "Show learning sets (Показать наборы для изучения)" }, new BotCommand { Command = BotCommands.Stats, Description = "Your stats (Твоя статистика)" }, new BotCommand { Command = BotCommands.Words, Description = "Your learned words (Твои выученные слова)" }, new BotCommand { Command = BotCommands.Chlang, Description = "Change interface language (Сменить язык интерфейса)" }, }).Wait(); var allUpdates = _botClient.GetUpdatesAsync().Result; Botlog.WriteInfo($"{allUpdates.Length} messages were missed"); foreach (var update in allUpdates) { OnBotWokeUp(update); } if (allUpdates.Any()) { _botClient.MessageOffset = allUpdates.Last().Id + 1; Botlog.WriteInfo($"{Chats.Count} users were waiting for us"); } _botClient.OnUpdate += BotClientOnOnUpdate; _botClient.OnMessage += Bot_OnMessage; _botClient.StartReceiving(); Botlog.WriteInfo($"... and here i go!", false); // workaround for infinity awaiting new TaskCompletionSource <bool>().Task.Wait(); // it will never happens _botClient.StopReceiving(); }