Example #1
0
        private void combo_lang_Loaded(object sender, RoutedEventArgs e)
        {
            string[]      langs       = Enum.GetNames(typeof(ProgramTech.Language));
            List <string> itemSources = new List <string>();

            foreach (string lang in langs)
            {
                if (DatabaseController.getInstance().checkTableExists(lang))
                {
                    itemSources.Add(lang);
                }
            }
            combo_lang.ItemsSource   = itemSources;
            combo_lang.SelectedIndex = 0;
        }
Example #2
0
 public bool saveBulk(DataTable wordsTable, string language)
 {
     connection = DatabaseController.getInstance().getSqlConnection();
     try
     {
         using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
         {
             bulkCopy.DestinationTableName = language;
             bulkCopy.WriteToServer(wordsTable);
         }
     } catch (SqlException ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
     return(true);
 }
Example #3
0
        public bool saveList(List <Word> words, Language language, bool async = false)
        {
            DatabaseController.getInstance().addTable(language.ToString());
            DataTable wordTable = toDataTable(words);

            if (async)
            {
                using (var localDao = new WordDAO())
                {
                    localDao.saveBulk(wordTable, language.ToString());
                }
            }
            else
            {
                staticDao.saveBulk(wordTable, language.ToString());
            }
            return(true);
        }
Example #4
0
        private void button_dictionary_Click(object sender, EventArgs e)
        {
            LangWindow langWind = new LangWindow();

            langWind.ShowDialog();

            string selectedLang = langWind.SelectedLang;

            if (selectedLang.Equals(String.Empty))
            {
                return;
            }

            if (DatabaseController.getInstance().checkTableExists(selectedLang))
            {
                AgreeWindow agreeWindow = new AgreeWindow();
                agreeWindow.ShowDialog();

                if (!agreeWindow.Agreement)
                {
                    return;
                }
                else
                {
                    DatabaseController.getInstance().removeTable(selectedLang);
                }
            }
            var senderButton = sender as Button;

            switch (senderButton.Name)
            {
            case "button_file":
                addDictionaryFromFile(selectedLang);
                break;

            case "button_url":
                addDictionaryFromUrl(selectedLang);
                break;
            }
        }
Example #5
0
        public bool downloadDictionary(Language language, string url)
        {
            if (DatabaseController.getInstance().checkTableExists(language.ToString()))
            {
                return(false);
            }

            List <Word> words = new List <Word>();

            try
            {
                using (var client = new WebClient())
                {
                    using (System.IO.StringReader reader = new System.IO.StringReader(client.DownloadString(new Uri(url))))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            if (Word.isVaild(line))
                            {
                                words.Add(new Word(line));
                            }
                            else
                            {
                                log.Info(String.Format("{0} was not added to database, because it is not forged only from letters", line));
                            }
                        }
                    }
                }
            } catch (WebException ex)
            {
                throw new Exceptions.WordControllerWebException(url, ex);
            }

            return(WordService.getInstance().saveList(words, language));
        }
Example #6
0
 public WordDAO()
 {
     connection = DatabaseController.getInstance().getSqlConnection();
 }