Пример #1
0
 private void UpdateVirtualRepos(IList <PackageAction> actions)
 {
     foreach (PackageAction action in actions)
     {
         PackageProjectAction action2 = action as PackageProjectAction;
         if (action2 != null)
         {
             VirtualRepository repository2 = this._virtualProjectRepos[action2.ProjectManager];
             if (action2.ActionType == PackageActionType.Install)
             {
                 repository2.AddPackage(action.Package);
                 continue;
             }
             repository2.RemovePackage(action.Package);
             continue;
         }
         PackageSolutionAction action3    = (PackageSolutionAction)action;
         VirtualRepository     repository = this._virtualPackageRepos[action3.PackageManager];
         if (action3.ActionType == PackageActionType.AddToPackagesFolder)
         {
             repository.AddPackage(action3.Package);
             continue;
         }
         if (action3.ActionType == PackageActionType.DeleteFromPackagesFolder)
         {
             repository.RemovePackage(action3.Package);
         }
     }
 }
Пример #2
0
 private void Rollback(List <PackageAction> executedOperations)
 {
     if (executedOperations.Count > 0)
     {
         this.Logger.Log(MessageLevel.Warning, "Rolling back", new object[0]);
     }
     executedOperations.Reverse();
     using (List <PackageAction> .Enumerator enumerator = executedOperations.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             PackageAction        action  = CreateReverseAction(enumerator.Current);
             PackageProjectAction action2 = action as PackageProjectAction;
             if (action2 != null)
             {
                 action2.ProjectManager.Logger = NullLogger.Instance;
                 action2.ProjectManager.Execute(new PackageOperation(action2.Package, (action2.ActionType == PackageActionType.Install) ? PackageAction.Install : PackageAction.Uninstall));
                 continue;
             }
             PackageSolutionAction action3 = (PackageSolutionAction)action;
             action3.PackageManager.Logger = NullLogger.Instance;
             if (action3.ActionType == PackageActionType.AddToPackagesFolder)
             {
                 action3.PackageManager.Execute(new PackageOperation(action3.Package, PackageAction.Install));
                 continue;
             }
             if (action3.ActionType == PackageActionType.DeleteFromPackagesFolder)
             {
                 action3.PackageManager.Execute(new PackageOperation(action3.Package, PackageAction.Uninstall));
             }
         }
     }
 }
Пример #3
0
 private void UpdateVirtualRepos(IList <PackageAction> actions)
 {
     foreach (var action in actions)
     {
         PackageProjectAction projectAction = action as PackageProjectAction;
         if (projectAction == null)
         {
             // update the virtual packages folder repo
             PackageSolutionAction solutionAction = (PackageSolutionAction)action;
             var packageRepo = _virtualPackageRepos[solutionAction.PackageManager];
             if (solutionAction.ActionType == PackageActionType.AddToPackagesFolder)
             {
                 packageRepo.AddPackage(solutionAction.Package);
             }
             else if (solutionAction.ActionType == PackageActionType.DeleteFromPackagesFolder)
             {
                 packageRepo.RemovePackage(solutionAction.Package);
             }
         }
         else
         {
             // update the virtual project repo
             var projectRepo = _virtualProjectRepos[projectAction.ProjectManager];
             if (projectAction.ActionType == PackageActionType.Install)
             {
                 projectRepo.AddPackage(action.Package);
             }
             else
             {
                 projectRepo.RemovePackage(action.Package);
             }
         }
     }
 }
Пример #4
0
        private static PackageAction CreateReverseAction(PackageAction action)
        {
            PackageProjectAction action2 = action as PackageProjectAction;

            if (action2 != null)
            {
                return(new PackageProjectAction(GetReverseActionType(action2.ActionType), action2.Package, action2.ProjectManager));
            }
            PackageSolutionAction action3 = (PackageSolutionAction)action;

            return(new PackageSolutionAction(GetReverseActionType(action3.ActionType), action3.Package, action3.PackageManager));
        }
        public void Execute(IEnumerable <PackageAction> actions)
        {
            var executedActions = new List <PackageAction>();

            try
            {
                foreach (var action in actions)
                {
                    executedActions.Add(action);

                    PackageProjectAction projectAction = action as PackageProjectAction;
                    if (projectAction != null)
                    {
                        ExecuteProjectOperation(projectAction);

                        // Binding redirect
                        if (projectAction.ActionType == PackageActionType.Install &&
                            projectAction.ProjectManager.PackageManager != null &&
                            projectAction.ProjectManager.PackageManager.BindingRedirectEnabled &&
                            projectAction.ProjectManager.Project.IsBindingRedirectSupported)
                        {
                            projectAction.ProjectManager.PackageManager.AddBindingRedirects(projectAction.ProjectManager);
                        }
                    }
                    else
                    {
                        PackageSolutionAction solutionAction = (PackageSolutionAction)action;
                        solutionAction.PackageManager.Logger = Logger;
                        if (solutionAction.ActionType == PackageActionType.AddToPackagesFolder)
                        {
                            solutionAction.PackageManager.Execute(new PackageOperation(
                                                                      action.Package,
                                                                      NuGet.PackageAction.Install));
                        }
                        else if (solutionAction.ActionType == PackageActionType.DeleteFromPackagesFolder)
                        {
                            solutionAction.PackageManager.Execute(new PackageOperation(
                                                                      action.Package,
                                                                      NuGet.PackageAction.Uninstall));
                        }
                    }
                }
            }
            catch
            {
                Rollback(executedActions);
                throw;
            }
        }
        private void Rollback(List <PackageAction> executedOperations)
        {
            if (executedOperations.Count > 0)
            {
                // Only print the rollback warning if we have something to rollback
                Logger.Log(MessageLevel.Warning, VsResources.Warning_RollingBack);
            }

            executedOperations.Reverse();
            foreach (var operation in executedOperations)
            {
                var reverseOperation = CreateReverseAction(operation);
                PackageProjectAction projectAction = reverseOperation as PackageProjectAction;
                if (projectAction != null)
                {
                    // Don't log anything during the rollback
                    projectAction.ProjectManager.Logger = NullLogger.Instance;
                    projectAction.ProjectManager.Execute(new PackageOperation(
                                                             projectAction.Package,
                                                             projectAction.ActionType == PackageActionType.Install ?
                                                             NuGet.PackageAction.Install :
                                                             NuGet.PackageAction.Uninstall));
                }
                else
                {
                    PackageSolutionAction solutionAction = (PackageSolutionAction)reverseOperation;

                    // Don't log anything during the rollback
                    solutionAction.PackageManager.Logger = NullLogger.Instance;
                    if (solutionAction.ActionType == PackageActionType.AddToPackagesFolder)
                    {
                        solutionAction.PackageManager.Execute(new PackageOperation(
                                                                  solutionAction.Package,
                                                                  NuGet.PackageAction.Install));
                    }
                    else if (solutionAction.ActionType == PackageActionType.DeleteFromPackagesFolder)
                    {
                        solutionAction.PackageManager.Execute(new PackageOperation(
                                                                  solutionAction.Package,
                                                                  NuGet.PackageAction.Uninstall));
                    }
                }
            }
        }
        private static PackageAction CreateReverseAction(PackageAction action)
        {
            PackageProjectAction projectAction = action as PackageProjectAction;

            if (projectAction != null)
            {
                return(new PackageProjectAction(
                           GetReverseActionType(projectAction.ActionType),
                           projectAction.Package,
                           projectAction.ProjectManager));
            }

            PackageSolutionAction solutionAction = (PackageSolutionAction)action;

            return(new PackageSolutionAction(
                       GetReverseActionType(solutionAction.ActionType),
                       solutionAction.Package,
                       solutionAction.PackageManager));
        }
Пример #8
0
        public void Execute(IEnumerable <PackageAction> actions)
        {
            List <PackageAction> executedOperations = new List <PackageAction>();

            try
            {
                foreach (PackageAction action in actions)
                {
                    executedOperations.Add(action);
                    PackageProjectAction action2 = action as PackageProjectAction;
                    if (action2 != null)
                    {
                        this.ExecuteProjectOperation(action2);
                        if ((action2.ActionType != PackageActionType.Install) || ((action2.ProjectManager.PackageManager == null) || (!action2.ProjectManager.PackageManager.BindingRedirectEnabled || !action2.ProjectManager.Project.IsBindingRedirectSupported)))
                        {
                            continue;
                        }
                        action2.ProjectManager.PackageManager.AddBindingRedirects(action2.ProjectManager);
                        continue;
                    }
                    PackageSolutionAction action3 = (PackageSolutionAction)action;
                    action3.PackageManager.Logger = this.Logger;
                    if (action3.ActionType == PackageActionType.AddToPackagesFolder)
                    {
                        action3.PackageManager.Execute(new PackageOperation(action.Package, PackageAction.Install));
                        continue;
                    }
                    if (action3.ActionType == PackageActionType.DeleteFromPackagesFolder)
                    {
                        action3.PackageManager.Execute(new PackageOperation(action.Package, PackageAction.Uninstall));
                    }
                }
            }
            catch
            {
                this.Rollback(executedOperations);
                throw;
            }
        }