Exemplo n.º 1
0
 public void Dispose()
 {
     if (IsInitialized)
     {
         try
         {
             _db.Dispose();
             IsInitialized = false;
         }
         catch (Exception e)
         {
             Console.WriteLine($"Error disconnecting to database: {e}");
             throw;
         }
     }
     else
     {
         Console.WriteLine("RandomWordsService isn't initialized!");
     }
 }
Exemplo n.º 2
0
        public void AddWordsToDataBaseFromFile(string path)
        {
            DeepMorphyService deepMorphyService = new DeepMorphyService();

            deepMorphyService.Init();
            var words      = File.ReadAllLines(path);
            var dictionary = deepMorphyService.GetBestGramKeysOfWords(words);

            if (words.Length != 0)
            {
                foreach (var word in dictionary)
                {
                    _db.Add(new WordsTableModel()
                    {
                        Word         = word.Key,
                        PartOfSpeech = word.Value["чр"]
                    });
                }
            }
            _db.SaveChanges();
            _db.Dispose();
        }