/// <summary>
 /// Deprecated Method for adding a new object to the ListNames EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToListNames(ListName listName)
 {
     base.AddObject("ListNames", listName);
 }
        private void buttonCollect_Click(object sender, EventArgs e)
        {
            var entities = new gredbEntities();

            long listNameId = -1;
            if (comboBoxList.Text.Trim().Length > 0)
            {
                var list = entities.ListNames.Where(o => o.Name.ToLower().Equals(comboBoxList.Text.Trim().ToLower())).Select(o => o).FirstOrDefault();
                if (list == null)
                {

                    ListName listName = new ListName();
                    listName.Name = comboBoxList.Text.Trim().ToLower();
                    entities.AddToListNames(listName);
                    entities.SaveChanges();

                    listNameId = listName.Id;
                }
                else
                {
                    listNameId = list.Id;
                }
            }
            else
            {
                listNameId = Convert.ToInt64(comboBoxList.SelectedValue);
            }

            String strWord = textBoxWord.Text.Trim().ToLower();
            ListName ln = (from n in entities.ListNames
                           where n.Id == listNameId
                           select n).FirstOrDefault();

            try
            {
                GreWord word;
                word = (from w in entities.GreWords
                        where w.Word.ToLower() == strWord
                        select w).FirstOrDefault();

                if (word == null)
                {
                    word = new GreWord()
                    {
                        Word = strWord,
                    };
                    entities.AddToGreWords(word);
                    entities.SaveChanges();
                }

                ListedWord lw = (from w in entities.ListedWords
                                 where w.ListName.Id == ln.Id && w.GreWord.Word == word.Word
                                 select w).FirstOrDefault();

                if (lw == null)
                {
                    lw = new ListedWord()
                    {
                        GreWord = word,
                        ListName = ln
                    };
                    entities.AddToListedWords(lw);
                    entities.SaveChanges();
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }

            ParserHelper parserHelper = new ParserHelper(entities);
            parserHelper.OnLogMessage += (sender2, person) => this.Invoke((MethodInvoker)(() => textBoxInfo.AppendText(person + "\r\n")));

            parserHelper.WordToFetch = strWord;
            var workerThread = new Thread(parserHelper.FetchAndParseSingleWord) {IsBackground = true};
            workerThread.Start();
        }
 /// <summary>
 /// Create a new ListName object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static ListName CreateListName(global::System.Int64 id, global::System.String name)
 {
     ListName listName = new ListName();
     listName.Id = id;
     listName.Name = name;
     return listName;
 }
        private void button1_Click(object sender, EventArgs e)
        {
            long listNameId = -1;
            var entities = new gredbEntities();

            var list = entities.ListNames.Where(o => o.Name.ToLower().Equals(comboBoxList.Text.Trim().ToLower())).Select(o => o).FirstOrDefault();
            if (list == null)
            {

                ListName listName = new ListName { Name = comboBoxList.Text.Trim() };
                entities.AddToListNames(listName);
                entities.SaveChanges();

                listNameId = listName.Id;
            }
            else
            {
                listNameId = list.Id;
            }

            String str = Regex.Replace(textBox1.Text, "([0-9\\.]+|<.+?>)", "");
            Regex regex = new Regex("([^\\s]+)");

            ListName ln = (from n in entities.ListNames
                           where n.Id == listNameId
                           select n).FirstOrDefault();

            try
            {
                MatchCollection mc = regex.Matches(str);

                foreach (Match m in mc)
                {
                    try
                    {
                        GreWord word = (from w in entities.GreWords
                                        where w.Word.ToLower() == m.Value.ToLower()
                                        select w).FirstOrDefault();

                        if (word == null)
                        {
                            word = new GreWord()
                            {
                                Word = m.Value.ToLower(),
                            };
                            entities.AddToGreWords(word);
                            entities.SaveChanges();
                        }

                        ListedWord lw = (from w in entities.ListedWords
                                         where w.ListName.Id == ln.Id && w.GreWord.Word == word.Word
                                         select w).FirstOrDefault();

                        if (lw == null)
                        {
                            lw = new ListedWord()
                            {
                                GreWord = word,
                                ListName = ln
                            };
                            entities.AddToListedWords(lw);
                            entities.SaveChanges();
                        }
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.Message);
                    }
                }
                entities.Connection.Close();
            }
            catch (Exception exp)
            {
            }
        }