private void ProcessSingle()
        {
            // Delete temp file
            if (File.Exists(TAGS_FILENAME + ".!tmp"))
            {
                File.Delete(TAGS_FILENAME + ".!tmp");
            }

            Program.Logger.Info("[Download Tags] Start downloading...");
            client.DownloadFileAsync(new Uri(txtUrl.Text), TAGS_FILENAME + ".!tmp");
        }
Example #2
0
        public async Task <IStagedPackage> GetPackageAsync(IProgressReporter progressReporter, string buildCode,
                                                           string buildNumber)
        {
            progressReporter.SetProgressPercent(0);
            progressReporter.SetProgressStatus("Downloading package for build " + buildCode + " for version "
                                               + buildNumber);

            var tempFile = stagingLocation.CreateTempFile();

            using (var webclient = new ExtendedWebClient((int)DefaultTimeout.TotalMilliseconds))
            {
                var  tcs         = new TaskCompletionSource <bool>();
                byte lastPercent = 0;
                webclient.DownloadProgressChanged += (sender, args) =>
                {
                    var percent = (byte)(((double)args.BytesReceived / (double)args.TotalBytesToReceive) * 100);
                    if (percent > lastPercent)
                    {
                        lastPercent = percent;
                        progressReporter.SetProgressPercent(percent);
                    }
                };
                webclient.DownloadFileCompleted += (sender, args) =>
                {
                    if (args.Error != null)
                    {
                        progressReporter.SetProgressPercent(100);
                        progressReporter.SetProgressStatus("download error: " + args.Error.ToString());
                        tcs.SetException(new ServiceException("Download error", args.Error));
                    }
                    else
                    {
                        progressReporter.SetProgressStatus("download completed");
                        tcs.SetResult(true);
                    }
                };
                webclient.DownloadFileAsync(
                    new Uri(string.Format("{0}/Packages/{1}/{2}", webServiceRootUrl, buildCode, buildNumber)),
                    tempFile.FullName);

                await tcs.Task;

                return(stagingLocation.CreatePackageFromZipFile(tempFile.FullName));
            }
        }
        public async Task<IStagedPackage> GetPackageAsync(IProgressReporter progressReporter, Version version)
        {
            progressReporter.SetProgressPercent(0);
            progressReporter.SetProgressStatus("Downloading package for version " + version);

            var tempFile = stagingLocation.CreateTempFile();
            try
            {
                using (var webclient = new ExtendedWebClient((int)DefaultTimeout.TotalMilliseconds))
                {
                    var tcs = new TaskCompletionSource<bool>();
                    byte lastPercent = 0;
                    webclient.DownloadProgressChanged += (sender, args) =>
                    {
                        var percent = (byte)(((double)args.BytesReceived / (double)args.TotalBytesToReceive) * 100);
                        if (percent > lastPercent)
                        {
                            lastPercent = percent;
                            progressReporter.SetProgressPercent(percent);
                            progressReporter.SetProgressStatus(string.Format("Downloaded {0}/{1}",
                                args.BytesReceived,
                                args.TotalBytesToReceive));
                        }
                    };
                    webclient.DownloadFileCompleted += (sender, args) =>
                    {
                        if (args.Error != null)
                        {
                            progressReporter.SetProgressPercent(100);
                            progressReporter.SetProgressStatus("download error: " + args.Error.ToString());
                            tcs.SetException(new ServiceException("Download error", args.Error));
                        }
                        else
                        {
                            progressReporter.SetProgressStatus("download completed");
                            tcs.SetResult(true);
                        }
                    };
                    webclient.DownloadFileAsync(
                        new Uri(string.Format("{0}/Package/{1}", webServiceRootUrl, version.ToString().Replace(".", "-"))),
                        tempFile.FullName);

                    await tcs.Task;

                    return stagingLocation.CreatePackageFromSevenZipByteArray(File.ReadAllBytes(tempFile.FullName), version);
                }
            }
            finally
            {
                tempFile.Delete();
            }
        }