コード例 #1
0
        public IDownload DownloadFile(string url, string assetFilename = null)
        {
            Tuple <IDisposable, IDownload> currentDownload;

            if (CurrentDownloadDictionary.TryGetValue(url, out currentDownload))
            {
                return(currentDownload.Item2);
            }

            if (assetFilename != null)
            {
                var duplicateFile = DownloadQueue.FirstOrDefault(x => x.FileIdentifier == assetFilename);
                if (duplicateFile != null)
                {
                    return(duplicateFile);
                }
            }
            Download download = new Download(url, assetFilename ?? Guid.NewGuid().ToString());

            download.Status = DownloadStatus.Queued;
            Debug.WriteLine($"Enqueue: {download.FileIdentifier}");

            DownloadQueue.Enqueue(download);
            _downloadUpdateSubject.OnNext(download);
            StartQueue();

            return(download);
        }
コード例 #2
0
        public void CancelDownload(string url)
        {
            Tuple <IDisposable, IDownload> currentDownload;

            if (CurrentDownloadDictionary.TryGetValue(url, out currentDownload))
            {
                currentDownload.Item1.Dispose();
            }

            var downloads = _downloads.Where(x => x.Url == url).ToList();

            foreach (var download in downloads)
            {
                ((Download)download).Status = DownloadStatus.Cancelled;
                _downloads.Remove(download);
            }
        }