Exemple #1
0
        public async Task AddWordToDictionary_GetWithExampleReturnsSame()
        {
            MongoTestHelper.DropAllCollections();
            var dictionaryRepo = new DictionaryRepo(MongoTestHelper.Database);
            var examplesRepo   = new ExamplesRepo(MongoTestHelper.Database);
            var service        = new DictionaryService(dictionaryRepo, examplesRepo);
            var example        = new Example
            {
                Direction        = TranlationDirection.EnRu,
                Id               = ObjectId.GenerateNewId(),
                OriginWord       = "table",
                TranslatedWord   = "стол",
                OriginPhrase     = "What the table?",
                TranslatedPhrase = "Какого стола?"
            };
            var word = new DictionaryWord
            {
                Id            = ObjectId.GenerateNewId(),
                Word          = "table",
                Language      = Language.En,
                Source        = TranslationSource.Yadic,
                Transcription = "qweqwe",
                Translations  = new[]
                {
                    new DictionaryTranslation
                    {
                        Word     = "Стол",
                        Language = Language.Ru,
                        Examples = new []
                        {
                            new DictionaryReferenceToExample()
                            {
                                ExampleId     = example.Id,
                                ExampleOrNull = example,
                            }
                        }
                    }
                }
            };
            await service.AddNewWord(word);

            var translations = await service.GetTranslationsWithExamples("table");

            Assert.AreEqual(1, translations.Count);
            var translation = translations[0];

            Assert.AreEqual(word.Source, translation.Source);
            Assert.AreEqual(word.Transcription, translation.EnTranscription);
            Assert.AreEqual(word.Word, translation.EnWord);
            Assert.AreEqual(word.Translations[0].Word, translation.RuWord);

            Assert.AreEqual(example.OriginWord, translation.Examples[0].OriginWord);
            Assert.AreEqual(example.OriginPhrase, translation.Examples[0].OriginPhrase);
            Assert.AreEqual(example.TranslatedWord, translation.Examples[0].TranslatedWord);
            Assert.AreEqual(example.TranslatedPhrase, translation.Examples[0].TranslatedPhrase);
        }
Exemple #2
0
        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();
        }
Exemple #3
0
 public void Intitalize()
 {
     MongoTestHelper.DropAllCollections();
     _repo = new ExamplesRepo(MongoTestHelper.Database);
     _repo.UpdateDb().Wait();
 }
Exemple #4
0
 public UsersWordsService(UserWordsRepo repository, ExamplesRepo examplesRepo)
 {
     _userWordsRepository = repository;
     _examplesRepo        = examplesRepo;
 }
 public DictionaryService(DictionaryRepo repository, ExamplesRepo exampleRepository)
 {
     _dicRepository     = repository;
     _exampleRepository = exampleRepository;
 }
Exemple #6
0
        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();
        }