private async Task LoadAvailablePackagesAsync() { await TaskUtilities.SwitchToBackgroundThread(); var vmAvailablePackages = new List <IRPackageViewModel>(); var availablePackages = await _packageManager.GetAvailablePackagesAsync(); var installedPackages = _installedPackages.ToDictionary(p => p.Name, p => p); foreach (var package in availablePackages) { IRPackageViewModel installedPackage; if (installedPackages.TryGetValue(package.Package, out installedPackage)) { installedPackage.UpdateAvailablePackageDetails(package); vmAvailablePackages.Add(installedPackage); } else { vmAvailablePackages.Add(RPackageViewModel.CreateAvailable(package, this)); } } _availablePackages = vmAvailablePackages.OrderBy(p => p.Name).ToList(); }
private async Task LoadInstalledAndAvailablePackagesAsync() { await TaskUtilities.SwitchToBackgroundThread(); var availablePackages = await _packageManager.GetAvailablePackagesAsync(); var installedPackages = await _packageManager.GetInstalledPackagesAsync(); var vmAvailablePackages = availablePackages.Select(RPackageViewModel.CreateAvailable).ToDictionary(p => p.Name); var vmInstalledPackages = new List <IRPackageViewModel>(); foreach (var installedPackage in installedPackages) { RPackageViewModel vmPackage; if (vmAvailablePackages.TryGetValue(installedPackage.Package, out vmPackage)) { vmPackage.AddDetails(installedPackage, true); vmInstalledPackages.Add(vmPackage); } else { vmInstalledPackages.Add(RPackageViewModel.CreateInstalled(installedPackage)); } } _installedPackages = vmInstalledPackages.OrderBy(p => p.Name).ToList(); _availablePackages = vmAvailablePackages.Values.OrderBy(p => p.Name).ToList <IRPackageViewModel>(); }
private async Task LoadInstalledAndLoadedPackagesAsync(bool reload, CancellationToken cancellationToken) { await TaskUtilities.SwitchToBackgroundThread(); var markUninstalledAndUnloadedTask = MarkUninstalledAndUnloaded(cancellationToken); var getInstalledPackagesTask = _packageManager.GetInstalledPackagesAsync(cancellationToken); await Task.WhenAll(markUninstalledAndUnloadedTask, getInstalledPackagesTask); if (reload) { _installedPackages = new List <IRPackageViewModel>(); } var installedPackages = getInstalledPackagesTask.Result; if (!_availableLock.IsSet) { var vmInstalledPackages = installedPackages .Select(package => RPackageViewModel.CreateInstalled(package, this)) .OrderBy(p => p.Name) .ToList <IRPackageViewModel>(); IdentifyRemovablePackages(vmInstalledPackages); await UpdateLoadedPackages(vmInstalledPackages, null, cancellationToken); _installedPackages = vmInstalledPackages; EnsureAvailablePackagesLoadedAsync(false, cancellationToken).DoNotWait(); } else { var vmAvailablePackages = _availablePackages.ToDictionary(k => k.Name); var vmInstalledPackages = new List <IRPackageViewModel>(); foreach (var installedPackage in installedPackages) { IRPackageViewModel vmPackage; if (vmAvailablePackages.TryGetValue(installedPackage.Package, out vmPackage)) { vmPackage.AddDetails(installedPackage, true); vmInstalledPackages.Add(vmPackage); } else { vmInstalledPackages.Add(RPackageViewModel.CreateInstalled(installedPackage, this)); } } IdentifyRemovablePackages(vmInstalledPackages); vmInstalledPackages = vmInstalledPackages.OrderBy(p => p.Name).ToList(); await UpdateLoadedPackages(vmInstalledPackages, null, cancellationToken); _installedPackages = vmInstalledPackages; } }