private async Task LoadPackages() { if (IsLoading) { return; } IsLoading = true; IsShowOnlyPackagesWithUpdateEnabled = false; _packages.Clear(); Packages.Clear(); var packages = (await _chocolateyService.GetInstalledPackages()) .Select(Mapper.Map <IPackageViewModel>).ToList(); foreach (var packageViewModel in packages) { _packages.Add(packageViewModel); Packages.Add(packageViewModel); } FirstLoadIncomplete = false; await CheckOutdated(false); }
private async Task LoadPackages() { try { _packages.Clear(); Packages.Clear(); var packages = await _chocolateyService.GetInstalledPackages(); foreach (var packageViewModel in packages) { _packages.Add(packageViewModel); Packages.Add(packageViewModel); if (packageViewModel.LatestVersion == null) { packageViewModel.RetriveLatestVersion(); } } } catch (Exception ex) { _logService.Fatal("Packages failed to load", ex); throw; } }
private async Task LoadPackages() { if (IsLoading) { return; } IsLoading = true; IsShowOnlyPackagesWithUpdateEnabled = false; try { _packages.Clear(); Packages.Clear(); var packages = (await _chocolateyService.GetInstalledPackages()) .Select(Mapper.Map <IPackageViewModel>).ToList(); foreach (var packageViewModel in packages) { _packages.Add(packageViewModel); Packages.Add(packageViewModel); } FirstLoadIncomplete = false; var updates = await _chocolateyService.GetOutdatedPackages(); foreach (var update in updates) { await _eventAggregator.PublishOnUIThreadAsync(new PackageHasUpdateMessage(update.Id, update.Version)); } PackageSource.Refresh(); } catch (ConnectionClosedException) { Logger.Warning("Threw connection closed message while processing load packages."); } catch (Exception ex) { Logger.Fatal("Packages failed to load", ex); throw; } finally { IsLoading = false; IsShowOnlyPackagesWithUpdateEnabled = true; } }
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; } }