void client_StatusChanged(object sender, EventArgs e)
{
// If all the clients are completed, then the status of this downloader is
// completed.
if (this.downloadClients.All(
client => client.Status == DownloadStatus.Completed))
{
this.Status = DownloadStatus.Completed;
}
// If all the clients are Canceled, then the status of this downloader is
// Canceled.
else if (this.downloadClients.All(
client => client.Status == DownloadStatus.Canceled))
{
this.Status = DownloadStatus.Canceled;
}
else
{
// The completed clients will not be taken into consideration.
var nonCompletedClients = this.downloadClients.
Where(client => client.Status != DownloadStatus.Completed);
// If all the nonCompletedClients are Waiting, then the status of this
// downloader is Waiting.
if (nonCompletedClients.All(
client => client.Status == DownloadStatus.Waiting))
{
this.Status = DownloadStatus.Waiting;
}
// If all the nonCompletedClients are Paused, then the status of this
// downloader is Paused.
else if (nonCompletedClients.All(
client => client.Status == DownloadStatus.Paused))
{
this.Status = DownloadStatus.Paused;
}
else if (this.Status != DownloadStatus.Pausing
&& this.Status != DownloadStatus.Canceling)
{
this.Status = DownloadStatus.Downloading;
}
}
}