Esempio n. 1
0
        private bool searchCards()
        {
            WordsListHandler wordsListHandler = new WordsListHandler();

            //загружаем cashList из файла
            SerializerToXML serializerToXML = new SerializerToXML();

            cashList = serializerToXML.DeSerialize(SettingsManager.PathCacheFile);

            //Список слов для обработки
            inputCardsList = new List <Card>();

            //загружаем inputCardsList из файла
            foreach (string line in textBox1.Lines)
            {
                if (line == "")
                {
                    continue;
                }
                string[] array = line.Split('\t');

                Card searchCard = new Card();
                searchCard.Word = array[0].Trim();

                if (array.Length > 1)
                {
                    string pos = array[1].Trim();
                    if ((pos == "n") || (pos == "noun"))
                    {
                        searchCard.PartOfSpeech = "noun";
                    }
                    else if ((pos == "v") || (pos == "verb"))
                    {
                        searchCard.PartOfSpeech = "verb";
                    }
                    else if ((pos == "conj") || (pos == "conjunction"))
                    {
                        searchCard.PartOfSpeech = "conjunction";
                    }
                    else if ((pos == "adj") || (pos == "adjective"))
                    {
                        searchCard.PartOfSpeech = "adjective";
                    }
                    else if ((pos == "det") || (pos == "determiner"))
                    {
                        searchCard.PartOfSpeech = "determiner";
                    }
                    else if ((pos == "prep") || (pos == "preposition"))
                    {
                        searchCard.PartOfSpeech = "";
                    }
                    else if ((pos == "pron") || (pos == "pronoun"))
                    {
                        searchCard.PartOfSpeech = "pronoun";
                    }
                    else if ((pos == "adv") || (pos == "adverb"))
                    {
                        searchCard.PartOfSpeech = "adverb";
                    }
                    else if ((pos == "mod") || (pos == "modal verb"))
                    {
                        searchCard.PartOfSpeech = "modal verb";
                    }
                    else if ((pos == "phrase v") || (pos == "phrasal verb"))
                    {
                        searchCard.PartOfSpeech = "phrasal verb";
                    }
                    else
                    {
                        searchCard.PartOfSpeech = "";
                    }
                }

                inputCardsList.Add(searchCard);
            }
            ;

            //Готовые карточки
            outputCardsList = new List <Card>();

            foreach (Card searchCard in inputCardsList)
            {
                Card card = new Card();

                if (cashList != null)
                {
                    //card = cashList.Find(x => x.Word == searchWord);
                    card = cashList.Find(x => x.Equals(searchCard));
                    if (card != null)
                    {
                        outputCardsList.Add(card);
                    }
                    else
                    {
                        card = wordsListHandler.SearchInInternet(searchCard);
                        outputCardsList.Add(card);
                        cashList.Add(card);
                    }
                }

                DisplayProgress("Обработано: " + outputCardsList.Count.ToString() + " / " + textBox1.Lines.Length.ToString());
            }

            serializerToXML.Serialize(cashList, SettingsManager.PathCacheFile);


            listBoxResult.DataSource = outputCardsList;
            return(true);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            SerializerToXML serializerToXML = new SerializerToXML();

            serializerToXML.Serialize(cashList, "Cards.xml");
        }