static void cl_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { DownloadJob j = (DownloadJob)e.UserState; j.status = string.Format("Downloading {0}: {1}% ({2}/{3})", j.name, e.ProgressPercentage, e.BytesReceived, e.TotalBytesToReceive); }
static void cl_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { DownloadJob job = (DownloadJob)e.UserState; if (e.Cancelled) { job.status = job.name + " Cancelled"; Console.WriteLine("Job was Cancelled!"); return; } if (e.Error != null) { job.status = job.name + " ERROR"; Console.WriteLine("Error: " + e.Error); lock (CountLock) { JobErrors.Add(string.Format("File {0} at {1} had error {2}", job.name, job.url, e.Error.Message)); DownloadingQueue.Remove(job); FilesBeingDownloaded--; } return; } byte[] data = e.Result; if (job.decompress) { job.status = job.name + " is Decompressing"; data = SevenZip.Compression.LZMA.SevenZipHelper.Decompress(data); } using (BinaryWriter wr = new BinaryWriter(File.Open(job.output + job.name, FileMode.OpenOrCreate))) { job.status = job.name + " is Writing"; if (data == null) { job.status = job.name + " NULL DATA"; return; } wr.Write(data); } job.status = job.name + " is Waiting on lock"; lock (CountLock) { int jobsLeft = DownloadQueue.Where(s => s.jobtag == job.jobtag).Count(); if (jobsLeft == 0) { JobCallbacks[job.jobtag](job.jobtag); FullDownloadJobComplete d; JobCallbacks.TryRemove(job.jobtag, out d); } FilesBeingDownloaded--; DownloadingQueue.Remove(job); } job.status = job.name + " Done"; Console.WriteLine(job.name + " is Done"); }