Exemplo n.º 1
0
        private bool InstallSatellitePackages(IFileSystem packagesFolderFileSystem, ConcurrentQueue <JObject> satellitePackages)
        {
            if (satellitePackages.Count == 0)
            {
                return(false);
            }

            var packageManager = CreatePackageManager(packagesFolderFileSystem, useSideBySidePaths: true);
            var filesystemInstallationTarget = new FilesystemInstallationTarget(packageManager);
            var packageActions = satellitePackages.Select(packageJSON => new NewPackageAction(NuGet.Client.PackageActionType.Download,
                                                                                              new PackageIdentity(packageJSON[Properties.PackageId].ToString(), new NuGetVersion(packageJSON[Properties.Version].ToString())), packageJSON, filesystemInstallationTarget, SourceRepository, null));

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

            return(true);
        }
Exemplo n.º 2
0
        private bool InstallSatellitePackages(IFileSystem packagesFolderFileSystem, ConcurrentQueue<JObject> satellitePackages)
        {
            if (satellitePackages.Count == 0)
            {
                return false;
            }

            var packageManager = CreatePackageManager(packagesFolderFileSystem, useSideBySidePaths: true);
            var filesystemInstallationTarget = new FilesystemInstallationTarget(packageManager);
            var packageActions = satellitePackages.Select(packageJSON => new NewPackageAction(NuGet.Client.PackageActionType.Download,
                    new PackageIdentity(packageJSON[Properties.PackageId].ToString(), new NuGetVersion (packageJSON[Properties.Version].ToString())), packageJSON, filesystemInstallationTarget, SourceRepository, null));

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

            return true;
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 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);
            }
        }