/// <summary> /// Takes a given FeedConfiItem and iterates through all the available plugins to see if any of them can handle it. /// </summary> private void GetFeedType(FeedConfigItem feedConfigItem) { try { Log.Debug("Getting the Feed Type"); var document = (XmlDocument)FeedwinManager.Fetch(feedConfigItem); foreach (var feedplugin in FeedwinManager.thisinst.Plugins) { Log.Debug("Testing {0} to see if it can handle feed", feedplugin.PluginName); if (!feedplugin.CanHandle(document)) { continue; } Log.Debug("It can! Yay!"); var reqproxy = feedConfigItem.ProxyType != HttpProxyHelper.ProxyType.Global ? feedConfigItem.Proxy : HttpProxyHelper.GetGlobalProxy(); if (reqproxy != null) { Log.Debug("Set Proxy for feed to {0}", reqproxy.GetProxy(new Uri(feedConfigItem.Url))); } else { Log.Debug("Set Proxy for feed to nothing, nothing at all"); } rssfeed = feedplugin.AddFeed(new Uri(feedConfigItem.Url), feedConfigItem.AuthType, feedConfigItem.UserName, feedConfigItem.Password, reqproxy); rssfeed.UpdateInterval = feedConfigItem.UpdateInterval; break; } } catch (XmlException ex) { errormsg = "Invalid XML Document"; Log.Error("XMLException thrown in parsing the feed", ex); } catch (UriFormatException ex) { errormsg = "Invalid URI"; Log.Error("URIException thrown in fetching the feed", ex); } catch (WebException ex) { errormsg = ex.Message; Log.Error("WebException thrown in fetching the feed", ex); } if (rssfeed == null) { Log.Debug("Didn't find a plugin to handle this feed"); if (errormsg == string.Empty) { errormsg = "No Plugin to handle feed"; } } else { rssfeed.Updated += rssfeed_Updated; Log.Debug("Kicking off the watcher thread"); var t = new Thread(rssfeed.Watch) { IsBackground = true }; t.SetApartmentState(ApartmentState.STA); t.Start(); } RedrawWin(); }
public static IXPathNavigable Fetch(FeedConfigItem fci) { Log.Debug("Fetching feed from intarweb"); HttpWebResponse resp = null; try { var requri = new Uri(fci.Url); var req = (HttpWebRequest)WebRequest.Create(requri); req.UserAgent = FetchUserAgentString(); req.Proxy = fci.ProxyType != HttpProxyHelper.ProxyType.Global ? fci.Proxy : HttpProxyHelper.GetGlobalProxy(); switch (fci.AuthType) { case FeedAuthTypes.Basic: req.Credentials = new NetworkCredential(fci.UserName, fci.Password); resp = (HttpWebResponse)req.GetResponse(); break; case FeedAuthTypes.Other: case FeedAuthTypes.None: resp = (HttpWebResponse)req.GetResponse(); break; } var tempdoc = new XmlDocument(); if (resp != null) { var respstream = resp.GetResponseStream(); if (respstream != null) { var streamtext = new StreamReader(respstream).ReadToEnd(); tempdoc.LoadXml(streamtext); } } return(tempdoc); } catch (Exception ex) { Log.Error("Exception thrown when fetching feed", ex); throw; } finally { if (resp != null) { resp.Close(); } } }