protected override void Run() { discoveredFeed = new NewsFeed(); try { //feedInfo = feedHandler.GetFeedDetails(this.feedUrl, this.credentials); using (Stream mem = SyncWebRequest.GetResponseStream(this.feedUrl, this.credentials, RssBanditApplication.UserAgent, this.Proxy)) { NewsFeed f = new NewsFeed(); f.link = feedUrl; if (RssParser.CanProcessUrl(feedUrl)) { feedInfo = RssParser.GetItemsForFeed(f, mem, false); if (feedInfo.ItemsList != null && feedInfo.ItemsList.Count > 0) f.containsNewMessages = true; } } } catch (ThreadAbortException) { // eat up } catch (Exception e) { // fatal errors p_operationException = e; } finally { WorkDone.Set(); } }
/// <summary> /// Implentation required for the Thread start call /// </summary> /// <example> /// Here is the impl. recommendation: /// <code> /// try { /// // long running task /// } catch (System.Threading.ThreadAbortException) { /// // eat up: op. cancelled /// } catch(Exception ex) { /// // handle them, or publish: /// p_operationException = ex; /// } finally { /// this.WorkDone.Set(); // signal end of operation to dismiss the dialog /// } /// </code> /// </example> protected override void Run() { RssLocater locator = new RssLocater(proxy, RssBanditApplication.UserAgent, this.Credentials); List <string> arrFeedUrls; Dictionary <string, string[]> htFeedUrls = null; // can raise System.Net.WebException: The remote server returned an error: (403) Forbidden try { if (locationMethod == FeedLocationMethod.AutoDiscoverUrl) { arrFeedUrls = locator.GetRssFeedsForUrl(webPageUrl, true); htFeedUrls = new Dictionary <string, string[]>(arrFeedUrls.Count); foreach (string rssurl in arrFeedUrls) { NewsFeed discoveredFeed = new NewsFeed(); discoveredFeed.link = rssurl; IFeedDetails feedInfo; try { // can raise System.Net.WebException: The remote server returned an error: (403) Forbidden feedInfo = RssParser.GetItemsForFeed(discoveredFeed, this.GetWebResponseStream(rssurl), false); } catch (Exception) { // fatal errors feedInfo = FeedInfo.Empty; } htFeedUrls.Add(rssurl, new string[] { (!string.IsNullOrEmpty(feedInfo.Title) ? feedInfo.Title: SR.AutoDiscoveredDefaultTitle), feedInfo.Description, feedInfo.Link, rssurl }); } } else // Syndic8SearchType.Keyword { htFeedUrls = locator.GetFeedsFromSyndic8(searchTerms, locationMethod); } } catch (ThreadAbortException) { // eat up } catch (System.Net.WebException wex) { p_operationException = wex; // Would it make sense, to display a credentials dialog for error (403) here? // MessageBox.Show( // SR.WebExceptionOnUrlAccess(webPageUrl, wex.Message), // SR.GUIAutoDiscoverFeedFailedCaption, MessageBoxButtons.OK,MessageBoxIcon.Error); htFeedUrls = new Dictionary <string, string[]>(); } catch (Exception e) { // fatal errors p_operationException = e; // MessageBox.Show( // SR.WebExceptionOnUrlAccess(webPageUrl, e.Message), // SR.GUIAutoDiscoverFeedFailedCaption, MessageBoxButtons.OK,MessageBoxIcon.Error); htFeedUrls = new Dictionary <string, string[]>(); } finally { discoveredFeeds = htFeedUrls; WorkDone.Set(); } }
protected override void Run() { this.responseStream = null; try { this.responseStream = SyncWebRequest.GetResponseStream( this.requestUrl, null, RssBanditApplication.UserAgent, this.Proxy); } catch (ThreadAbortException) { // eat up } catch (Exception e) { // fatal errors this.p_operationException = e; } finally { WorkDone.Set(); } }
protected override void Run() { List <string> result = new List <string>(500); try { NntpWebRequest request = (NntpWebRequest)WebRequest.Create(IdentityNewsServerManager.BuildNntpRequestUri(serverDef)); request.Method = "LIST"; if (!string.IsNullOrEmpty(serverDef.AuthUser)) { IBanditFeedSource extension = app.BanditFeedSourceExtension; if (extension != null) { request.Credentials = extension.GetFeedCredentials(serverDef); } //string u = null, p = null; //FeedSource.GetNntpServerCredentials(serverDef, ref u, ref p); //request.Credentials = FeedSource.CreateCredentialsFrom(u, p); } //TODO: implement proxy support in NntpWebRequest request.Proxy = app.Proxy; request.Timeout = 1000 * 60; // default timeout: 1 minute if (serverDef.Timeout > 0) { request.Timeout = serverDef.Timeout * 1000 * 60; // sd.Timeout specified in minutes, but we need msecs } WebResponse response = request.GetResponse(); foreach (string s in NntpParser.GetNewsgroupList(response.GetResponseStream())) { result.Add(s); } this.Newsgroups = result; } catch (System.Threading.ThreadAbortException) { // eat up } catch (Exception ex) { p_operationException = ex; } finally { WorkDone.Set(); } } // Run
/// <summary> /// Does the actual work of determining the top stories /// </summary> protected override void Run() { try { FeedSourceEntry entry = rssBanditApp.CurrentFeedSource; if (entry != null) { int numDays = RssBanditApplication.ReadAppSettingsEntry("TopStoriesTimeSpanInDays", 7); TopStories = new List <RelationHRefEntry>(entry.Source.GetTopStories(new TimeSpan(numDays, 0, 0, 0), 10)); this.GenerateTopStoriesPage(entry.Name); } } catch (ThreadAbortException) { // eat up } catch (Exception ex) { p_operationException = ex; _log.Error("GetTopStories() exception", ex); } finally { WorkDone.Set(); } }
protected override void Run() { try { if (this.postTarget != null) { this.feedHandler.PostComment(item2post, postTarget); } else { this.feedHandler.PostComment(commentApiUri, item2post, inReply2item); } } catch (ThreadAbortException) { // eat up } catch (WebException we) { //Open file for writing System.Text.StringBuilder sb = new System.Text.StringBuilder(); StringWriter writeStream = null; StreamReader readStream = null; if (we.Response != null) { writeStream = new StringWriter(sb); //Retrieve input stream from response and specify encoding Stream receiveStream = we.Response.GetResponseStream(); System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format. readStream = new StreamReader(receiveStream, encode); Char[] read = new Char[256]; // Reads 256 characters at a time. int count = readStream.Read(read, 0, 256); while (count > 0) { // Dumps the 256 characters on a string and displays the string to the console. writeStream.Write(read, 0, count); count = readStream.Read(read, 0, 256); } p_operationException = new WebException(sb.ToString(), we, we.Status, we.Response); // dump to log file/trace _log.Error(@"Error while posting a comment", p_operationException); AppExceptions.ExceptionManager.Publish(p_operationException); p_operationException = we; if (writeStream != null) { writeStream.Close(); } if (readStream != null) { readStream.Close(); } } else { p_operationException = we; } } catch (Exception ex) { p_operationException = ex; } finally { WorkDone.Set(); } }