Beispiel #1
0
        public async Task <string> DownloadBuild(PixelExperienceBuild latestBuild)
        {
            var downloadLocation = new FileInfo(GetDownloadPath(latestBuild));

            await Spinner.StartAsync(GetDownloadingText(latestBuild), async spinner =>
            {
                using (var wc = new WebClient())
                {
                    wc.DownloadProgressChanged += (sender, args) =>
                                                  ProgressChanged(args.BytesReceived, spinner, args, latestBuild);

                    wc.DownloadFileCompleted += (sender, args) =>
                    {
                        if (!args.Cancelled && args.Error == null)
                        {
                            spinner.Succeed($"Downloaded {latestBuild.Name} successfully");
                        }
                        else
                        {
                            spinner.Fail(args.Error?.Message);
                        }
                    };

                    await wc.DownloadFileTaskAsync(latestBuild.Url, downloadLocation.FullName);
                }
            });


            return(downloadLocation.FullName);
        }
Beispiel #2
0
        private void ProgressChanged(long bytes, Spinner spinner, ProgressChangedEventArgs args,
                                     PixelExperienceBuild latestBuild)
        {
            if (_lastBytes == 0)
            {
                _lastUpdate = DateTime.Now;
                _lastBytes  = bytes;
                return;
            }

            var now      = DateTime.Now;
            var timeSpan = now - _lastUpdate;

            if (timeSpan.Seconds <= 0)
            {
                return;
            }

            var bytesChange    = bytes - _lastBytes;
            var bytesPerSecond = bytesChange / timeSpan.Seconds;

            _lastBytes  = bytes;
            _lastUpdate = now;

            spinner.Text =
                $"Downloading file {latestBuild.Name}... {args.ProgressPercentage}% @ {ByteSize.FromBytes(bytesPerSecond).KiloBytes}Kb/s";
        }
Beispiel #3
0
        private string GetDownloadPath(PixelExperienceBuild build)
        {
            var combine = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? throw new
                                       InvalidOperationException(), Parameters.DownloadPath);
            var dir = new DirectoryInfo(combine);

            if (!dir.Exists)
            {
                dir.Create();
            }

            return(Path.Combine(combine, build.Name));
        }
Beispiel #4
0
 private static string GetDownloadingText(PixelExperienceBuild latestBuild)
 {
     return($"Downloading file {latestBuild.Name}...");
 }