Esempio n. 1
0
        public async Task <TransferInfo> AddTransfer(DownloadDefinition request)
        {
            await AssureInit();

            StorageFolder destinationFolder;

            switch (request.Storage)
            {
            case StorageType.AudioLibrary:
                destinationFolder = KnownFolders.MusicLibrary;
                break;

            default:
                destinationFolder = KnownFolders.VideosLibrary;
                break;
            }

            var destinationFile = await destinationFolder.CreateFileAsync(request.Filename, CreationCollisionOption.GenerateUniqueName);

            var downloader = new BackgroundDownloader();

            if (!string.IsNullOrEmpty(request.Username) && !string.IsNullOrEmpty(request.Password))
            {
                downloader.ServerCredential = new PasswordCredential(request.Source.ToString(), request.Username,
                                                                     request.Password);
            }
            var download = downloader.CreateDownload(request.Source, destinationFile);
            var progress = new DownloadProgress(download);

            download.StartAsync().AsTask(progress);
            _activeDownloads.Add(download.Guid, progress);
            return(progress.TransferInfo);
        }
Esempio n. 2
0
        private async Task Init()
        {
            var activeDownloads = await BackgroundDownloader.GetCurrentDownloadsAsync();

            var progresses = new Dictionary <Guid, DownloadProgress>();

            foreach (var downloadOperation in activeDownloads)
            {
                var progress = new DownloadProgress(downloadOperation);
                downloadOperation.AttachAsync().AsTask(progress);
                progresses.Add(downloadOperation.Guid, progress);
            }
            _activeDownloads = progresses;
        }