Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hutchinson <m.j.hutchinson@gmail.com>2012-11-29 04:59:07 +0400
committerMichael Hutchinson <m.j.hutchinson@gmail.com>2012-11-29 05:01:11 +0400
commitdb2016a9e20b567c51df2f1881c087d82a615a74 (patch)
treed80ad475c2708a5fb7930d031d0b5644301de3d5 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage
parent031cf27f9c0803eb69127bae10037b924c0bf81e (diff)
New UpdateDownloadedCacheFile method on FileService
Factored out from WelcomePageNewsFeed. Used for downloading cache files, skipping unnecessary redownload using If-Modified-Since.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage/WelcomePageNewsFeed.cs78
1 files changed, 16 insertions, 62 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage/WelcomePageNewsFeed.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage/WelcomePageNewsFeed.cs
index 72b5f1f93d..827119952f 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage/WelcomePageNewsFeed.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage/WelcomePageNewsFeed.cs
@@ -129,77 +129,31 @@ namespace MonoDevelop.Ide.WelcomePage
return;
}
LoggingService.LogInfo ("Updating Welcome Page from '{0}'.", newsUrl);
-
- //HACK: .NET blocks on DNS in BeginGetResponse, so use a threadpool thread
- // see http://stackoverflow.com/questions/1232139#1232930
- System.Threading.ThreadPool.QueueUserWorkItem ((state) => {
- var request = (HttpWebRequest)WebRequest.Create (newsUrl);
-
+
+ FileService.UpdateDownloadedCacheFile (newsUrl, CacheFile, s => {
+ using (var reader = XmlReader.Create (s, GetSafeReaderSettings ())) {
+ return reader.ReadToDescendant ("links");
+ }
+ }).ContinueWith (t => {
try {
- //check to see if the online news file has been modified since it was last downloaded
- string localCachedNewsFile = CacheFile;
- var localNewsXml = new FileInfo (localCachedNewsFile);
- if (localNewsXml.Exists)
- request.IfModifiedSince = localNewsXml.LastWriteTime;
-
- request.BeginGetResponse (HandleResponse, request);
+ if (t.IsCanceled)
+ return;
+
+ if (!t.Result)
+ LoggingService.LogInfo ("Welcome Page already up-to-date.");
+
+ LoggingService.LogInfo ("Welcome Page updated.");
+ Gtk.Application.Invoke (delegate { LoadNews (); });
+
} catch (Exception ex) {
LoggingService.LogWarning ("Welcome Page news file could not be downloaded.", ex);
+ } finally {
lock (updateLock)
isUpdating = false;
}
});
}
- void HandleResponse (IAsyncResult ar)
- {
- string localCachedNewsFile = CacheFile;
- try {
- var request = (HttpWebRequest) ar.AsyncState;
- var tempFile = localCachedNewsFile + ".temp";
- //FIXME: limit this size in case open wifi hotspots provide bad data
- var response = (HttpWebResponse) request.EndGetResponse (ar);
- if (response.StatusCode == HttpStatusCode.OK) {
- using (var fs = File.Create (tempFile))
- response.GetResponseStream ().CopyTo (fs, 2048);
- }
-
- //check the document is valid, might get bad ones from wifi hotspots etc
- try {
- var updateDoc = new XmlDocument ();
- using (var reader = XmlReader.Create (tempFile, GetSafeReaderSettings ()))
- updateDoc.Load (reader);
- updateDoc.SelectSingleNode ("/links");
- } catch (Exception ex) {
- LoggingService.LogWarning ("Welcome Page news file is bad, keeping old version.", ex);
- File.Delete (tempFile);
- return;
- }
-
- if (File.Exists (localCachedNewsFile))
- File.Delete (localCachedNewsFile);
- File.Move (tempFile, localCachedNewsFile);
-
- Gtk.Application.Invoke (delegate {
- LoadNews ();
- });
- } catch (System.Net.WebException wex) {
- var httpResp = wex.Response as HttpWebResponse;
- if (httpResp != null && httpResp.StatusCode == HttpStatusCode.NotModified) {
- LoggingService.LogInfo ("Welcome Page already up-to-date.");
- } else if (httpResp != null && httpResp.StatusCode == HttpStatusCode.NotFound) {
- LoggingService.LogInfo ("Welcome Page update file not found.", newsUrl);
- } else {
- LoggingService.LogWarning ("Welcome Page news file could not be downloaded.", wex);
- }
- } catch (Exception ex) {
- LoggingService.LogWarning ("Welcome Page news file could not be downloaded.", ex);
- } finally {
- lock (updateLock)
- isUpdating = false;
- }
- }
-
static XmlReaderSettings GetSafeReaderSettings ()
{
//allow DTD but not try to resolve it from web