[blam] FeedUpdater: Add simple filtering
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam] FeedUpdater: Add simple filtering
- Date: Sun, 27 Mar 2011 15:38:43 +0000 (UTC)
commit 3b91b4726fb887c3b7e3b9185b1a552b1d3bbaf5
Author: Carlos MartÃn Nieto <carlos cmartin tk>
Date: Sun Mar 27 14:37:22 2011 +0200
FeedUpdater: Add simple filtering
If the first load doesn't succeed, pass it through a filter and try
again.
Signed-off-by: Carlos MartÃn Nieto <carlos cmartin tk>
src/FeedUpdater.cs | 14 +++++++++-----
src/Filter.cs | 27 +++++++++++++++++++++++++++
src/Makefile.am | 3 ++-
3 files changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/src/FeedUpdater.cs b/src/FeedUpdater.cs
index 92053de..673175f 100644
--- a/src/FeedUpdater.cs
+++ b/src/FeedUpdater.cs
@@ -46,13 +46,17 @@ namespace Imendio.Blam {
XmlTextReader reader = null;
SyndicationFeed feed = null;
try{
- System.Console.WriteLine("about to read {0}", channel.Url);
reader = new XmlTextReader(channel.Url);
- if(reader == null){
- System.Console.WriteLine("Can't init reader");
- }
- System.Console.WriteLine("xml reader done");
feed = SyndicationFeed.Load(reader);
+ } catch(XmlException e){
+ Console.Error.WriteLine("Need to filter {0}", channel.Url);
+ reader = Filter.FromUrl(channel.Url);
+ try{
+ feed = SyndicationFeed.Load(reader);
+ } catch(Exception ex){
+ System.Console.WriteLine("Filter didn't help: {0}", e.Message);
+ return false;
+ }
} catch(Exception e){
System.Console.WriteLine("Ex caught: {0}", e.Message);
return false;
diff --git a/src/Filter.cs b/src/Filter.cs
new file mode 100644
index 0000000..e1474be
--- /dev/null
+++ b/src/Filter.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Net;
+using System.Xml;
+using System.Text.RegularExpressions;
+using System.IO;
+
+namespace Imendio.Blam
+{
+ public class Filter
+ {
+ static public XmlTextReader FromUrl(string url)
+ {
+ string orig;
+ try {
+ WebClient client = new WebClient();
+ orig = client.DownloadString(url);
+ } catch (Exception ex) {
+ Console.Error.WriteLine("Can't download {0}: {1}", url, ex.Message);
+ return null;
+ }
+
+ Regex regex = new Regex(@"\x0C");
+ string result = regex.Replace(orig, String.Empty);
+ return new XmlTextReader(new StringReader(result));
+ }
+ }
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index 7ea194e..a2cd0f7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,7 +35,8 @@ BLAM_CSFILES = Application.cs \
TrayIcon.cs \
Utils.cs \
Proxy.cs \
- ItemStore.cs
+ ItemStore.cs \
+ Filter.cs
GENERATED_CSFILES = \
Defines.cs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]