capuchin r84 - in trunk: . src/libcapuchin src/libcapuchin/Downloaders
- From: sebp svn gnome org
- To: svn-commits-list gnome org
- Subject: capuchin r84 - in trunk: . src/libcapuchin src/libcapuchin/Downloaders
- Date: Wed, 2 Apr 2008 21:12:26 +0100 (BST)
Author: sebp
Date: Wed Apr 2 21:12:26 2008
New Revision: 84
URL: http://svn.gnome.org/viewvc/capuchin?rev=84&view=rev
Log:
Made AppObject.Update a blocking call.
Modified:
trunk/ChangeLog
trunk/src/libcapuchin/AppObject.cs
trunk/src/libcapuchin/DownloadManager.cs
trunk/src/libcapuchin/Downloaders/AbstractDownloader.cs
Modified: trunk/src/libcapuchin/AppObject.cs
==============================================================================
--- trunk/src/libcapuchin/AppObject.cs (original)
+++ trunk/src/libcapuchin/AppObject.cs Wed Apr 2 21:12:26 2008
@@ -15,8 +15,8 @@
{
/// <summary>
- /// An application specific object that handels the plugins
- /// </summary>
+ /// An application specific object that handels the plugins
+ /// </summary>
public class AppObject : IDisposable, IAppObject
{
public event UpdateFinishedHandler UpdateFinished;
@@ -33,12 +33,12 @@
protected string InstallPath;
protected IDictionary<int, string> DownloadToPluginId;
protected string ApplicationName;
- protected IDictionary<string, List<string>> TagToPlugins;
+ protected IDictionary<string, List<string>> TagToPlugins;
private const int SLEEP_TIME = 500;
private bool disposed = false;
private int repo_dlid = -1;
-
+
/// <param name="repository_url">URL to repository's XML file</param>
public AppObject (string repository_url)
{
@@ -46,8 +46,8 @@
this.LocalRepo = Path.Combine(Globals.Instance.LOCAL_CACHE_DIR, Path.GetFileName(repository_url));
// Used to map DownloadId to PluginID
this.DownloadToPluginId = new Dictionary<int, string>();
- // Used to map tag to plugin ids
- this.TagToPlugins = new Dictionary<string, List<string>> ();
+ // Used to map tag to plugin ids
+ this.TagToPlugins = new Dictionary<string, List<string>> ();
// Forward DownloadStatus event
Globals.DLM.DownloadStatus += new DownloadManagerStatusHandler(
@@ -85,7 +85,7 @@
/// <summary>Load the repository</summary>
/// <param name="force_update">Whether to force to download the XML file from the server
/// or use the cached one, if no newer version is available</param>
- /// <exception cref="Capuchin.RepositoryConnectionException">
+ /// <exception cref="Capuchin.RepositoryConnectionException">
/// Thrown if connection to repository failed
/// </exception>
public void Update (bool force_update)
@@ -97,16 +97,15 @@
Log.Info("Downloading XML file from {0}", this.RepositoryURL);
File.Delete( this.LocalRepo );
- this.repo_dlid = Globals.DLM.DownloadFile (this.RepositoryURL, Globals.Instance.LOCAL_CACHE_DIR);
- } else {
- this.LoadRepository ();
+ Globals.DLM.DownloadFileBlocking (this.RepositoryURL, Globals.Instance.LOCAL_CACHE_DIR);
}
+ this.LoadRepository ();
}
protected void LoadRepository ()
{
Log.Info("Deserializing XML file");
-
+
XmlSerializer ser = new XmlSerializer(typeof(Repository));
FileStream repo_stream = new FileStream( this.LocalRepo, FileMode.Open );
@@ -122,22 +121,22 @@
this.RepoItems = repo.items;
this.InstallPath = ExpandPath(repo.installpath);
this.ApplicationName = repo.application;
-
- this.fillTagToPlugins ();
+
+ this.fillTagToPlugins ();
this.OnUpdateFinished();
}
- /// <returns>
- /// The name of the application the repository belongs to
- /// </returns>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <returns>
+ /// The name of the application the repository belongs to
+ /// </returns>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string GetApplicationName ()
{
- this.RepoInitialized ();
-
+ this.RepoInitialized ();
+
return this.ApplicationName;
}
@@ -145,14 +144,14 @@
/// <returns>
/// An array of plugin IDs
/// </returns>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string[] GetAvailablePlugins ()
{
Log.Info("Getting available plugins");
-
- this.RepoInitialized ();
+
+ this.RepoInitialized ();
string[] ids = new string[this.RepoItems.Count];
int c=0;
@@ -171,22 +170,22 @@
/// The first element is the plugin's ID and the second its version.
/// </param>
/// <returns>An array of strings containing plugin IDs</returns>
- /// <exception cref="Capuchin.NoSuchPluginException">
- /// Thrown when given plugin is not in the repository
- /// </exception>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <exception cref="Capuchin.NoSuchPluginException">
+ /// Thrown when given plugin is not in the repository
+ /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string[] GetAvailableUpdates (string[][] plugins)
{
Log.Info("Getting updates");
-
- this.RepoInitialized ();
+
+ this.RepoInitialized ();
List<string> updates = new List<string>();
- foreach (string[] p in plugins)
- {
- string plugin_id = p[0];
+ foreach (string[] p in plugins)
+ {
+ string plugin_id = p[0];
this.PluginIdExists (plugin_id);
string repo_version = this.RepoItems[plugin_id].Version;
@@ -203,19 +202,19 @@
/// Update the plugin with ID <code>plugin_id</code>
/// </summary>
/// <param name="plugin_id">Plugin's ID</param>
- /// <exception cref="Capuchin.NoSuchPluginException">
- /// Thrown when given plugin is not in the repository
- /// </exception>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <exception cref="Capuchin.NoSuchPluginException">
+ /// Thrown when given plugin is not in the repository
+ /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public void Install (string plugin_id)
{
Log.Info("Updating plugin with id '{0}'", plugin_id);
- this.RepoInitialized ();
- this.PluginIdExists (plugin_id);
-
+ this.RepoInitialized ();
+ this.PluginIdExists (plugin_id);
+
int dlid = Globals.DLM.DownloadFile(this.RepoItems[plugin_id].Url, this.InstallPath, this.RepoItems[plugin_id].Signature, this.RepoItems[plugin_id].Checksum);
lock (this) {
@@ -229,81 +228,81 @@
/// </summary>
/// <param name="tag">A tag</param>
/// <returns>A list of plugin IDs</returns>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string[] GetPluginsWithTag (string tag)
{
- Log.Info ("Getting plugins with tag '{0}'", tag);
-
- this.RepoInitialized ();
-
- tag = tag.Trim().ToLower ();
- if (!this.TagToPlugins.ContainsKey (tag)) {
- return new string[] {};
- }
-
- List<string> pluginList = this.TagToPlugins[tag];
- string[] plugins = new string[pluginList.Count];
- pluginList.CopyTo (plugins, 0);
+ Log.Info ("Getting plugins with tag '{0}'", tag);
+
+ this.RepoInitialized ();
+
+ tag = tag.Trim().ToLower ();
+ if (!this.TagToPlugins.ContainsKey (tag)) {
+ return new string[] {};
+ }
+
+ List<string> pluginList = this.TagToPlugins[tag];
+ string[] plugins = new string[pluginList.Count];
+ pluginList.CopyTo (plugins, 0);
return plugins;
}
/// <summary>
/// Get name of plugin with given <code>plugin_id</code>
/// </summary>
- /// <exception cref="Capuchin.NoSuchPluginException">
- /// Thrown when given plugin is not in the repository
- /// </exception>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <exception cref="Capuchin.NoSuchPluginException">
+ /// Thrown when given plugin is not in the repository
+ /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string GetPluginName (string plugin_id)
{
- Log.Info ("Getting name of plugin '{0}'", plugin_id);
-
- this.RepoInitialized ();
- this.PluginIdExists (plugin_id);
-
+ Log.Info ("Getting name of plugin '{0}'", plugin_id);
+
+ this.RepoInitialized ();
+ this.PluginIdExists (plugin_id);
+
return this.RepoItems[plugin_id].Name;
}
/// <summary>
/// Get description for given <code>plugin_id</code>
/// </summary>
- /// <exception cref="Capuchin.NoSuchPluginException">
- /// Thrown when given plugin is not in the repository
- /// </exception>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <exception cref="Capuchin.NoSuchPluginException">
+ /// Thrown when given plugin is not in the repository
+ /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string GetPluginDescription (string plugin_id)
{
- Log.Info ("Getting description of plugin '{0}'", plugin_id);
-
- this.RepoInitialized ();
- this.PluginIdExists (plugin_id);
-
+ Log.Info ("Getting description of plugin '{0}'", plugin_id);
+
+ this.RepoInitialized ();
+ this.PluginIdExists (plugin_id);
+
return this.RepoItems[plugin_id].Description;
}
/// <summary>
/// Get changes for plugin with given ID made in given version
/// </summary>
- /// <exception cref="Capuchin.NoSuchPluginException">
- /// Thrown when given plugin is not in the repository
- /// </exception>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <exception cref="Capuchin.NoSuchPluginException">
+ /// Thrown when given plugin is not in the repository
+ /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string GetPluginChanges (string plugin_id, string version)
{
- Log.Info ("Getting changes in version {0} of plugin '{1}'", version, plugin_id);
-
- this.RepoInitialized ();
- this.PluginIdExists (plugin_id);
-
- changelog changes = this.RepoItems[plugin_id].Changelog;
+ Log.Info ("Getting changes in version {0} of plugin '{1}'", version, plugin_id);
+
+ this.RepoInitialized ();
+ this.PluginIdExists (plugin_id);
+
+ changelog changes = this.RepoItems[plugin_id].Changelog;
if (changes != null && changes.ContainsKey (version))
{
return this.RepoItems[plugin_id].Changelog[version];
@@ -317,19 +316,19 @@
/// </summary>
/// <param name="plugin_id">Plugin's ID</param>
/// <returns>An array of tags</returns>
- /// <exception cref="Capuchin.NoSuchPluginException">
- /// Thrown when given plugin is not in the repository
- /// </exception>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <exception cref="Capuchin.NoSuchPluginException">
+ /// Thrown when given plugin is not in the repository
+ /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string[] GetPluginTags (string plugin_id)
{
Log.Info("Getting tags for plugin with id '{0}'", plugin_id);
-
- this.RepoInitialized ();
- this.PluginIdExists (plugin_id);
-
+
+ this.RepoInitialized ();
+ this.PluginIdExists (plugin_id);
+
string[] tags = this.RepoItems[plugin_id].Tags;
return (tags == null) ? new string[] {} : tags;
}
@@ -342,57 +341,57 @@
/// An array whereas the first entry ist the author's name
/// and the second entry the author's e-mail
/// </returns>
- /// <exception cref="Capuchin.NoSuchPluginException">
- /// Thrown when given plugin is not in the repository
- /// </exception>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <exception cref="Capuchin.NoSuchPluginException">
+ /// Thrown when given plugin is not in the repository
+ /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string[] GetPluginAuthor (string plugin_id)
{
Log.Info("Getting author of plugin with id '{0}'", plugin_id);
- this.RepoInitialized ();
- this.PluginIdExists (plugin_id);
-
+ this.RepoInitialized ();
+ this.PluginIdExists (plugin_id);
+
author plugin_author = this.RepoItems[plugin_id].Author;
return new string[] { plugin_author.Name, plugin_author.Email };
}
- /// <param name="plugin_id">Plugin's ID</param>
- /// <returns>The version of the plugin</returns>
- /// <exception cref="Capuchin.NoSuchPluginException">
- /// Thrown when given plugin is not in the repository
- /// </exception>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
- public string GetPluginVersion (string plugin_id)
- {
- Log.Info ("Getting version of plugin {0}", plugin_id);
-
- this.RepoInitialized ();
- this.PluginIdExists (plugin_id);
-
- return this.RepoItems[plugin_id].Version;
- }
-
- /// <summary>
- /// Get all available tags available in this repository
- /// </summary>
- /// <returns>A list of tags</returns>
- /// <exception cref="Capuchin.RepositoryNotInitializedException">
- /// Thrown when the Update method hasn't been called before
- /// </exception>
+ /// <param name="plugin_id">Plugin's ID</param>
+ /// <returns>The version of the plugin</returns>
+ /// <exception cref="Capuchin.NoSuchPluginException">
+ /// Thrown when given plugin is not in the repository
+ /// </exception>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
+ public string GetPluginVersion (string plugin_id)
+ {
+ Log.Info ("Getting version of plugin {0}", plugin_id);
+
+ this.RepoInitialized ();
+ this.PluginIdExists (plugin_id);
+
+ return this.RepoItems[plugin_id].Version;
+ }
+
+ /// <summary>
+ /// Get all available tags available in this repository
+ /// </summary>
+ /// <returns>A list of tags</returns>
+ /// <exception cref="Capuchin.RepositoryNotInitializedException">
+ /// Thrown when the Update method hasn't been called before
+ /// </exception>
public string[] GetTags ()
{
- Log.Info ("Getting all tags in the repository");
-
- this.RepoInitialized ();
-
- ICollection<string> tagsCol = this.TagToPlugins.Keys;
- string[] tags = new string[tagsCol.Count];
- tagsCol.CopyTo (tags, 0);
+ Log.Info ("Getting all tags in the repository");
+
+ this.RepoInitialized ();
+
+ ICollection<string> tagsCol = this.TagToPlugins.Keys;
+ string[] tags = new string[tagsCol.Count];
+ tagsCol.CopyTo (tags, 0);
return tags;
}
@@ -410,8 +409,8 @@
/// <param name="checksumField">Checksum information</param>
internal void CheckFile (string local_file, string signature, checksum checksumField)
{
- Log.Info ("Checking file");
-
+ Log.Info ("Checking file");
+
if (checksumField != null)
{
FileStream fs = new FileStream( local_file, FileMode.Open );
@@ -443,60 +442,60 @@
/// <summary>Actually install the file</summary>
/// <param name="local_file_obj">
- /// A <see cref="System.String" /> where the file is located
- /// </param>
+ /// A <see cref="System.String" /> where the file is located
+ /// </param>
protected void InstallFileReal (object local_file_obj)
{
- Log.Info ("Installing file");
-
+ Log.Info ("Installing file");
+
string local_file = (string)local_file_obj;
- IInstaller installer = new SimpleInstaller (this.InstallPath);
- installer.InstallFile (local_file);
+ IInstaller installer = new SimpleInstaller (this.InstallPath);
+ installer.InstallFile (local_file);
+ }
+
+ protected void fillTagToPlugins ()
+ {
+ this.TagToPlugins.Clear ();
+
+ foreach (item itemEntry in this.RepoItems.Values)
+ {
+ this.addPluginToTags (itemEntry);
+ }
+ }
+
+ protected void addPluginToTags (item pluginItem)
+ {
+ if (pluginItem.Tags == null) return;
+
+ foreach (string tag in pluginItem.Tags)
+ {
+ string lowertag = tag.Trim().ToLower ();
+ // Check if list for tag already exists
+ if (!this.TagToPlugins.ContainsKey (lowertag))
+ {
+ // Create new List
+ this.TagToPlugins.Add (lowertag, new List<string> ());
+ }
+ // Add plugin's id to list
+ this.TagToPlugins[lowertag].Add (pluginItem.Id);
+ }
+ }
+
+ protected void PluginIdExists (string plugin_id)
+ {
+ if (!this.RepoItems.ContainsKey (plugin_id)) {
+ throw new NoSuchPluginException ("The repository does not contain a plugin with ID "+plugin_id);
+ }
}
-
- protected void fillTagToPlugins ()
- {
- this.TagToPlugins.Clear ();
-
- foreach (item itemEntry in this.RepoItems.Values)
- {
- this.addPluginToTags (itemEntry);
- }
- }
-
- protected void addPluginToTags (item pluginItem)
- {
- if (pluginItem.Tags == null) return;
-
- foreach (string tag in pluginItem.Tags)
- {
- string lowertag = tag.Trim().ToLower ();
- // Check if list for tag already exists
- if (!this.TagToPlugins.ContainsKey (lowertag))
- {
- // Create new List
- this.TagToPlugins.Add (lowertag, new List<string> ());
- }
- // Add plugin's id to list
- this.TagToPlugins[lowertag].Add (pluginItem.Id);
- }
- }
-
- protected void PluginIdExists (string plugin_id)
- {
- if (!this.RepoItems.ContainsKey (plugin_id)) {
- throw new NoSuchPluginException ("The repository does not contain a plugin with ID "+plugin_id);
- }
- }
-
- protected void RepoInitialized ()
- {
- if (this.RepoItems == null) {
- throw new RepositoryNotInitializedException ("The repository is not initialized. You have to call Update first.");
- }
- }
-
+
+ protected void RepoInitialized ()
+ {
+ if (this.RepoItems == null) {
+ throw new RepositoryNotInitializedException ("The repository is not initialized. You have to call Update first.");
+ }
+ }
+
protected void OnUpdateFinished ()
{
if (UpdateFinished != null)
@@ -549,7 +548,7 @@
wresp.Close();
return (File.GetLastWriteTime(this.LocalRepo) >= remoteModTime);
} catch (WebException e) {
- throw new RepositoryConnectionException("Connection to repository "+this.RepositoryURL+" failed: "+e.Message, e);
+ throw new RepositoryConnectionException("Connection to repository "+this.RepositoryURL+" failed: "+e.Message, e);
}
}
@@ -571,7 +570,6 @@
private void OnDownloadFinished (int dlid)
{
if (dlid == this.repo_dlid) {
- this.LoadRepository();
return;
}
@@ -589,7 +587,7 @@
// Install file
Thread installThread = new Thread( new ParameterizedThreadStart( this.InstallFileReal ) );
- installThread.Start( local_file );
+ installThread.Start( local_file );
while (installThread.IsAlive)
{
this.OnStatus( ActionType.ExtractingPlugin, plugin_id, -1.0, -1);
Modified: trunk/src/libcapuchin/DownloadManager.cs
==============================================================================
--- trunk/src/libcapuchin/DownloadManager.cs (original)
+++ trunk/src/libcapuchin/DownloadManager.cs Wed Apr 2 21:12:26 2008
@@ -16,14 +16,17 @@
public delegate void DownloaderDel(object startPoint);
+ public const int BLOCKING_DOWNLOAD_ID = -1;
+
internal Dictionary<int, Download> Downloads;
private int downloadsIndex;
+ private int blockingDownloadId;
public DownloadManager()
{
this.Downloads = new Dictionary<int, Download>();
- this.downloadsIndex = 0;
+ this.downloadsIndex = 0;
}
/// <summary>Download a file using the DownloadManager</summary>
@@ -39,7 +42,8 @@
/// An <see cref="Capuchin.Downloaders.AbstractDownloader" /> instance to
/// download the given file
/// </returns>
- internal int DownloadFile (string download_url, string download_dest, string signature, checksum checksumField)
+ internal int DownloadFile (string download_url, string download_dest,
+ string signature, checksum checksumField)
{
Download dl = new Download(this.downloadsIndex, download_url, download_dest, signature, checksumField);
@@ -55,25 +59,37 @@
downloaderThread.Start();
}
- Log.Info("Started downloading file {0} to {1} with id '{2}'", download_url, download_dest, this.downloadsIndex-1);
+ Log.Info("Started downloading file {0} to {1} with id '{2}'",
+ download_url, download_dest, this.downloadsIndex-1);
return (this.downloadsIndex-1);
}
+
+ internal void DownloadFileBlocking (string download_url, string download_dest)
+ {
+ Download dl = new Download(this.downloadsIndex, download_url, download_dest, null, null);
+
+ Downloaders.AbstractDownloader downloader = this.GetDownloader(BLOCKING_DOWNLOAD_ID, dl);
+ downloader.Status += new Downloaders.StatusHandler( this.OnDownloadStatus );
+ downloader.Finished += new Downloaders.FinishedHandler( this.DownloadFinishedCallback );
+
+ downloader.Download ();
+ }
/// <summary>Pause download</summary>
/// <param name="id">
- /// Download id as returned by <see cref="Capuchin.DownloadManager.DownloadFile" />
- /// </param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when download id doesn't exist
- /// </exception>
+ /// Download id as returned by <see cref="Capuchin.DownloadManager.DownloadFile" />
+ /// </param>
+ /// <exception cref="System.ArgumentOutOfRangeException">
+ /// Thrown when download id doesn't exist
+ /// </exception>
public virtual void PauseDownload(int id)
{
- Log.Info("Paused download with id '{0}'", id);
-
- if (!this.Downloads.ContainsKey (id)) {
- throw new ArgumentOutOfRangeException ("A download with id "+id+" does not exist");
- }
+ Log.Info("Paused download with id '{0}'", id);
+
+ if (!this.Downloads.ContainsKey (id)) {
+ throw new ArgumentOutOfRangeException ("A download with id "+id+" does not exist");
+ }
lock (this) {
// Kill Downloader Thread
@@ -85,16 +101,16 @@
/// <param name="id">
/// Download id as returned by <see cref="Capuchin.DownloadManager.DownloadFile" />
/// </param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when download id doesn't exist
- /// </exception>
+ /// <exception cref="System.ArgumentOutOfRangeException">
+ /// Thrown when download id doesn't exist
+ /// </exception>
public virtual void AbortDownload(int id)
{
Log.Info("Aborted download with id '{0}'", id);
-
- if (!this.Downloads.ContainsKey (id)) {
- throw new ArgumentOutOfRangeException ("A download with id "+id+" does not exist");
- }
+
+ if (!this.Downloads.ContainsKey (id)) {
+ throw new ArgumentOutOfRangeException ("A download with id "+id+" does not exist");
+ }
lock (this) {
this.PauseDownload(id);
@@ -107,15 +123,15 @@
/// <param name="id">
/// Download id as returned by <see cref="Capuchin.DownloadManager.DownloadFile" />
/// </param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when download id doesn't exist
- /// </exception>
+ /// <exception cref="System.ArgumentOutOfRangeException">
+ /// Thrown when download id doesn't exist
+ /// </exception>
public virtual void ResumeDownload(int id)
{
- if (!this.Downloads.ContainsKey (id)) {
- throw new ArgumentOutOfRangeException ("A download with id "+id+" does not exist");
- }
-
+ if (!this.Downloads.ContainsKey (id)) {
+ throw new ArgumentOutOfRangeException ("A download with id "+id+" does not exist");
+ }
+
// Get file info
FileInfo f = new FileInfo( this.Downloads[id].LocalFile );
@@ -154,13 +170,22 @@
}
}
- protected void DownloadFinishedCallback(int id)
+ private void DownloadFinishedCallback(Downloaders.AbstractDownloader downloader, int id)
{
Log.Info("Finished downloading file with id '{0}'", id);
+ // Don't report finished signal when download is called blocking
+ if (id == BLOCKING_DOWNLOAD_ID) return;
+
lock (this) {
// Remove Download
this.Downloads.Remove(id);
+
+ // TODO: Maybe dangerous when disconnecting while other download
+ // is still running?
+ // Disconnect signals
+ downloader.Status -= new Downloaders.StatusHandler( this.OnDownloadStatus );
+ downloader.Finished -= new Downloaders.FinishedHandler( this.DownloadFinishedCallback );
}
this.OnDownloadFinished(id);
Modified: trunk/src/libcapuchin/Downloaders/AbstractDownloader.cs
==============================================================================
--- trunk/src/libcapuchin/Downloaders/AbstractDownloader.cs (original)
+++ trunk/src/libcapuchin/Downloaders/AbstractDownloader.cs Wed Apr 2 21:12:26 2008
@@ -8,7 +8,7 @@
{
internal delegate void StatusHandler(int id, double progress, int speed);
- internal delegate void FinishedHandler(int id);
+ internal delegate void FinishedHandler(AbstractDownloader downloader, int id);
/// <summary>Abstract base class to download a file</summary>
internal abstract class AbstractDownloader : IDisposable
@@ -75,7 +75,7 @@
/// <summary>Emits the finished signal</summary>
protected void OnFinished() {
if (Finished != null) {
- Finished(this.Id);
+ Finished(this, this.Id);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]