Example #1
0
 private void SetTileFinishedDownloading(TileSpecifier specifier)
 {
     lock (CurrentDownloads)
     {
         CurrentDownloads.Remove(specifier);
     }
 }
        private void downloader_DownloadProgress(DownloadOperation downloadOperation)
        {
            var appDownloadItem = CurrentDownloads.SingleOrDefault(item =>
                                                                   (item.Tag as DownloadOperation).Guid == downloadOperation.Guid);

            if (appDownloadItem == null)
            {
                return;
            }
            appDownloadItem.BytesReceived = downloadOperation.Progress.BytesReceived;
            appDownloadItem.SetStatus(downloadOperation.Progress.Status);

            // When this event handler is occured for first time (for a specefic DownloadOperation),
            // appDownloadItem.TotalBytesToReceive is zero
            if (appDownloadItem.TotalBytesToReceive == 0)
            {
                appDownloadItem.TotalBytesToReceive = downloadOperation.Progress.TotalBytesToReceive;
            }

            // OS might not report a download completion event, we should check this.
            if ((downloadOperation.Progress.BytesReceived == downloadOperation.Progress.TotalBytesToReceive) &&
                (downloadOperation.Progress.BytesReceived > 0))
            {
                appDownloadItem.SetStatus(BackgroundTransferStatus.Completed);
            }

            if (appDownloadItem.GetStatus() == BackgroundTransferStatus.Completed)
            {
                appDownloadItem.EndDate = DateTime.Now;
                CurrentDownloads.Remove(appDownloadItem);
                CompletedDownloads.Add(appDownloadItem);
                var task = SaveDownloadsHistoryToFileAsync();
                if (this.DownloadCompleted != null)
                {
                    DownloadCompleted(appDownloadItem);
                }
            }

            if (this.DownloadProgress != null)
            {
                DownloadProgress(appDownloadItem);
            }
        }