Exemple #1
0
 public AddWordService(UsersWordsService usersWordsService, YandexDictionaryApiClient yapiDicClient,
                       YandexTranslateApiClient yapiTransClient, DictionaryService dictionaryService)
 {
     _usersWordsService = usersWordsService;
     _yapiDicClient     = yapiDicClient;
     _yapiTransClient   = yapiTransClient;
     _dictionaryService = dictionaryService;
 }
Exemple #2
0
 public YapiPingHostedService(
     ILogger <YapiPingHostedService> logger,
     YandexDictionaryApiClient yadicapiClient, YandexTranslateApiClient yaTransClient)
 {
     _logger         = logger;
     _yadicapiClient = yadicapiClient;
     _yaTransClient  = yaTransClient;
 }
Exemple #3
0
 public WordsController(YandexDictionaryApiClient yaapiClient, YandexTranslateApiClient yandexTransApiClient
                        , DictionaryService dictionaryService, UsersPairsService usersPairsService, UserService userService)
 {
     _yandexDictionaryApiClient = yaapiClient;
     _yandexTransApiClient      = yandexTransApiClient;
     _dictionaryService         = dictionaryService;
     _usersPairsService         = usersPairsService;
     _userService = userService;
 }
 public WordAdditionMode(YandexTranslateApiClient yapiTranslateApiClient,
                         YandexDictionaryApiClient yandexDictionaryApiClient, UsersWordService usersWordService,
                         DictionaryService dictionaryService, AddWordService addWordService)
 {
     _yapiDicClient     = yandexDictionaryApiClient;
     _yapiTransClient   = yapiTranslateApiClient;
     _usersWordService  = usersWordService;
     _dictionaryService = dictionaryService;
     _addWordService    = addWordService;
 }
Exemple #5
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 #6
0
 public AddingWordsMode(
     Chat chat,
     YandexTranslateApiClient yapiTranslateApiClient,
     YandexDictionaryApiClient yandexDictionaryApiClient,
     NewWordsService wordService
     )
 {
     _chat            = chat;
     _wordService     = wordService;
     _yapiDicClient   = yandexDictionaryApiClient;
     _yapiTransClient = yapiTranslateApiClient;
 }
Exemple #7
0
        static void Main()
        {
            TaskScheduler.UnobservedTaskException +=
                (sender, args) => Console.WriteLine($"Unobserved ex {args.Exception}");


            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);

            var dbFileName        = configuration.GetSection("wordDb").Value;
            var yatransapiKey     = configuration.GetSection("yatransapi").GetSection("key").Value;
            var yatransapiTimeout = TimeSpan.FromSeconds(5);

            _yapiDicClient   = new YandexDictionaryApiClient(yadicapiKey, yadicapiTimeout);
            _yapiTransClient = new YandexTranslateApiClient(yatransapiKey, yatransapiTimeout);

            var repo = new WordsRepository(dbFileName);

            repo.ApplyMigrations();

            Console.WriteLine("Dic started");
            _wordsService = new NewWordsService(new RuengDictionary(), repo);

            _botClient = new TelegramBotClient(ApiToken);

            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();

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();

            _botClient.StopReceiving();
        }
Exemple #8
0
 public AddPhraseToWordsMode(YandexDictionaryApiClient client)
 {
     _client = client;
 }
 public WordAdditionMode(YandexTranslateApiClient yapiTranslateApiClient, YandexDictionaryApiClient yandexDictionaryApiClient)
 {
     _yapiDicClient   = yandexDictionaryApiClient;
     _yapiTransClient = yapiTranslateApiClient;
 }
Exemple #10
0
        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("===========================================");
            }
        }
Exemple #11
0
 public WordsController(NewWordsService wordsService, YandexDictionaryApiClient yaapiClient, YandexTranslateApiClient yaTransApi)
 {
     _yandexDictionaryApiClient = yaapiClient;
     _yaTransApi   = yaTransApi;
     _wordsService = wordsService;
 }
Exemple #12
0
        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);

            var dbFileName        = configuration.GetSection("wordDb").Value;
            var yatransapiKey     = configuration.GetSection("yatransapi").GetSection("key").Value;
            var yatransapiTimeout = TimeSpan.FromSeconds(5);


            var yapiDicClient = new YandexDictionaryApiClient(yadicapiKey, yadicapiTimeout);

            var yapiTransClient = new YandexTranslateApiClient(yatransapiKey, yatransapiTimeout);

            var modes = new IConsoleMode[]
            {
                new ExamMode(),
                new WordAdditionMode(yapiTransClient, yapiDicClient),
                new GraphsStatsMode(),
                //   new RandomizeMode(),
                //   new AddPhraseToWordsMode(yapiDicClient),
            };

            var repo = new WordsRepository(dbFileName);

            repo.ApplyMigrations();

            Console.WriteLine("Dic started");

            //var metrics = repo.GetAllQuestionMetrics();

            //string path = "T:\\Dictionary\\eng_rus_full.json";
            //Console.WriteLine("Loading dictionary");
            //var dictionary = Dic.Logic.Dictionaries.Tools.ReadFromFile(path);
            var service = new NewWordsService(new RuengDictionary(), repo);

            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(@"
     ____ _  _ ____ ___ _ ____ _  _ ____ ___  ____ _    
     |    |__| |  |  |  | [__  |_/  |__|   /  |__| |    
     |___ |  | |__|  |  | ___] | \_ |  |  /__ |  | |___                                                    
");
            Console.ResetColor();
            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:");

                var val = Console.ReadKey();
                Console.WriteLine();

                if (val.Key == ConsoleKey.Escape)
                {
                    return;
                }

                var 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(service);
                }
                Console.WriteLine();

                Console.WriteLine("===========================================");
            }
        }
Exemple #13
0
 public YaService(YandexDictionaryApiClient yaDicClient,
                  YandexTranslateApiClient yaTransClient)
 {
     _yaDicClient   = yaDicClient;
     _yaTransClient = yaTransClient;
 }
Exemple #14
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();
        }