Пример #1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            this.currentLine = 0;
            this.maxLines    = File.ReadLines(openFileDialog1.FileName).Count();
            using (StreamReader sr = File.OpenText(openFileDialog1.FileName))
            {
                string line = String.Empty;
                while ((line = sr.ReadLine()) != null)
                {
                    if (backgroundWorker.CancellationPending == true)
                    {
                        e.Cancel = true;
                        break;
                    }
                    foreach (string word in StringParseLibrary.GetWordsInString(line))
                    {
                        DataLayer.dataLayer.AddWord(word);
                    }
                    this.currentLine++;
                    backgroundWorker.ReportProgress((int)(this.currentLine * 100 / this.maxLines));
                }
            }
        }
Пример #2
0
        public void TestWhitespaceLine()
        {
            string line = " \t ";

            string[] words = StringParseLibrary.GetWordsInString(line);
            Assert.IsNotNull(words);
            Assert.AreEqual(0, words.Length);
        }
Пример #3
0
        public void TestSingleWord()
        {
            string line = "hello";

            string[] words = StringParseLibrary.GetWordsInString(line);
            Assert.AreEqual(1, words.Length);
            Assert.AreEqual(line, words[0]);
        }
Пример #4
0
        public void TestManyWords()
        {
            string line = "hello world, here I am";

            string[] words = StringParseLibrary.GetWordsInString(line);
            Assert.AreEqual(5, words.Length);
            Assert.AreEqual("hello", words[0]);
            Assert.AreEqual("world,", words[1]);
            Assert.AreEqual("here", words[2]);
            Assert.AreEqual("I", words[3]);
            Assert.AreEqual("am", words[4]);
        }