예제 #1
0
        private async Task <IEnumerable <JObject> > GetPackages(int skip, int page)
        {
            SourceRepository sourceRepository = SourceRepositoryHelper.CreateSourceRepository(SourceProvider, Source);

            string searchTerm = Arguments != null?Arguments.FirstOrDefault() : null;

            var packages = await sourceRepository.Search(searchTerm, new SearchFilter()
            {
                IncludePrerelease = Prerelease, SupportedFrameworks = new string[0]
            }, skip, page, CancellationToken.None);

            return(packages);
        }
        private async Task InstallPackage(
            IFileSystem installPathFileSystem,
            string packageId,
            NuGetVersion version)
        {
            if (version == null)
            {
                NoCache = true;
            }
            var packageManager = CreatePackageManager(installPathFileSystem, useSideBySidePaths: true);

            // BUGBUG: When adding support for 'AllowMultipleVersions', remember to add PackageInstallNeeded method

            JObject packageMetadata;

            if (version == null)
            {
                packageMetadata = await SourceRepositoryHelper.GetLatestVersionMetadata(SourceRepository, packageId, prerelease : Prerelease);

                version = NuGetVersion.Parse(packageMetadata["version"].ToString());
            }
            else
            {
                packageMetadata = await SourceRepository.GetPackageMetadata(packageId, version);
            }

            if (packageMetadata == null)
            {
                throw new InvalidOperationException(
                          String.Format(CultureInfo.CurrentCulture,
                                        NuGet.Resources.NuGetResources.UnknownPackageSpecificVersion, packageId, version));
            }

            var actionResolver = new ActionResolver(
                SourceRepository,
                SourceRepository,
                new ResolutionContext()
            {
                AllowPrerelease    = Prerelease,
                DependencyBehavior = DependencyBehavior,
            });

            var packageActions = await actionResolver.ResolveActionsAsync(new PackageIdentity(packageId, version),
                                                                          PackageActionType.Install,
                                                                          new FilesystemInstallationTarget(packageManager));

            if (Verbosity == NuGet.Verbosity.Detailed)
            {
                Console.WriteLine("Actions returned by resolver");
                foreach (var action in packageActions)
                {
                    Console.WriteLine(action.ActionType.ToString() + "-" + action.PackageIdentity.ToString());
                }
            }

            packageActions = packageActions.Where(a => a.ActionType == PackageActionType.Download || a.ActionType == PackageActionType.Purge);

            if (Verbosity == NuGet.Verbosity.Detailed)
            {
                Console.WriteLine("After reducing actions to just Download and Purge");
                foreach (var action in packageActions)
                {
                    Console.WriteLine(action.ActionType.ToString() + "-" + action.PackageIdentity.ToString());
                }
            }

            var actionExecutor = new ActionExecutor();

            actionExecutor.ExecuteActions(packageActions, Console);
        }
예제 #3
0
 protected void InitializeSourceRepository()
 {
     SourceRepository = SourceRepositoryHelper.CreateSourceRepository(SourceProvider, Source);
 }
예제 #4
0
        private bool RestorePackage(
            IFileSystem packagesFolderFileSystem,
            PackageIdentity packageIdentity,
            bool packageRestoreConsent,
            ConcurrentQueue <JObject> satellitePackages)
        {
            // BUGBUG: Looks like we are creating PackageManager for every single restore. This is likely done to support execution in parallel
            var packageManager = CreatePackageManager(packagesFolderFileSystem, useSideBySidePaths: true);

            if (IsPackageInstalled(packageManager.LocalRepository, packagesFolderFileSystem, packageIdentity))
            {
                return(false);
            }

            // BUGBUG: Investigate if the following lock is needed
            EnsurePackageRestoreConsent(packageRestoreConsent);
            if (RequireConsent && _outputOptOutMessage)
            {
                lock (_outputOptOutMessageLock)
                {
                    if (_outputOptOutMessage)
                    {
                        string message = String.Format(
                            CultureInfo.CurrentCulture,
                            LocalizedResourceManager.GetString("RestoreCommandPackageRestoreOptOutMessage"),
                            NuGet.Resources.NuGetResources.PackageRestoreConsentCheckBoxText.Replace("&", ""));
                        Console.WriteLine(message);
                        _outputOptOutMessage = false;
                    }
                }
            }

            SourceRepository = SourceRepositoryHelper.CreateSourceRepository(SourceProvider, Source);

            // BUGBUG: TO BE REMOVED AFTER INVESTIGATION
            using (packageManager.SourceRepository.StartOperation(
                       RepositoryOperationNames.Restore,
                       packageIdentity.Id,
                       packageIdentity.Version == null ? null : packageIdentity.Version.ToString()))
            {
                // BUGBUG: Satellite packages should only be restored at the end. Find out Why first??
                //         And, then, handle it here


                var filesystemInstallationTarget = new FilesystemInstallationTarget(packageManager);

                // BUGBUG: Should consider using async method and await
                var task = SourceRepository.GetPackageMetadata(packageIdentity.Id, packageIdentity.Version);
                task.Wait();
                var packageJSON = task.Result;

                if (IsSatellitePackage(packageJSON))
                {
                    // Satellite packages would necessarily have to be installed later than the corresponding package.
                    // We'll collect them in a list to keep track and then install them later.
                    satellitePackages.Enqueue(packageJSON);
                    return(true);
                }

                var packageAction = new NewPackageAction(NuGet.Client.PackageActionType.Download,
                                                         packageIdentity, packageJSON, filesystemInstallationTarget, SourceRepository, null);

                // BUGBUG: See PackageExtractor.cs for locking mechanism used to handle concurrency
                NuGet.Client.Installation.ActionExecutor actionExecutor = new Client.Installation.ActionExecutor();

                // BUGBUG: This is likely inefficient. Consider collecting all actions first and executing them in 1 shot
                var packageActions = new List <NewPackageAction>()
                {
                    packageAction
                };
                actionExecutor.ExecuteActions(packageActions, Console);
                return(true);
            }
        }