public ReleaseInfo ToReleaseInfo() {
                var r = new ReleaseInfo {
                    Name = String.IsNullOrWhiteSpace(Name) ? TagName : Name,
                    ReleaseNotes = Body,
                    PublishedAt = PublishedAt,
                    CreatedAt = CreatedAt,
                    HtmlUrl = HtmlUrl,
                    TagName = TagName,
                    IsPrerelease = Prerelease,
                };
                var asset = Assets.FirstOrDefault(a => a.Name.EndsWith(".msi"));
                if (asset != null) {
                    r.Filename = asset.Name;
                    r.DownloadUrl = asset.Url;
                }

                var match = Regex.Match(r.TagName, @"^v(?<major>\d+)\.(?<minor>\d+)(\.(?<patch>\d+))?$");
                if (match.Success) {
                    int major, minor, patch;
                    Int32.TryParse(match.Groups["major"].Value, out major);
                    Int32.TryParse(match.Groups["minor"].Value, out minor);
                    if (Int32.TryParse(match.Groups["patch"].Value, out patch)) {
                        r.Version = new Version(major, minor, patch);
                    } else {
                        r.Version = new Version(major, minor);
                    }
                }

                return r;
            }
 public abstract Task<string> DownloadReleasePackage(ReleaseInfo releaseInfo, Action<int> downloadProgressCallback, CancellationToken cancellationToken);
 public override async Task<string> DownloadReleasePackage(ReleaseInfo releaseInfo, Action<int> downloadProgressCallback, CancellationToken cancellationToken) {
     var destination = Path.Combine(Path.GetTempPath(), releaseInfo.Filename);
     if (File.Exists(destination)) {
         File.Delete(destination);
         Thread.Sleep(100);
     }
     using (var webClient = new WebClient()) {
         webClient.Headers.Add("Accept", "application/octet-stream");
         if (downloadProgressCallback != null) {
             webClient.DownloadProgressChanged += (sender, args) => downloadProgressCallback(args.ProgressPercentage);
         }
         cancellationToken.Register(webClient.CancelAsync);
         _log.Debug("Downloading release from {0} to {1}", releaseInfo.DownloadUrl, destination);
         await webClient.DownloadFileTaskAsync(releaseInfo.DownloadUrl, destination);
     }
     return destination;
 }
 public async override Task<string> DownloadReleasePackage(ReleaseInfo releaseInfo, Action<int> downloadProgressCallback, CancellationToken cancellationToken) {
     for (var i = 0; i < 50; ++i) {
         if (downloadProgressCallback != null) {
             downloadProgressCallback(i*2);
         }
         if (cancellationToken.IsCancellationRequested) {
             return null;
         }
         await Task.Delay(100, cancellationToken);
     }
     return String.Empty;
 }
        protected override async Task<List<ReleaseInfo>> GetReleasesAsync() {
            var github = new GitHubClient(new ProductHeaderValue("Solutionizer", AppEnvironment.CurrentVersion.ToString()));
            var result = new List<ReleaseInfo>();
            foreach (var release in await github.Release.GetAll(GitHubOwner, GitHubRepository)) {
                var r = new ReleaseInfo {
                    Name = String.IsNullOrWhiteSpace(release.Name) ? release.TagName : release.Name,
                    ReleaseNotes = release.Body,
                    PublishedAt = release.PublishedAt,
                    CreatedAt = release.CreatedAt,
                    HtmlUrl = release.HtmlUrl,
                    TagName = release.TagName,
                    IsPrerelease = release.Prerelease,
                };

                var assets = await github.Release.GetAllAssets(GitHubOwner, GitHubRepository, release.Id);
                var asset = assets.FirstOrDefault(a => a.Name.EndsWith(".msi"));
                if (asset != null) {
                    r.Filename = asset.Name;
                    r.DownloadUrl = asset.Url;
                }

                var match = Regex.Match(r.TagName, @"^v(?<major>\d+)\.(?<minor>\d+)(\.(?<patch>\d+))?$");
                if (match.Success) {
                    int major, minor, patch;
                    Int32.TryParse(match.Groups["major"].Value, out major);
                    Int32.TryParse(match.Groups["minor"].Value, out minor);
                    if (Int32.TryParse(match.Groups["patch"].Value, out patch)) {
                        r.Version = new Version(major, minor, patch);
                    } else {
                        r.Version = new Version(major, minor);
                    }
                }
                result.Add(r);
            }
            return result;
        }
Example #6
0
 public Task<string> DownloadReleaseAsync(ReleaseInfo releaseInfo, Action<int> downloadProgressCallback, CancellationToken cancellationToken) {
     return _reader.DownloadReleasePackage(releaseInfo, downloadProgressCallback, cancellationToken);
 }