public void ExecuteOperation(NuGet.PackageOperation operation)
 {
     if (ExecuteOperationCallback != null)
     {
         ExecuteOperationCallback(operation);
     }
 }
Exemplo n.º 2
0
 protected override void OnAfterPackageWalk(IPackage package)
 {
     if (this.Repository.Exists(package))
     {
         this._operations.RemoveOperation(package, PackageAction.Uninstall);
         this._packagesToKeep.Add(package);
     }
     else
     {
         PackageOperation operation = new PackageOperation(package, PackageAction.Install);
         if (GetPackageTarget(package) == PackageTargets.External)
         {
             operation.Target = PackageOperationTarget.PackagesFolder;
         }
         this._operations.AddOperation(operation);
     }
     if (this._packagesByDependencyOrder != null)
     {
         IList <IPackage> list;
         if (!this._packagesByDependencyOrder.TryGetValue(package.Id, out list))
         {
             this._packagesByDependencyOrder[package.Id] = list = new List <IPackage>();
         }
         list.Add(package);
     }
 }
		public PackageOperation AddOneFakeUninstallPackageOperation()
		{
			var package = new FakePackage("PackageToUninstall");			
			var operation = new PackageOperation(package, PackageAction.Uninstall);
			FakeSolution.FakeActiveProject.FakeInstallOperations.Add(operation);
			return operation;
		}
Exemplo n.º 4
0
		public FakePackage AddPackageInstallOperation ()
		{
			var package = new FakePackage ("Package to install");
			var operation = new PackageOperation (package, PackageAction.Install);
			PackageOperations.Add (operation);
			return package;
		}
Exemplo n.º 5
0
            internal void AddOperation(PackageOperation operation)
            {
                _operations.Add(operation);
                Dictionary <IPackage, PackageOperation> dictionary = GetPackageLookup(operation.Action, createIfNotExists: true);

                dictionary.Add(operation.Package, operation);
            }
        protected override void OnAfterPackageWalk(IPackage package)
        {
            if (!Repository.Exists(package))
            {
                // Don't add the package for installation if it already exists in the repository
                var operation     = new PackageOperation(package, PackageAction.Install);
                var packageTarget = GetPackageTarget(package);
                if (packageTarget == PackageTargets.External)
                {
                    operation.Target = PackageOperationTarget.PackagesFolder;
                }
                ;
                _operations.AddOperation(operation);
            }
            else
            {
                // If we already added an entry for removing this package then remove it
                // (it's equivalent for doing +P since we're removing a -P from the list)
                _operations.RemoveOperation(package, PackageAction.Uninstall);

                // and mark the package as being "retained".
                _packagesToKeep.Add(package);
            }

            if (_packagesByDependencyOrder != null)
            {
                IList <IPackage> packages;
                if (!_packagesByDependencyOrder.TryGetValue(package.Id, out packages))
                {
                    _packagesByDependencyOrder[package.Id] = packages = new List <IPackage>();
                }

                packages.Add(package);
            }
        }
		FakeInstallPackageAction CreateInstallActionWithOneOperation()
		{
			var operations = new PackageOperation[] {
				new PackageOperation(new FakePackage(), PackageAction.Install)
			};
			FakeInstallPackageAction action = CreateInstallAction();
			action.Operations = operations;
			return action;
		}
Exemplo n.º 8
0
            internal void AddOperation(PackageOperation operation)
            {
                Dictionary <IPackage, PackageOperation> dictionary = GetPackageLookup(operation.Action, createIfNotExists: true);

                if (!dictionary.ContainsKey(operation.Package))
                {
                    dictionary.Add(operation.Package, operation);
                    _operations.Add(operation);
                }
            }
		void AddInstallOperationWithFile(string fileName)
		{
			var package = new FakePackage();
			package.AddFile(fileName);
			
			var operation = new PackageOperation(package, PackageAction.Install);
			var operations = new List<PackageOperation>();
			operations.Add(operation);
			
			action.Operations = operations;
		}
		public PackageOperation AddOneFakeInstallPackageOperationForViewModelPackage()
		{
			var operation = new PackageOperation(FakePackage, PackageAction.Install);
			
			FakeSolution
				.FakeActiveProject
				.FakeInstallOperations
				.Add(operation);
			
			return operation;
		}
Exemplo n.º 11
0
        protected void Execute(PackageOperation operation)
        {
            bool packageExists = LocalRepository.Exists(operation.Package);

            if (operation.Action == PackageAction.Install)
            {
                // If the package is already installed, then skip it
                if (packageExists)
                {
                    Logger.Log(MessageLevel.Verbose, NuGetResources.Log_ProjectAlreadyReferencesPackage, Project.ProjectName, operation.Package.GetFullName());
                }
                else
                {
                    if (WhatIf)
                    {
                        Logger.Log(
                            MessageLevel.Info,
                            NuGetResources.Log_InstallPackageIntoProject,
                            operation.Package,
                            Project.ProjectName);

                        PackageOperationEventArgs args = CreateOperation(operation.Package);
                        OnPackageReferenceAdding(args);
                    }
                    else
                    {
                        AddPackageReferenceToProject(operation.Package);
                    }
                }
            }
            else
            {
                if (packageExists)
                {
                    if (WhatIf)
                    {
                        Logger.Log(
                            MessageLevel.Info,
                            NuGetResources.Log_UninstallPackageFromProject,
                            operation.Package,
                            Project.ProjectName);

                        PackageOperationEventArgs args = CreateOperation(operation.Package);
                        OnPackageReferenceRemoved(args);
                    }
                    else
                    {
                        RemovePackageReferenceFromProject(operation.Package);
                    }
                }
            }
        }
Exemplo n.º 12
0
		void CreateInstallActionWithOnePowerShellScript()
		{
			CreateInstallActionWithNoPowerShellScripts();
			
			var package = new FakePackage();
			package.AddFile(@"tools\init.ps1");
			
			var operation = new PackageOperation(package, PackageAction.Install);
			var operations = new List<PackageOperation>();
			operations.Add(operation);
			
			fakeAction.Operations = operations;
			fakeActions.Add(fakeAction);
		}
Exemplo n.º 13
0
        public void Execute(PackageOperation operation)
        {
            bool flag = this.LocalRepository.Exists(operation.Package);

            if (operation.Action != PackageAction.Install)
            {
                if (flag)
                {
                    this.ExecuteUninstall(operation.Package);
                }
            }
            else if (!flag)
            {
                this.ExecuteInstall(operation.Package);
            }
            else
            {
                object[] args = new object[] { operation.Package.GetFullName() };
                this.Logger.Log(MessageLevel.Info, NuGetResources.Log_PackageAlreadyInstalled, args);
            }
        }
Exemplo n.º 14
0
        public virtual void Execute(PackageOperation operation)
        {
            bool flag = this.LocalRepository.Exists(operation.Package);

            if (operation.Action != PackageAction.Install)
            {
                if (flag)
                {
                    this.RemovePackageReferenceFromProject(operation.Package);
                }
            }
            else if (!flag)
            {
                this.AddPackageReferenceToProject(operation.Package);
            }
            else
            {
                object[] args = new object[] { this.Project.ProjectName, operation.Package.GetFullName() };
                this.Logger.Log(MessageLevel.Info, NuGetResources.Log_ProjectAlreadyReferencesPackage, args);
            }
        }
Exemplo n.º 15
0
        protected void Execute(PackageOperation operation)
        {
            bool packageExists = LocalRepository.Exists(operation.Package);

            if (operation.Action == PackageAction.Install)
            {
                // If the package is already installed, then skip it
                if (packageExists)
                {
                    Logger.Log(MessageLevel.Verbose, NuGetResources.Log_PackageAlreadyInstalled, operation.Package.GetFullName());
                }
                else
                {
                    if (WhatIf)
                    {
                        Logger.Log(MessageLevel.Info, NuGetResources.Log_InstallPackage, operation.Package);
                    }
                    else
                    {
                        ExecuteInstall(operation.Package);
                    }
                }
            }
            else
            {
                if (packageExists)
                {
                    if (WhatIf)
                    {
                        Logger.Log(MessageLevel.Info, NuGetResources.Log_UninstallPackage, operation.Package);
                    }
                    else
                    {
                        ExecuteUninstall(operation.Package);
                    }
                }
            }
        }
Exemplo n.º 16
0
        protected void Execute(PackageOperation operation)
        {
            bool packageExists = LocalRepository.Exists(operation.Package);

            if (operation.Action == PackageAction.Install)
            {
                // If the package is already installed, then skip it
                if (packageExists)
                {
                    Logger.Log(MessageLevel.Info, NuGetResources.Log_ProjectAlreadyReferencesPackage, Project.ProjectName, operation.Package.GetFullName());
                }
                else
                {
                    if (WhatIf)
                    {
                        Logger.Log(MessageLevel.Info, NuGetResources.Log_PackageOperation, operation.Action, operation.Package);
                    }
                    else
                    {
                        AddPackageReferenceToProject(operation.Package);
                    }
                }
            }
            else
            {
                if (packageExists)
                {
                    if (WhatIf)
                    {
                        Logger.Log(MessageLevel.Info, NuGetResources.Log_PackageOperation, operation.Action, operation.Package);
                    }
                    else
                    {
                        RemovePackageReferenceFromProject(operation.Package);
                    }
                }
            }
        }
		FakePackage InstallPackageWithPackageOperations(PackageOperation operation)
		{
			var operations = new PackageOperation[] {
				operation
			};
			FakePackage package = CreateFakePackage();
			var installAction = new FakeInstallPackageAction();
			installAction.Operations = operations;
			packageManager.InstallPackage(package, installAction);
			return package;
		}
		FakePackage UpdatePackageWithPackageOperations(PackageOperation operation)
		{
			var operations = new PackageOperation[] {
				operation
			};
			FakePackage package = CreateFakePackage();
			var updateAction = new FakeUpdatePackageAction();
			updateAction.Operations = operations;
			updateAction.UpdateDependencies = true;
			packageManager.UpdatePackage(package, updateAction);
			return package;
		}
 public IndexedPackageOperation(int index, PackageOperation operation)
 {
     Index = index;
     Operation = operation;
 }
		public void HasPackageScriptsToRun_ProjectHasOnePackageOperation_PackageLocated()
		{
			CreateAction();
			FakePackage expectedPackage = fakeProject.FakeSourceRepository.AddFakePackageWithVersion("Test", "1.0");
			var operation = new PackageOperation(expectedPackage, PackageAction.Install);
			action.PackageId = expectedPackage.Id;
			action.PackageVersion = expectedPackage.Version;
			fakeProject.FakeInstallOperations.Add(operation);
			
			bool hasPackageScripts = action.HasPackageScriptsToRun();
			
			IPackage actualPackage = action.Package;
			
			Assert.AreEqual(expectedPackage, actualPackage);
		}
Exemplo n.º 21
0
 private static object GetOpposingOperationKey(PackageOperation operation)
 {
     return(Tuple.Create(operation.Action == PackageAction.Install ?
                         PackageAction.Uninstall :
                         PackageAction.Install, operation.Package.Id, operation.Package.Version));
 }
 void AssertReducedOperationsContains(PackageOperation operation)
 {
     Assert.Contains(operation, reducedPackageOperations.Operations.ToList());
 }
Exemplo n.º 23
0
        public override bool Equals(object obj)
        {
            PackageOperation operation = obj as PackageOperation;

            return((operation != null) && ((operation.Action == this.Action) && (operation.Package.Id.Equals(this.Package.Id, StringComparison.OrdinalIgnoreCase) && operation.Package.Version.Equals(this.Package.Version))));
        }
Exemplo n.º 24
0
 public void ExecuteOperation(PackageOperation operation)
 {
     EnsurePackageManagerInstance();
     _packageManager.ExecuteOperation(operation);
 }
Exemplo n.º 25
0
        protected override void OnAfterPackageWalk(IPackage package)
        {   
            if (!Repository.Exists(package))
            {
                // Don't add the package for installation if it already exists in the repository
                var operation = new PackageOperation(package, PackageAction.Install);
                var packageTarget = GetPackageTarget(package);
                if (packageTarget == PackageTargets.External)
                {
                    operation.Target = PackageOperationTarget.PackagesFolder;
                };
                _operations.AddOperation(operation);
            }
            else
            {
                // If we already added an entry for removing this package then remove it 
                // (it's equivalent for doing +P since we're removing a -P from the list)
                _operations.RemoveOperation(package, PackageAction.Uninstall);

                // and mark the package as being "retained".
                _packagesToKeep.Add(package);
            }

            if (_packagesByDependencyOrder != null)
            {
                IList<IPackage> packages;
                if (!_packagesByDependencyOrder.TryGetValue(package.Id, out packages))
                {
                    _packagesByDependencyOrder[package.Id] = packages = new List<IPackage>();
                }

                packages.Add(package);
            }
        }
Exemplo n.º 26
0
 private static object GetOperationKey(PackageOperation operation)
 {
     return(Tuple.Create(operation.Action, operation.Package.Id, operation.Package.Version));
 }
Exemplo n.º 27
0
		bool IsMatch(PackageOperation x, PackageOperation y)
		{
			return (x.Package.Id == y.Package.Id) &&
				(x.Package.Version == y.Package.Version) &&
				(x.Action == y.Action);
		}
Exemplo n.º 28
0
		bool InstallOperationExists(IPackage package)
		{
			var installOperation = new PackageOperation(package, PackageAction.Install);
			return operations.Any(operation => IsMatch(installOperation, operation));
		}
		public void RunPackageOperations_TwoPackageOperations_BothPackagesInOperationsAddedToSharedRepository()
		{
			CreatePackageManager();
			CreateTestableProjectManager();
			PackageOperation operation1 = CreateOneInstallPackageOperation("First", "1.0");
			PackageOperation operation2 = CreateOneInstallPackageOperation("Second", "1.0");
			var operations = new PackageOperation[] { operation1, operation2 };
			var expectedPackages = new FakePackage[] {
				operation1.Package as FakePackage,
				operation2.Package as FakePackage
			};
			
			packageManager.RunPackageOperations(operations);
			
			PackageCollectionAssert.AreEqual(expectedPackages, fakeSolutionSharedRepository.PackagesAdded);
		}
		FakePackage InstallPackageWithPackageOperations(PackageOperation operation)
		{
			var operations = new PackageOperation[] {
				operation
			};
			FakePackage package = CreateFakePackage();
			packageManager.InstallPackage(package, operations, false);
			return package;
		}
Exemplo n.º 31
0
 private static object GetOpposingOperationKey(PackageOperation operation) =>
 Tuple.Create <PackageAction, string, SemanticVersion>((operation.Action == PackageAction.Install) ? PackageAction.Uninstall : PackageAction.Install, operation.Package.Id, operation.Package.Version);
		FakePackage UpdatePackageWithPackageOperations(PackageOperation operation)
		{
			var operations = new PackageOperation[] {
				operation
			};
			FakePackage package = CreateFakePackage();
			packageManager.UpdatePackage(package, operations, true);
			return package;
		}
 private static object GetOperationKey(PackageOperation operation)
 {
     return Tuple.Create(operation.Action, operation.Package.Id, operation.Package.Version);
 }
Exemplo n.º 34
0
 public void ExecuteOperation(PackageOperation operation)
 {
     // Allow to call this method from outside of the class
     base.Execute(operation);
 }
Exemplo n.º 35
0
		public void AddPackage_PackageAddedSuccessfully_PackageOperationsUsedWhenInstallingPackage ()
		{
			CreateViewModel ();
			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage ();
			viewModel.AddPackage ();

			PackageOperation[] expectedOperations = new PackageOperation[] {
				new PackageOperation (fakePackage, PackageAction.Install)
			};

			FakeInstallPackageAction action = fakeSolution.FakeProjectToReturnFromGetProject.LastInstallPackageCreated;
			CollectionAssert.AreEqual (expectedOperations, action.Operations);
		}
 PackageOperation AddInstallOperationForPackage(IPackage package)
 {
     var operation = new PackageOperation(package, PackageAction.Install);
     AddInstallOperationsForPackage(package, operation);
     return operation;
 }
		public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_PackageOperationsReturnedFromPackageOperationsResolverCreated ()
		{
			CreatePackageManager ();
			var package = new FakePackage ();
			var expectedOperations = new PackageOperation [] {
				new PackageOperation (package, PackageAction.Install)
			};
			fakePackageOperationResolver.AddOperations (package, expectedOperations);

			IEnumerable<PackageOperation> operations = GetInstallPackageOperations (package);

			Assert.AreEqual (expectedOperations, operations);
		}
		bool IsInstallingMSBuildFiles (PackageOperation operation)
		{
			return (operation.Action == PackageAction.Install) &&
				operation.Package.GetBuildFiles ().Any ();
		}
 private static object GetOpposingOperationKey(PackageOperation operation)
 {
     return Tuple.Create(operation.Action == PackageAction.Install ?
                         PackageAction.Uninstall :
                         PackageAction.Install, operation.Package.Id, operation.Package.Version);
 }
Exemplo n.º 40
0
        public void Execute(PackageOperation operation)
        {
            bool packageExists = LocalRepository.Exists(operation.Package);

            if (operation.Action == PackageAction.Install)
            {
                // If the package is already installed, then skip it
                if (packageExists)
                {
                    Logger.Log(MessageLevel.Info, NuGetResources.Log_PackageAlreadyInstalled, operation.Package.GetFullName());
                }
                else
                {
                    ExecuteInstall(operation.Package);
                }
            }
            else
            {
                if (packageExists)
                {
                    ExecuteUninstall(operation.Package);
                }
            }
        }
		public void HasPackageScriptsToRun_ProjectHasOnePackageOperation_DoesNotThrowNullReferenceException()
		{
			CreateAction();
			FakePackage package = fakeProject.FakeSourceRepository.AddFakePackageWithVersion("Test", "1.0");
			var operation = new PackageOperation(package, PackageAction.Install);
			action.PackageId = package.Id;
			action.PackageVersion = package.Version;
			fakeProject.FakeInstallOperations.Add(operation);
			
			bool hasPackageScripts = false;
			Assert.DoesNotThrow(() => hasPackageScripts = action.HasPackageScriptsToRun());
		}
Exemplo n.º 42
0
 private static object GetOperationKey(PackageOperation operation) =>
 Tuple.Create <PackageAction, string, SemanticVersion>(operation.Action, operation.Package.Id, operation.Package.Version);
Exemplo n.º 43
0
 public IndexedPackageOperation(int index, PackageOperation operation)
 {
     Index     = index;
     Operation = operation;
 }
        public void Execute_OneProjectThatHasOlderVersionOfPackageBeingUpdated_PackageOperationsAreRun()
        {
            PackageOperation operation = CreateInstallOperationWithFile(@"tools\readme.txt");
            CreateActionWithOperations(operation);
            IPackageFromRepository package = AddPackageToAction("Test", "1.0");
            IPackageManagementProject project = AddProjectToSolution();
            var expectedOperations = new PackageOperation[] { operation };

            action.Execute();

            project.AssertWasCalled(p => p.RunPackageOperations(expectedOperations));
        }
Exemplo n.º 45
0
		public void AddPackage_PackageAddedSuccessfully_PackageOperationsUsedWhenInstallingPackage()
		{
			CreateViewModel();
			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
			viewModel.AddPackage();
		
			PackageOperation[] expectedOperations = new PackageOperation[] {
				new PackageOperation(fakePackage, PackageAction.Install)
			};
			
			CollectionAssert.AreEqual(expectedOperations, fakeInstallPackageAction.Operations);
		}
Exemplo n.º 46
0
 internal void AddOperation(PackageOperation operation)
 {
     Dictionary<IPackage, PackageOperation> dictionary = GetPackageLookup(operation.Action, createIfNotExists: true);
     if (!dictionary.ContainsKey(operation.Package))
     {
         dictionary.Add(operation.Package, operation);
         _operations.Add(operation);
     }
 }
Exemplo n.º 47
0
 private static Tuple <PackageAction, string, Version> GetOperationKey(PackageOperation operation)
 {
     return(Tuple.Create(operation.Action, operation.Package.Id, operation.Package.Version));
 }