[blam] Channel: better handling of downloading the feed



commit 43d2b83d9a329ca0bc7f023206a09fdfc4982c59
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Sat Jun 15 21:15:03 2013 +0200

    Channel: better handling of downloading the feed
    
    Downloading the feed and giving the string to XmlReader doesn't work
    when the feed is not in utf-8, as the characters have already been
    interpreted then.
    
    As the reason we wanted to have the string was to filter it for
    invalid characters, tell the XmlReader to not to check characters via
    options, which provides a much better solution than the ad-hoc one we
    had until now.

 blam.csproj     |    2 --
 src/Channel.cs  |   44 +++++++++++++-------------------------------
 src/Filter.cs   |   17 -----------------
 src/Makefile.am |    2 --
 4 files changed, 13 insertions(+), 52 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index aa296e3..41025e6 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -77,7 +77,6 @@
       <Private>False</Private>
       <Package>gconf-sharp-2.0</Package>
     </Reference>
-    <Reference Include="System.Net.Http" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="src\Application.cs" />
@@ -88,7 +87,6 @@
     <Compile Include="src\Conf.cs" />
     <Compile Include="src\Delegates.cs" />
     <Compile Include="src\Dialogs.cs" />
-    <Compile Include="src\Filter.cs" />
     <Compile Include="src\HigUtils.cs" />
     <Compile Include="src\HtmlUtils.cs" />
     <Compile Include="src\Item.cs" />
diff --git a/src/Channel.cs b/src/Channel.cs
index b2f3b1f..4ad911a 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -7,7 +7,6 @@
 using System.Collections;
 using System;
 using System.Net;
-using System.Net.Http;
 using System.Net.Security;
 using System.Xml;
 using System.Xml.Serialization;
@@ -305,41 +304,24 @@ namespace Imendio.Blam {
                        return Conf.Get(Preference.IGNORE_SSL_ERR, false);
                }
 
-               /// <summary>
-               /// Loads the string as an SyndicationFee. It will try to clean it up once. If the clean up 
attempt fails,
-               /// it will let SyndicationFeed.Load() throw its exception.
-               /// </summary>
-               /// <returns>The feed.</returns>
-               /// <param name="str">The XML string to load</param>
-               SyndicationFeed LoadFeed(string str)
+               async Task<SyndicationFeed> LoadFeedAsync(string url)
                {
-                       SyndicationFeed feed = null;
-                       try {
-                               var xml = XmlReader.Create(new StringReader(str));
-                               feed = SyndicationFeed.Load(xml);
-                       } catch (Exception) {
-                               str = Filter.FilterString(str);
-                               var xml = XmlReader.Create(new StringReader(str));
-                               feed = SyndicationFeed.Load(xml);
-                       }
-
-                       return feed;
+                       var opts = new XmlReaderSettings();
+                       opts.CheckCharacters = false;
+                       var reader = await Task.Run(() => XmlReader.Create(url, opts));
+                       return SyndicationFeed.Load(reader);
                }
 
                public async Task<bool> RefreshAsync()
                {
-                       using (var http = new HttpClient())
-                       {
-                               ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate;
-                               try {
-                                       var xmlstring = await http.GetStringAsync(Url);
-                                       var feed = LoadFeed(xmlstring);
-
-                                       return Update(feed);
-                               } catch (Exception e) {
-                                       Console.WriteLine("Failed to get feed {0}: {1}", Name, e.Message);
-                                       return false;
-                               }
+                       ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate;
+                       try {
+                               var feed = await LoadFeedAsync(Url);
+
+                               return Update(feed);
+                       } catch (Exception e) {
+                               Console.WriteLine("Failed to get feed {0}: {1}", Name, e.Message);
+                               return false;
                        }
                }
        }
diff --git a/src/Makefile.am b/src/Makefile.am
index dd80f0b..50a8910 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,7 +11,6 @@ RESOURCES = \
 ASSEMBLIES = \
             -r:System.Web   \
             -r:Mono.Posix   \
-            -r:System.Net.Http \
             -r:System.ServiceModel
 
 BLAM_CSFILES = Application.cs \
@@ -39,7 +38,6 @@ BLAM_CSFILES = Application.cs \
               Utils.cs \
               Proxy.cs \
               ItemStore.cs \
-              Filter.cs \
               ../gtk-gui/generated.cs \
               ../gtk-gui/Imendio.Blam.AddChannelDialog.cs \
               gtk-sharp-beans/Global.cs


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]