private void IssueIconQuery(string name, string ver, string tfm, PackageGlyphTag t) { IPackageFeedSearchJob <IPackageInfo> job = _searchManager.SearchPackageInfo(name, ver, tfm); EventHandler handler = null; string currentIcon = null; handler = (o, e) => { if (job.IsCancelled) { job.Updated -= handler; job = _searchManager.SearchPackageInfo(name, ver, tfm); job.Updated += handler; handler(o, e); return; } IPackageInfo package = job.Results.OrderByDescending(x => SemanticVersion.Parse(x.Version)).FirstOrDefault(); if (package != null) { if (string.IsNullOrEmpty(package.IconUrl) || package.IconUrl == currentIcon) { return; } if (Uri.TryCreate(package.IconUrl, UriKind.Absolute, out Uri iconUri)) { string proposedIcon = package.IconUrl; ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (currentIcon == proposedIcon) { return; } currentIcon = proposedIcon; BitmapImage img = new BitmapImage(iconUri); t.PackageIcon.Source = img; }); } } }; job.Updated += handler; handler(null, EventArgs.Empty); }
public PackageInfoControl(string packageId, string version, string tfm, IPackageSearchManager searcher) { InitializeComponent(); PackageId.Content = packageId; Glyph.Source = WpfUtil.MonikerToBitmap(KnownMonikers.NuGet, 32); Glyph.ImageFailed += OnImageFailed; _job = searcher.SearchPackageInfo(packageId, version, tfm); _job.Updated += JobUpdated; _firstRun = true; JobUpdated(null, EventArgs.Empty); }
public static Task <IReadOnlyList <IPackageInfo> > SearchPackageInfo( this IPackageSearchManager manager, string packageId, string packageVersion, string tfm, CancellationToken cancelToken) { var search = manager.SearchPackageInfo(packageId, packageVersion, tfm); if (search.RemainingFeeds.Count == 0) { return(Task.FromResult(search.Results)); } var tcs = new TaskCompletionSource <IReadOnlyList <IPackageInfo> > (); //making sure we actually unregister the eventhandler is kinda tricky //it could be already completed, or it could complete after we check but before we register EventHandler handleSearchUpdated = null; cancelToken.Register(() => { search.Cancel(); if (tcs.TrySetCanceled()) { search.Updated -= handleSearchUpdated; } }); handleSearchUpdated = (s, a) => { if (!cancelToken.IsCancellationRequested && search.RemainingFeeds.Count == 0) { if (tcs.TrySetResult(search.Results)) { search.Updated -= handleSearchUpdated; } } }; search.Updated += handleSearchUpdated; if (search.RemainingFeeds.Count == 0) { handleSearchUpdated(search, EventArgs.Empty); } return(tcs.Task); }
public override Task <TooltipInformation> CreateTooltipInformation(bool smartWrap, CancellationToken cancelToken) { return(manager.SearchPackageInfo(packageId, packageVersion, tfm, cancelToken).ContinueWith( t => PackageSearchHelpers.CreateTooltipInformation(t.Result), cancelToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default)); }