Esempio n. 1
0
        IObservable <Unit> downloadReleases(IEnumerable <ReleaseEntry> releasesToDownload, IObserver <int> progress = null)
        {
            progress = progress ?? new Subject <int>();
            IObservable <Unit> downloadResult = null;

            if (isHttpUrl(updateUrlOrPath))
            {
                var urls  = releasesToDownload.Select(x => String.Format("{0}/{1}", updateUrlOrPath, x.Filename));
                var paths = releasesToDownload.Select(x => Path.Combine(rootAppDirectory, "packages", x.Filename));

                downloadResult = urlDownloader.QueueBackgroundDownloads(urls, paths, progress);
            }
            else
            {
                var toIncrement = 100.0 / releasesToDownload.Count();

                // Do a parallel copy from the remote directory to the local
                var downloads = releasesToDownload.ToObservable()
                                .Select(x => fileSystem.CopyAsync(
                                            Path.Combine(updateUrlOrPath, x.Filename),
                                            Path.Combine(rootAppDirectory, "packages", x.Filename)))
                                .Merge(4)
                                .Publish();

                downloads
                .Scan(0.0, (acc, _) => acc + toIncrement)
                .Select(x => (int)x)
                .Subscribe(progress);

                downloadResult = downloads.TakeLast(1);
                downloads.Connect();
            }

            return(downloadResult.SelectMany(_ => checksumAllPackages(releasesToDownload)));
        }
Esempio n. 2
0
        public IObservable <int> DownloadReleases(IEnumerable <ReleaseEntry> releasesToDownload)
        {
            var noLock = checkForLock <int>();

            if (noLock != null)
            {
                return(noLock);
            }

            IObservable <int> downloadResult;

            if (isHttpUrl(updateUrlOrPath))
            {
                var urls  = releasesToDownload.Select(x => String.Format("{0}/{1}", updateUrlOrPath, x.Filename));
                var paths = releasesToDownload.Select(x => Path.Combine(rootAppDirectory, "packages", x.Filename));

                downloadResult = urlDownloader.QueueBackgroundDownloads(urls, paths);
            }
            else
            {
                var toIncrement = 100.0 / releasesToDownload.Count();

                // Do a parallel copy from the remote directory to the local
                downloadResult = releasesToDownload.ToObservable()
                                 .Select(x => fileSystem.CopyAsync(
                                             Path.Combine(updateUrlOrPath, x.Filename),
                                             Path.Combine(rootAppDirectory, "packages", x.Filename)))
                                 .Merge(4)
                                 .Scan(0.0, (acc, _) => acc + toIncrement)
                                 .Select(x => (int)x);
            }

            return(downloadResult
                   .Select(x => (int)(x * 0.95))
                   .Concat(checksumAllPackages(releasesToDownload).Select(_ => 100)));
        }