예제 #1
0
        /// <summary>
        /// Install a NuGet package and make it available for use in the <see cref="EvaluationService"/>.
        /// </summary>
        public async Task InstallAsync(
            InteractivePackageDescription packageDescription,
            CancellationToken cancellationToken = default)
        {
            if (packageDescription.PackageId == null)
            {
                throw new ArgumentException(
                          $"{nameof (packageDescription.PackageId)} property cannot be null",
                          nameof(packageDescription));
            }

            var package = packageDescription.ToInteractivePackage();

            var installedPackages = await packageManager.InstallPackageAsync(
                package,
                packageDescription.GetSourceRepository(),
                cancellationToken);

            // TODO: Should probably alert user that the package is already installed.
            //       Should we add a fresh #r for the package in case that's what they're trying to get?
            //       A feel good thing?
            if (installedPackages.Count == 0)
            {
                return;
            }

            var agent = await getAgentConnectionHandler(false, cancellationToken);

            foreach (var installedPackage in installedPackages)
            {
                ReferencePackageInWorkspace(installedPackage);
                await LoadPackageIntegrationsAsync(agent, installedPackage, cancellationToken);
            }

            // TODO: Figure out metapackages. Install Microsoft.AspNet.SignalR, for example,
            //       and no #r submission gets generated, so all the workspace reference stuff
            //       above fails to bring in references to dependnet assemblies automatically.
            //       User must type them out themselves.
            //
            //       This was busted in our NuGet 2.x code as well.
            package = installedPackages.FirstOrDefault(
                p => PackageIdComparer.Equals(p, package));

            // TODO: Same issue as installedPackages.Count == 0. What do we want to tell user?
            //       probably they tried to install a package they already had installed, and
            //       maybe it bumped a shared dep (which is why installedPackages is non-empty).
            if (package == null)
            {
                return;
            }

            if (await ReferenceTopLevelPackageAsync(package, cancellationToken))
            {
                evaluationService.OutdateAllCodeCells();
                await evaluationService.EvaluateAllAsync(cancellationToken);
            }
        }
예제 #2
0
        public async Task AddPackageAsync(
            PackageViewModel packageViewModel,
            CancellationToken cancellationToken)
        {
            if (packageViewModel == null)
            {
                throw new ArgumentNullException(nameof(packageViewModel));
            }

            await clientSession.PackageManager.InstallAsync(
                InteractivePackageDescription.FromPackageViewModel(packageViewModel),
                cancellationToken);
        }
예제 #3
0
 public int GetHashCode(InteractivePackageDescription obj)
 => obj?.PackageId == null ? 0 : obj.PackageId.GetHashCode();
예제 #4
0
 public bool Equals(InteractivePackageDescription x, InteractivePackageDescription y)
 => Equals(x?.PackageId, y?.PackageId);