示例#1
0
 private void SetTileDownloading(TileSpecifier specifier)
 {
     lock (CurrentDownloads)
     {
         CurrentDownloads.Add(specifier);
     }
 }
示例#2
0
 private void SetTileFinishedDownloading(TileSpecifier specifier)
 {
     lock (CurrentDownloads)
     {
         CurrentDownloads.Remove(specifier);
     }
 }
        /// <summary>
        /// Discovers Current and Completed Downloads.
        /// </summary>
        public async Task DiscoverDownloadsAsync()
        {
            CurrentDownloads.Clear();
            CompletedDownloads.Clear();
            var currentDownloads = await _downloader.DiscoverBackgroundDownloadsAsync();

            foreach (var download in currentDownloads)
            {
                var status = download.Progress.Status;
                if (status == BackgroundTransferStatus.Canceled)
                {
                    continue;
                }

                var appDownloadItem = GetAppDownloadItem(download);
                appDownloadItem.Tag = download;

                if (status == BackgroundTransferStatus.Completed)
                {
                    CompletedDownloads.Add(appDownloadItem);
                }
                else
                {
                    CurrentDownloads.Add(appDownloadItem);
                }
            }
        }
        public async Task StartDownloadAsync(AppDownloadItem appDownloadItem)
        {
            await InitializeAsync();

            if (FindAppInCurrentDownloads(appDownloadItem.AppGuid) != null)
            {
                return;
            }

            // Start Download
            CurrentDownloads.Add(appDownloadItem);
            appDownloadItem.StorageFile = await CurrentApplication.AppDownloadFolder.CreateFileAsync(
                $"{appDownloadItem.AppGuid}.pstl",
                CreationCollisionOption.ReplaceExisting);

            var downloadOperation = await _downloader.StartDownloadAsync(
                ServerUri.GetAppDownloadUri(appDownloadItem.AppGuid),
                appDownloadItem.StorageFile);

            appDownloadItem.StartDate    = DateTime.Now;
            appDownloadItem.DownloadGuid = downloadOperation.Guid;
            appDownloadItem.Tag          = downloadOperation;

            // update collections
            _downloadsHistory.Add(appDownloadItem);
            await SaveDownloadsHistoryToFileAsync();
        }
        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);
            }
        }
示例#6
0
        public static MapsetDownload Download(int id)
        {
            // Require login in order to download.
            if (!OnlineManager.Connected)
            {
                NotificationManager.Show(NotificationLevel.Error, "You must be logged in to download mapsets!");
                return(null);
            }

            if (CurrentDownloads.Count >= MAX_CONCURRENT_DOWNLOADS)
            {
                NotificationManager.Show(NotificationLevel.Error, $"Slow down! You can only download {MAX_CONCURRENT_DOWNLOADS} at a time!");
                return(null);
            }

            var download = new MapsetDownload(id);

            CurrentDownloads.Add(download);

            return(download);
        }
示例#7
0
 public override ArchiveDownloadRequest <IScoreInfo> GetExistingDownload(IScoreInfo model)
 => CurrentDownloads.Find(r => r.Model.OnlineID == model.OnlineID);
 public AppDownloadItem FindAppInCurrentDownloads(Guid appGuid)
 {
     return(CurrentDownloads.SingleOrDefault(appDownloadItem => appDownloadItem.AppGuid == appGuid));
 }