private void doFilteredSearch2() { List <string> searchTerms = getSearchTerms(); List <string> includeTerms = null; List <string> excludeTerms = null; if (checkBoxFilterGroups.Checked) { if (radioButtonInclude.Checked && radioButtonExclude.Checked == false) { includeTerms = searchTerms; } else if (radioButtonExclude.Checked && radioButtonInclude.Checked == false) { excludeTerms = searchTerms; } else { MessageBox.Show("Unable to complete search. Please try again."); } addSearchToComboBox(searchTerms); } newsGroups = Utils.GetNewsGroups(server, includeTerms, excludeTerms); }
//good test server: forums.embarcadero.com. public static NewsgroupCollection GetNewsGroups(string server, List <string> includeList, List <string> excludeList) { NewsConnection connection = new NewsConnection(); connection.Connect(server); NewsgroupCollection groups = connection.GetNewsgroups(includeList, excludeList); connection.Disconnect(); return(groups); }
private void NewsReaderForm_Load(object sender, EventArgs e) { //server server = "forums.embarcadero.com"; textBoxServerURL.Text = server; textBoxServerURL.Select(); //listboxes newsGroups = new NewsgroupCollection(); listBoxNewsgroups.DisplayMember = "Name"; listBoxArticleHeaders.DisplayMember = "Subject"; //filtering checkBoxFilterGroups.Checked = false; deactivateFiltering(); radioButtonInclude.Checked = true; checkBoxFilterArticles.Checked = true; textBoxNumArticles.Text = "100"; }
private bool downloadGroups() { string server = txtServer.Text; // add an item to the group filter list addGroupFilters(); string[] filterList = cboGroupFilters.Text.Split(' '); try { // Temporary connection to the server. NewsConnection connection = new NewsConnection(); connection.Connect(server); if (chkFilterGroups.Checked) { if (radInclude.Checked) { groups = connection.GetNewsgroups(filterList, null); } else { groups = connection.GetNewsgroups(null, filterList); } } else { groups = connection.GetNewsgroups(); } connection.Disconnect(); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "Download Articles", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } }
private void doFilteredSearch() { List <string> includeTerms = null; List <string> excludeTerms = null; if (checkBoxFilterGroups.Checked) { includeTerms = getIncludeTerms(); excludeTerms = getExcludeTerms(); } newsGroups = Utils.GetNewsGroups(server, includeTerms, excludeTerms); ///this is corny, need to simplify if (includeTerms != null) { addSearchToComboBox(includeTerms); } else if (excludeTerms != null) { addSearchToComboBox(excludeTerms); } }
private bool downloadGroups() { string server = txtServer.Text; // add an item to the group filter list addGroupFilters(); string[] filterList = cboGroupFilters.Text.Split(' '); try { // Temporary connection to the server. NewsConnection connection = new NewsConnection(); connection.Connect(server); if (chkFilterGroups.Checked) { if (radInclude.Checked) { groups = connection.GetNewsgroups(filterList, null); } else { groups = connection.GetNewsgroups(null, filterList); } } else { groups = connection.GetNewsgroups(); } connection.Disconnect(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Download Articles", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } }
/// <summary> /// If includeList is not null then this method downloads the newsgroups /// that have any of the words in includeList in any part of the newsgroup name. If excludeList /// is not null then this method downloads the newsgroups that do not have any of the words in /// the excludeList in any part of the newsgroup name. If both parameters are null then all newsgroups /// are downloaded; if both are not null then an assertion is raised. /// </summary> /// <param name="includeList">A collection of strings to search for in the newsgroup names. If any /// of the words are in any part of the newsgroup name then that newsgroup is downloaded. This value /// must be null if excludeList is not null.</param> /// <param name="excludeList">A collection of strings to search for in the newsgroup names. If any /// of the words are in any part of the newsgroup name then that newsgroup is not downloaded. This /// value must be null if includeList is not null.</param> /// <returns>A collection of Newsgroup objects that match the filter criteria given by includeList /// or by excludeList. Each object's Articles property will be null. Use GetArticleHeaders to populate /// these objects with Article objects.</returns> public NewsgroupCollection GetNewsgroups(IList<string> includeList, IList<string> excludeList) { string message; string response; NewsgroupCollection groups = new NewsgroupCollection(); message = "LIST\r\n"; Write(message); response = Response(); if (response.Substring(0, 3) != "215") { throw new NntpException(response); } // Suck next line of data from the socket. response = Response(); while (response != ".\r\n" && response != ".\n") { // The response line should take the format: // group last first p // // groupName - name of the group // last - sequence number of the last message // first - sequence number of the first message // p - boolean value equal to y or n indicating whether or not posting is allowed // (note: this is independent of whether the particular news server allows // posting; some groups are moderated and therefore can only have posting by // the moderator). string[] values = response.Split(' '); // I don't think this would happen, but... if (values.Length != 4) { throw new NntpException("LIST command returned unexpected results."); } string groupName = values[0]; int last = int.Parse(values[1]); int first = int.Parse(values[2]); bool postingAllowed = values[3].Trim().ToLower() == "y"; Newsgroup newGroup; if (includeList != null) { // An include list has been supplied. Add this group only if the group name // contains one of the include list strings. foreach (string includeString in includeList) { if (groupName.Contains(includeString)) { newGroup = new Newsgroup(groupName, postingAllowed, first, last); groups.Add(newGroup); break; } } } else if (excludeList != null) { // An exclude list has been supplied. Add this group only if the group name // contains *none* of the include list strings. bool contains = false; foreach (string excludeString in excludeList) { if (groupName.Contains(excludeString)) { contains = true; break; } } if (!contains) { newGroup = new Newsgroup(groupName, postingAllowed, first, last); groups.Add(newGroup); } } else { // Neither include nor exclude list has been supplied. Add this group. newGroup = new Newsgroup(groupName, postingAllowed, first, last); groups.Add(newGroup); } // Pump the loop. response = Response(); } return groups; }