public async Task HandleAsync(PackageChangedMessage message, CancellationToken cancellationToken) #endif { switch (message.ChangeType) { case PackageChangeType.Pinned: PackageSource.Refresh(); break; case PackageChangeType.Unpinned: if (message.Package.SourceType != chocolatey.infrastructure.app.domain.SourceType.normal) { PackageSource.Refresh(); } else { // Local file system var package = Packages.First(p => p.Id == message.Id); if (package.LatestVersion != null) { PackageSource.Refresh(); } else { var outOfDatePackages = await _chocolateyService.GetOutdatedPackages(package.IsPrerelease, package.Id, false); foreach (var update in outOfDatePackages) { await _eventAggregator.PublishOnUIThreadAsync(new PackageHasUpdateMessage(update.Id, update.Version)); } PackageSource.Refresh(); } } break; case PackageChangeType.Uninstalled: Packages.Remove(Packages.First(p => p.Id == message.Id)); break; default: await LoadPackages(); break; } }
public async Task Handle(PackageChangedMessage message) { switch (message.ChangeType) { case PackageChangeType.Pinned: PackageSource.Refresh(); break; case PackageChangeType.Unpinned: var package = Packages.First(p => p.Id == message.Id); if (package.LatestVersion != null) { PackageSource.Refresh(); } else { var outOfDatePackages = await _chocolateyService.GetOutdatedPackages(package.IsPrerelease, package.Id); foreach (var update in outOfDatePackages) { await _eventAggregator.PublishOnUIThreadAsync(new PackageHasUpdateMessage(update.Id, update.Version)); } PackageSource.Refresh(); } break; case PackageChangeType.Uninstalled: Packages.Remove(Packages.First(p => p.Id == message.Id)); break; default: await LoadPackages(); break; } }
public async Task LoadPackages(bool forceCheckForOutdatedPackages) { try { if (!CanLoadRemotePackages() && Packages.Any()) { return; } if (!HasLoaded && (_configService.GetEffectiveConfiguration().PreventPreload ?? false)) { ShowShouldPreventPreloadMessage = true; HasLoaded = true; return; } HasLoaded = false; ShowShouldPreventPreloadMessage = false; var sort = SortSelection == Resources.RemoteSourceViewModel_SortSelectionPopularity ? "DownloadCount" : "Title"; await _progressService.StartLoading(string.Format(Resources.RemoteSourceViewModel_LoadingPage, CurrentPage)); _progressService.WriteMessage(Resources.RemoteSourceViewModel_FetchingPackages); try { var result = await _chocolateyPackageService.Search( SearchQuery, new PackageSearchOptions( PageSize, CurrentPage - 1, sort, IncludePrerelease, IncludeAllVersions, MatchWord, Source.Value)); var installed = await _chocolateyPackageService.GetInstalledPackages(); var outdated = await _chocolateyPackageService.GetOutdatedPackages(false, null, forceCheckForOutdatedPackages); PageCount = (int)Math.Ceiling((double)result.TotalCount / (double)PageSize); Packages.Clear(); SourceType sourceType = SourceType.normal; Enum.TryParse <SourceType>(Source.Value, out sourceType); result.Packages.ToList().ForEach(p => { if (installed.Any(package => string.Equals(package.Id, p.Id, StringComparison.OrdinalIgnoreCase))) { p.IsInstalled = true; } if (outdated.Any(package => string.Equals(package.Id, p.Id, StringComparison.OrdinalIgnoreCase))) { p.IsLatestVersion = false; } var pnew = Mapper.Map <IPackageViewModel>(p); pnew.SourceType = sourceType; Packages.Add(pnew); }); if (_configService.GetEffectiveConfiguration().ExcludeInstalledPackages ?? false) { Packages.RemoveAll(x => x.IsInstalled); } if (PageCount < CurrentPage) { CurrentPage = PageCount == 0 ? 1 : PageCount; } } finally { await _progressService.StopLoading(); HasLoaded = true; } await _eventAggregator.PublishOnUIThreadAsync(new ResetScrollPositionMessage()); } catch (Exception ex) { Logger.Error(ex, "Failed to load new packages."); await _dialogService.ShowMessageAsync( Resources.RemoteSourceViewModel_FailedToLoad, string.Format(Resources.RemoteSourceViewModel_FailedToLoadRemotePackages, ex.Message)); throw; } }
public async Task LoadPackages() { try { if (!CanLoadRemotePackages() && Packages.Any()) { return; } _hasLoaded = false; var sort = SortSelection == Resources.RemoteSourceViewModel_SortSelectionPopularity ? "DownloadCount" : "Title"; await _progressService.StartLoading(string.Format(Resources.RemoteSourceViewModel_LoadingPage, CurrentPage)); _progressService.WriteMessage(Resources.RemoteSourceViewModel_FetchingPackages); try { var result = await _chocolateyPackageService.Search( SearchQuery, new PackageSearchOptions( PageSize, CurrentPage - 1, sort, IncludePrerelease, IncludeAllVersions, MatchWord, Source.Value)); var installed = await _chocolateyPackageService.GetInstalledPackages(); var outdated = await _chocolateyPackageService.GetOutdatedPackages(); PageCount = (int)(((double)result.TotalCount / (double)PageSize) + 0.5); Packages.Clear(); result.Packages.ToList().ForEach(p => { if (installed.Any(package => string.Equals(package.Id, p.Id, StringComparison.OrdinalIgnoreCase))) { p.IsInstalled = true; } if (outdated.Any(package => string.Equals(package.Item1, p.Id, StringComparison.OrdinalIgnoreCase))) { p.IsLatestVersion = false; } Packages.Add(Mapper.Map <IPackageViewModel>(p)); }); if (PageCount < CurrentPage) { CurrentPage = PageCount == 0 ? 1 : PageCount; } } finally { await _progressService.StopLoading(); _hasLoaded = true; } await _eventAggregator.PublishOnUIThreadAsync(new ResetScrollPositionMessage()); } catch (Exception ex) { Logger.Error(ex, "Failed to load new packages."); await _progressService.ShowMessageAsync( Resources.RemoteSourceViewModel_FailedToLoad, string.Format(Resources.RemoteSourceViewModel_FailedToLoadRemotePackages, ex.Message)); throw; } }