Problem with file downloader

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im quite new to C# and currently building a WPF app to download multiple files. I have a ListBox in it that will display currently downloading files with progress bar, download speed, size, an image and title. Thats why I created a ViewModel and Model
classes to bind the data to the view.
<br/>
Problem is that my downloads have multiple files.
<br/>
Simple example:
Download 1: setup.exe, setup.bin, setup-1.bin<br/>
Download 2: install.exe<br/>
Download 3: program.exe, program.bim, program-1.bin, program-2.bin
<br/>
I need to download all the files in chunks (server returns the info in xml format):
<br/>
<file name="setup.exe" available="1" notavailablemsg="" md5="d3d52dd30d6a4a288c529b2c655510fb" chunks="1" timestamp="2011-09-30 10:05:03" total_size="2438405 <br/>
<chunk id="0" from="0" to="2438404" method="md5 d3d52dd30d6a4a288c529b2c655510fb</chunk><br/>
</file>
<br/>
I found a good downloader app example here ( http://www.codeproject.com/KB/cs/BackgroundFileDownloader.aspx http://www.codeproject.com/KB/cs/BackgroundFileDownloader.aspx ), with a downloader class that is doing all the work
with the downloads. Problem is that it does not support multiple files per download and it only has one progress bar, not one for each file. Of course I need to be able to pause one download and resume another. This app only let me pause whole download.
<br/>
Can anyone point me in the right direction? What changes need to be done to the above example to get it working for me? Or just give me some general ideas on how to implement it.
<br/>
Thanks in advance,<br/>
Peter
<br/>

<div style="color:black; background-color:white
<pre><span style="color:blue using System;
<span style="color:blue using System.Collections.Generic;
<span style="color:blue using System.Linq;
<span style="color:blue using System.Text;
<span style="color:blue using System.Collections.ObjectModel;
<span style="color:blue using App.Model;
<span style="color:blue using System.Windows.Media;
<span style="color:blue using System.Web.Script.Serialization;
<span style="color:blue using System.Windows;
<span style="color:blue using System.Net;

<span style="color:blue namespace App.ViewModels
{
<span style="color:blue class DownloadsViewModel
{
<span style="color:blue private ObservableCollection<Download> _downloads = <span style="color:blue new ObservableCollection<Download>();
<span style="color:blue public ObservableCollection<Download> Downloads
{
<span style="color:blue get { <span style="color:blue return _downloads; }
<span style="color:blue set { _downloads = value; }
}
}
}
[/code]


<br/>

<div style="color:black; background-color:white
<pre><span style="color:blue using System;
<span style="color:blue using System.Collections.Generic;
<span style="color:blue using System.Linq;
<span style="color:blue using System.Text;
<span style="color:blue using System.Windows.Media;
<span style="color:blue using System.ComponentModel;

<span style="color:blue namespace App.Model
{
<span style="color:blue class Download
{
<span style="color:blue private <span style="color:blue string _name { <span style="color:blue get; <span style="color:blue set; }
<span style="color:blue public <span style="color:blue string Name
{
<span style="color:blue get { <span style="color:blue return _name; }
<span style="color:blue set
{
_name = value;
}
}
<span style="color:blue private <span style="color:blue int _progress { <span style="color:blue get; <span style="color:blue set; }
<span style="color:blue public <span style="color:blue int Progress
{
<span style="color:blue get { <span style="color:blue return _progress; }
<span style="color:blue set
{
_progress = value;
RaisePropertyChanged(<span style="color:#a31515 "Progress");
}
}
<span style="color:blue private Uri _image { <span style="color:blue get; <span style="color:blue set; }
<span style="color:blue public Uri Image
{
<span style="color:blue get { <span style="color:blue return _image; }
<span style="color:blue set
{
_image = value;
}
}
<span style="color:blue private <span style="color:blue decimal _size { <span style="color:blue get; <span style="color:blue set; }
<span style="color:blue public <span style="color:blue decimal Size
{
<span style="color:blue get { <span style="color:blue return _size; }
<span style="color:blue set
{
_size = value;
}
}
<span style="color:blue private SolidColorBrush _color { <span style="color:blue get; <span style="color:blue set; }
<span style="color:blue public SolidColorBrush Color
{
<span style="color:blue get { <span style="color:blue return _color; }
<span style="color:blue set
{
_color = value;
RaisePropertyChanged(<span style="color:#a31515 "Color");
}
}

<span style="color:blue private DownloadStatus _status { <span style="color:blue get; <span style="color:blue set; }
<span style="color:blue public DownloadStatus Status
{
<span style="color:blue get { <span style="color:blue return _status; }
<span style="color:blue set
{
_status = value;
RaisePropertyChanged(<span style="color:#a31515 "DownloadStatus");
}
}

<span style="color:blue private <span style="color:blue decimal _downloaded { <span style="color:blue get; <span style="color:blue set; }
<span style="color:blue public <span style="color:blue decimal Downloaded
{
<span style="color:blue get { <span style="color:blue return _downloaded; }
<span style="color:blue set
{
_downloaded = value;
RaisePropertyChanged(<span style="color:#a31515 "Downloaded");
}
}

<span style="color:blue private <span style="color:blue string _downloadProgress { <span style="color:blue get; <span style="color:blue set; }
<span style="color:blue public <span style="color:blue string DownloadProgress
{
<span style="color:blue get
{
<span style="color:blue if (Size == 0)
{
<span style="color:blue return <span style="color:#a31515 "Fetching game size...";
}
<span style="color:blue else
{
<span style="color:blue return <span style="color:blue string.Format(<span style="color:#a31515 "{0} MB of {1} MB", Downloaded, Size);
}
}
<span style="color:blue set
{
_downloadProgress = value;
}
}

<span style="color:blue public <span style="color:blue enum DownloadStatus
{
Downloading,
Paused
}

<span style="color:blue public <span style="color:blue event PropertyChangedEventHandler PropertyChanged;

<span style="color:blue private <span style="color:blue void RaisePropertyChanged(<span style="color:blue string propertyName)
{
<span style="color:blue if (<span style="color:blue this.PropertyChanged != <span style="color:blue null)
{
<span style="color:blue this.PropertyChanged(<span style="color:blue this, <span style="color:blue new PropertyChangedEventArgs(propertyName));
}
}
}
}
[/code]


<br/>
<br/>
<br/>
<br/>

View the full article
 
Back
Top