Exemple #1
0
        public async Task ChangeSelectedPackageRowAsync(PackageRowPresentationModel selected)
        {
            _selectedPackage = selected;
            _loadDetailsCancellationTokenSource?.Cancel();
            _loadDetailsCancellationTokenSource = new CancellationTokenSource();

            var identity = new PackageIdentity(selected.Id, PackageVersion.Parse(selected.Version));

            var    installed     = _localPackagesService.IsPackageInstalled(selected.Id);
            var    installIcon   = RequireInstallOrRemoveIcon(installed);
            Action installAction = RequireInstallOrRemoveAction(installed);

            var assemblies = (await _assembliesService.RequireAllAssembliesAsync())
                             .Select(assembly =>
            {
                var icon = ImageHelper.LoadImageFromResource(Paths.AssemblyDefinitionAssetIconResourceName);
                var installedInAssembly = _assembliesService.IsPackageInstalledInAssembly(selected.Id, assembly.Name);
                var version             = installedInAssembly
            ? _assembliesService.RequireInstalledPackageVersion(selected.Id, assembly.Name)
            : null;
                var buttonIcon = RequireInstallOrRemoveIcon(installedInAssembly);
                // ReSharper disable once ConvertToLocalFunction
                Action buttonAction = RequireInstallOrRemoveAction(installedInAssembly, new[] { assembly.Name });
                return(new AssemblyPackageDetailsPresentationModel(icon, assembly.Name, version, buttonIcon, buttonAction));
            });

            var selectedDetails = new PackageDetailsPresentationModel(selected.Id, selected.IsInstalled, selected.Icon, selected.Version,
                                                                      new[] { selected.Version }, selected.Sources.FirstOrDefault() ?? string.Empty, selected.Sources, null,
                                                                      null, installIcon, installAction, null, assemblies);

            _mainWindow.SelectedPackage = selectedDetails;

            if (!string.IsNullOrWhiteSpace(selectedDetails.SelectedSource))
            {
                // delayed adding versions
                await SetVersionsAsync(selectedDetails, selected, _loadDetailsCancellationTokenSource.Token);

                PackageInfoSourceWrapper?detailInfo;

                try
                {
                    detailInfo = await _remotePackagesService.GetPackageInfoAsync(identity, selectedDetails.SelectedSource,
                                                                                  _loadDetailsCancellationTokenSource.Token);
                }
                catch (TaskCanceledException)
                {
                    return;
                }

                if (!detailInfo.HasValue)
                {
                    LogHelper.LogWarning($"Package {identity.Id} with version {identity.Version} not found in online sources");
                    return;
                }

                // delayed adding dependencies and description
                SetDependencies(selectedDetails, detailInfo.Value);
            }
        }
Exemple #2
0
        private async Task SetVersionsAsync(PackageDetailsPresentationModel details, PackageRowPresentationModel selectedModel, CancellationToken cancellationToken)
        {
            var versions =
                await _remotePackagesService.FindPackageVersionsAsync(selectedModel.Id, selectedModel.Sources.First(), cancellationToken);

            details.Versions            = versions.Select(v => v.PackageVersion.ToString());
            _mainWindow.SelectedPackage = details;
        }
Exemple #3
0
        private void SetDependencies(PackageDetailsPresentationModel details, PackageInfoSourceWrapper detailInfo)
        {
            details.Dependencies = detailInfo.PackageInfo.Dependencies?
                                   .Select(d => new DependenciesPresentationModel(d.TargetFramework.TFM, d.Dependencies
                                                                                  .Select(dd => new DependencyPresentationModel(dd.Id, dd.Version.ToString()))));
            details.Description = detailInfo.PackageInfo.Description;

            _mainWindow.SelectedPackage = details;
        }