CreateInstalled() public static method

public static CreateInstalled ( RPackage package, IRPackageManagerViewModel owner ) : RPackageViewModel
package Microsoft.R.Components.PackageManager.Model.RPackage
owner IRPackageManagerViewModel
return RPackageViewModel
Beispiel #1
0
        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>();
        }
Beispiel #2
0
        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;
            }
        }