예제 #1
0
        public async Task<IEnumerable<PackageAction>> ResolveActionsAsync(
            PackageIdentity packageIdentity,
            PackageActionType operation,
            InstallationTarget target)
        {
            // Construct the Action Resolver
            var oldResolver = new OldResolver();
            if (Logger != null)
            {
                oldResolver.Logger = new ShimLogger(Logger);
            }

            // Apply context settings
            ApplyContext(oldResolver);

            var packageManager = target.GetRequiredFeature<IPackageManager>();

            var nullProjectManager = new NullProjectManager(
                new CoreInteropPackageManager(
                    packageManager.LocalRepository,
                    _dependencyResolver,
                    new CoreInteropSourceRepository(_source)));

            oldResolver.AddOperation(
                MapNewToOldActionType(operation),
                await CreateVirtualPackage(packageIdentity.Id, packageIdentity.Version),
                nullProjectManager);

            // Resolve actions!
            var actions = await Task.Factory.StartNew(() => oldResolver.ResolveActions());

            // Convert the actions
            var converted =
                from action in actions
                select new PackageAction(
                    MapOldToNewActionType(action.ActionType),
                    new PackageIdentity(
                        action.Package.Id,
                        new NuGetVersion(
                            action.Package.Version.Version,
                            action.Package.Version.SpecialVersion)),
                    UnwrapPackage(action.Package),
                    target,
                    _source,
                    packageIdentity);

            // Identify update operations so we can mark them as such.
            foreach (var group in converted.GroupBy(c => c.PackageIdentity.Id))
            {
                var installs = group.Where(p => p.ActionType == PackageActionType.Install).ToList();
                var uninstalls = group.Where(p => p.ActionType == PackageActionType.Uninstall).ToList();
                if (installs.Count > 0 && uninstalls.Count > 0)
                {
                    var maxInstall = installs.OrderByDescending(a => a.PackageIdentity.Version).First();
                    maxInstall.IsUpdate = true;
                }
            }

            return converted;
        }
예제 #2
0
        private IEnumerable <PackageAction> ResolveActionsForOperation(Operation operation)
        {
            IEnumerable <PackageOperation> enumerable = Enumerable.Empty <PackageOperation>();

            if (operation.ProjectManager.Project is INuGetPackageManager)
            {
                PackageActionType actionType = (operation.OperationType == PackageAction.Install) ? PackageActionType.Install : PackageActionType.Uninstall;
                return(new PackageProjectAction[] { new PackageProjectAction(actionType, operation.Package, operation.ProjectManager) });
            }
            bool flag = operation.ProjectManager.PackageManager.IsProjectLevel(operation.Package);

            enumerable = (operation.OperationType != PackageAction.Install) ? ((operation.OperationType != PackageAction.Update) ? (!flag ? this.ResolveOperationsToUninstallSolutionLevelPackage(operation) : this.ResolveOperationsToUninstallProjectLevelPackage(operation)) : (!flag ? this.ResolveOperationsToUpdateSolutionLevelPackage(operation) : this.ResolveOperationsToInstallProjectLevelPackage(operation))) : (!flag ? this.ResolveOperationsToInstallSolutionLevelPackage(operation) : this.ResolveOperationsToInstallProjectLevelPackage(operation));
            List <PackageAction> projectActions = new List <PackageAction>();

            foreach (PackageOperation operation2 in enumerable)
            {
                PackageActionType actionType = (operation2.Action == PackageAction.Install) ? PackageActionType.Install : PackageActionType.Uninstall;
                if (operation2.Target == PackageOperationTarget.Project)
                {
                    projectActions.Add(new PackageProjectAction(actionType, operation2.Package, operation.ProjectManager));
                    continue;
                }
                projectActions.Add(new PackageSolutionAction(actionType, operation2.Package, operation.ProjectManager.PackageManager));
            }
            IList <PackageAction> actions = this.ResolveFinalActions(operation.ProjectManager.PackageManager, projectActions);

            this.UpdateVirtualRepos(actions);
            return(actions);
        }
예제 #3
0
 protected PackageAction(
     PackageActionType actionType,
     IPackage package)
 {
     ActionType = actionType;
     Package = package;
 }
예제 #4
0
        // Async void because we don't want metric recording to block anything at all
        public override async void RecordMetric(PackageActionType actionType, PackageIdentity packageIdentity, PackageIdentity dependentPackage, bool isUpdate, IInstallationTarget target)
        {
            var metricsUrl = await GetServiceUri(ServiceUris.MetricsService);

            if (metricsUrl == null)
            {
                // Nothing to do!
                return;
            }

            // Create the JSON payload
            var payload = new JObject();

            payload.Add("id", packageIdentity.Id);
            payload.Add("version", packageIdentity.Version.ToNormalizedString());
            payload.Add("operation", isUpdate ? "Update" : "Install");
            payload.Add("userAgent", _userAgent);
            payload.Add("targetFrameworks", new JArray(target.GetSupportedFrameworks().Select(fx => VersionUtility.GetShortFrameworkName(fx))));
            if (dependentPackage != null)
            {
                payload.Add("dependentPackage", dependentPackage.Id);
                payload.Add("dependentPackageVersion", dependentPackage.Version.ToNormalizedString());
            }
            target.AddMetricsMetadata(payload);

            // Post the message
            await _http.PostAsync(metricsUrl, new StringContent(payload.ToString()));
        }
 protected PackageAction(
     PackageActionType actionType,
     IPackage package)
 {
     ActionType = actionType;
     Package    = package;
 }
예제 #6
0
 public PackageAction(PackageActionType actionType, PackageIdentity packageName, JObject package, InstallationTarget target, SourceRepository source, PackageIdentity dependentPackage)
 {
     ActionType = actionType;
     PackageIdentity = packageName;
     Package = package;
     Target = target;
     Source = source;
     DependentPackage = dependentPackage;
     IsUpdate = false;
 }
 public PackageAction(PackageActionType actionType, PackageIdentity packageName, JObject package, InstallationTarget target, SourceRepository source, PackageIdentity dependentPackage)
 {
     ActionType       = actionType;
     PackageIdentity  = packageName;
     Package          = package;
     Target           = target;
     Source           = source;
     DependentPackage = dependentPackage;
     IsUpdate         = false;
 }
 public PackageActionBaseCommand(
     IVsPackageSourceProvider packageSourceProvider,
     IPackageRepositoryFactory packageRepositoryFactory,
     SVsServiceProvider svcServiceProvider,
     IVsPackageManagerFactory packageManagerFactory,
     ISolutionManager solutionManager,
     IHttpClientEvents clientEvents,
     PackageActionType actionType)
     : base(packageSourceProvider, packageRepositoryFactory, svcServiceProvider, packageManagerFactory, solutionManager, clientEvents)
 {
     _actionType             = actionType;
     _vsCommonOperations     = ServiceLocator.GetInstance <IVsCommonOperations>();
     _deleteOnRestartManager = ServiceLocator.GetInstance <IDeleteOnRestartManager>();
 }
 public PackageActionBaseCommand(
     IVsPackageSourceProvider packageSourceProvider,
     IPackageRepositoryFactory packageRepositoryFactory,
     SVsServiceProvider svcServiceProvider,
     IVsPackageManagerFactory packageManagerFactory,
     ISolutionManager solutionManager,
     IHttpClientEvents clientEvents,
     PackageActionType actionType)
     : base(packageSourceProvider, packageRepositoryFactory, svcServiceProvider, packageManagerFactory, solutionManager, clientEvents)
 {
     _actionType = actionType;
     _vsCommonOperations = ServiceLocator.GetInstance<IVsCommonOperations>();
     _deleteOnRestartManager = ServiceLocator.GetInstance<IDeleteOnRestartManager>();
 }
예제 #10
0
        private static PackageActionType GetReverseActionType(PackageActionType actionType)
        {
            switch (actionType)
            {
            case PackageActionType.Install:
                return(PackageActionType.Uninstall);

            case PackageActionType.Uninstall:
                return(PackageActionType.Install);

            case PackageActionType.AddToPackagesFolder:
                return(PackageActionType.DeleteFromPackagesFolder);

            case PackageActionType.DeleteFromPackagesFolder:
                return(PackageActionType.AddToPackagesFolder);
            }
            throw new InvalidOperationException();
        }
예제 #11
0
        private static NuGet.PackageAction MapNewToOldActionType(PackageActionType operation)
        {
            switch (operation)
            {
            case PackageActionType.Install:
                return(NuGet.PackageAction.Install);

            case PackageActionType.Uninstall:
                return(NuGet.PackageAction.Uninstall);

            default:
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Strings.ActionResolver_UnsupportedAction,
                              operation),
                          "operation");
            }
        }
예제 #12
0
 public override void RecordMetric(PackageActionType actionType, PackageIdentity packageIdentity, PackageIdentity dependentPackage, bool isUpdate, IInstallationTarget target)
 {
     // No-op, V2 doesn't support this.
 }
예제 #13
0
 public UserAction(PackageActionType action, PackageIdentity package)
 {
     Action          = action;
     PackageIdentity = package;
 }
 public override void RecordMetric(PackageActionType actionType, PackageIdentity packageIdentity, PackageIdentity dependentPackage, bool isUpdate, IInstallationTarget target)
 {
     // should not be called
     throw new NotImplementedException();
 }
 public override async void RecordMetric(PackageActionType actionType, PackageIdentity packageIdentity, PackageIdentity dependentPackage, bool isUpdate, IInstallationTarget target)
 {
     await DetectVersionWhenNeccessary();
     _repo.RecordMetric(actionType, packageIdentity, dependentPackage, isUpdate, target);
 }
예제 #16
0
        public async Task <IEnumerable <PackageAction> > ResolveActionsAsync(
            PackageIdentity packageIdentity,
            PackageActionType operation,
            InstallationTarget target)
        {
            // Construct the Action Resolver
            var oldResolver = new OldResolver();

            if (Logger != null)
            {
                oldResolver.Logger = new ShimLogger(Logger);
            }

            // Apply context settings
            ApplyContext(oldResolver);

            var packageManager = target.GetRequiredFeature <IPackageManager>();

            var nullProjectManager = new NullProjectManager(
                new CoreInteropPackageManager(
                    packageManager.LocalRepository,
                    _dependencyResolver,
                    new CoreInteropSourceRepository(_source)));

            oldResolver.AddOperation(
                MapNewToOldActionType(operation),
                await CreateVirtualPackage(packageIdentity.Id, packageIdentity.Version),
                nullProjectManager);

            // Resolve actions!
            var actions = await Task.Factory.StartNew(() => oldResolver.ResolveActions());

            // Convert the actions
            var converted =
                from action in actions
                select new PackageAction(
                    MapOldToNewActionType(action.ActionType),
                    new PackageIdentity(
                        action.Package.Id,
                        new NuGetVersion(
                            action.Package.Version.Version,
                            action.Package.Version.SpecialVersion)),
                    UnwrapPackage(action.Package),
                    target,
                    _source,
                    packageIdentity);

            // Identify update operations so we can mark them as such.
            foreach (var group in converted.GroupBy(c => c.PackageIdentity.Id))
            {
                var installs   = group.Where(p => p.ActionType == PackageActionType.Install).ToList();
                var uninstalls = group.Where(p => p.ActionType == PackageActionType.Uninstall).ToList();
                if (installs.Count > 0 && uninstalls.Count > 0)
                {
                    var maxInstall = installs.OrderByDescending(a => a.PackageIdentity.Version).First();
                    maxInstall.IsUpdate = true;
                }
            }

            return(converted);
        }
예제 #17
0
        public async Task <IEnumerable <PackageAction> > ResolveActionsAsync(
            PackageIdentity packageIdentity,
            PackageActionType operation,
            IEnumerable <Project> targetedProjects,
            Solution solution)
        {
            // Construct the Action Resolver
            var resolver = new OldResolver();

            if (Logger != null)
            {
                resolver.Logger = new ShimLogger(Logger);
            }

            // Apply context settings
            ApplyContext(resolver);

            // Add the operation request(s)
            NuGetTraceSources.ActionResolver.Verbose("resolving", "Resolving {0} of {1} {2}", operation.ToString(), packageIdentity.Id, packageIdentity.Version.ToNormalizedString());
            foreach (var project in targetedProjects)
            {
                resolver.AddOperation(
                    MapNewToOldActionType(operation),
                    await CreateVirtualPackage(packageIdentity.Id, packageIdentity.Version),
                    new CoreInteropProjectManager(project, _source, _dependencyResolver));
            }

            // Resolve actions!
            var actions = await Task.Factory.StartNew(() => resolver.ResolveActions());

            // Convert the actions
            var converted =
                from action in actions
                let projectAction = action as PackageProjectAction
                                    select new PackageAction(
                    MapOldToNewActionType(action.ActionType),
                    new PackageIdentity(
                        action.Package.Id,
                        new NuGetVersion(
                            action.Package.Version.Version,
                            action.Package.Version.SpecialVersion)),
                    UnwrapPackage(action.Package),
                    (projectAction != null ?
                     FindProject(targetedProjects, projectAction.ProjectManager.Project.ProjectName) :
                     (InstallationTarget)solution),
                    _source,
                    packageIdentity);

            // Identify update operations so we can mark them as such.
            foreach (var group in converted.GroupBy(c => c.PackageIdentity.Id))
            {
                var installs   = group.Where(p => p.ActionType == PackageActionType.Install).ToList();
                var uninstalls = group.Where(p => p.ActionType == PackageActionType.Uninstall).ToList();
                if (installs.Count > 0 && uninstalls.Count > 0)
                {
                    var maxInstall = installs.OrderByDescending(a => a.PackageIdentity.Version).First();
                    maxInstall.IsUpdate = true;
                }
            }

            return(converted);
        }
 public PackageProjectAction(PackageActionType actionType, IPackage package, IProjectManager projectManager) :
     base(actionType, package)
 {
     ProjectManager = projectManager;
     _projectName   = ProjectManager.Project.ProjectName;
 }
예제 #19
0
 public UserAction(PackageActionType action, PackageIdentity package)
 {
     Action = action;
     PackageIdentity = package;
 }
예제 #20
0
 protected PackageAction(PackageActionType actionType, IPackage package)
 {
     this.ActionType = actionType;
     this.Package    = package;
 }
예제 #21
0
 public override void RecordMetric(PackageActionType actionType, PackageIdentity packageIdentity, PackageIdentity dependentPackage, bool isUpdate, IInstallationTarget target)
 {
     // No-op, V2 doesn't support this.
 }
        public override async void RecordMetric(PackageActionType actionType, PackageIdentity packageIdentity, PackageIdentity dependentPackage, bool isUpdate, IInstallationTarget target)
        {
            await DetectVersionWhenNeccessary();

            _repo.RecordMetric(actionType, packageIdentity, dependentPackage, isUpdate, target);
        }
예제 #23
0
        // Async void because we don't want metric recording to block anything at all
        public override async void RecordMetric(PackageActionType actionType, PackageIdentity packageIdentity, PackageIdentity dependentPackage, bool isUpdate, IInstallationTarget target)
        {
            var metricsUrl = await GetServiceUri(ServiceUris.MetricsService);

            if (metricsUrl == null)
            {
                // Nothing to do!
                return;
            }

            // Create the JSON payload
            var payload = new JObject();
            payload.Add("id", packageIdentity.Id);
            payload.Add("version", packageIdentity.Version.ToNormalizedString());
            payload.Add("operation", isUpdate ? "Update" : "Install");
            payload.Add("userAgent", _userAgent);
            payload.Add("targetFrameworks", new JArray(target.GetSupportedFrameworks().Select(fx => VersionUtility.GetShortFrameworkName(fx))));
            if (dependentPackage != null)
            {
                payload.Add("dependentPackage", dependentPackage.Id);
                payload.Add("dependentPackageVersion", dependentPackage.Version.ToNormalizedString());
            }
            target.AddMetricsMetadata(payload);

            // Post the message
            await _http.PostAsync(metricsUrl, new StringContent(payload.ToString()));
        }
예제 #24
0
 private static PackageActionType GetReverseActionType(PackageActionType actionType)
 {
     switch (actionType)
     {
         case PackageActionType.AddToPackagesFolder:
             return PackageActionType.DeleteFromPackagesFolder;
         case PackageActionType.DeleteFromPackagesFolder:
             return PackageActionType.AddToPackagesFolder;
         case PackageActionType.Install:
             return PackageActionType.Uninstall;
         case PackageActionType.Uninstall:
             return PackageActionType.Install;
         default:
             throw new InvalidOperationException();
     }
 }
예제 #25
0
 public PackageProjectAction(PackageActionType actionType, IPackage package, IProjectManager projectManager) :
     base(actionType, package)
 {
     ProjectManager = projectManager;
     _projectName = ProjectManager.Project.ProjectName;
 }
예제 #26
0
        public async Task<IEnumerable<PackageAction>> ResolveActionsAsync(
            PackageIdentity packageIdentity,
            PackageActionType operation,
            IEnumerable<Project> targetedProjects,
            Solution solution)
        {
            // Construct the Action Resolver
            var resolver = new OldResolver();
            if (Logger != null)
            {
                resolver.Logger = new ShimLogger(Logger);
            }

            // Apply context settings
            ApplyContext(resolver);

            // Add the operation request(s)
            NuGetTraceSources.ActionResolver.Verbose("resolving", "Resolving {0} of {1} {2}", operation.ToString(), packageIdentity.Id, packageIdentity.Version.ToNormalizedString());
            foreach (var project in targetedProjects)
            {
                resolver.AddOperation(
                    MapNewToOldActionType(operation),
                    await CreateVirtualPackage(packageIdentity.Id, packageIdentity.Version),
                    new CoreInteropProjectManager(project, _source, _dependencyResolver));
            }

            // Resolve actions!
            var actions = await Task.Factory.StartNew(() => resolver.ResolveActions());

            // Convert the actions
            var converted =
                from action in actions
                let projectAction = action as PackageProjectAction
                select new PackageAction(
                    MapOldToNewActionType(action.ActionType),
                    new PackageIdentity(
                        action.Package.Id,
                        new NuGetVersion(
                            action.Package.Version.Version,
                            action.Package.Version.SpecialVersion)),
                    UnwrapPackage(action.Package),
                    (projectAction != null ?
                        FindProject(targetedProjects, projectAction.ProjectManager.Project.ProjectName) :
                        (InstallationTarget)solution),
                    _source,
                    packageIdentity);

            // Identify update operations so we can mark them as such.
            foreach (var group in converted.GroupBy(c => c.PackageIdentity.Id))
            {
                var installs = group.Where(p => p.ActionType == PackageActionType.Install).ToList();
                var uninstalls = group.Where(p => p.ActionType == PackageActionType.Uninstall).ToList();
                if (installs.Count > 0 && uninstalls.Count > 0)
                {
                    var maxInstall = installs.OrderByDescending(a => a.PackageIdentity.Version).First();
                    maxInstall.IsUpdate = true;
                }
            }

            return converted;
        }
예제 #27
0
        private static NuGet.PackageAction MapNewToOldActionType(PackageActionType operation)
        {
            switch (operation)
            {
                case PackageActionType.Install:
                    return NuGet.PackageAction.Install;

                case PackageActionType.Uninstall:
                    return NuGet.PackageAction.Uninstall;

                default:
                    throw new ArgumentException(
                        String.Format(
                            CultureInfo.CurrentCulture,
                            Strings.ActionResolver_UnsupportedAction,
                            operation),
                        "operation");
            }
        }
예제 #28
0
 public PackageSolutionAction(PackageActionType actionType, IPackage package, IPackageManager packageManager) :
     base(actionType, package)
 {
     PackageManager = packageManager;
 }
        /// <summary>
        /// Resolve and execute actions for a single package for specified package action type.
        /// </summary>
        /// <param name="identity"></param>
        /// <param name="projects"></param>
        /// <param name="actionType"></param>
        protected void ExecuteSinglePackageAction(PackageIdentity identity, IEnumerable <VsProject> projects, PackageActionType actionType)
        {
            if (identity == null)
            {
                return;
            }

            try
            {
                // Resolve Actions
                List <VsProject> targetProjects = projects.ToList();
                Task <IEnumerable <Client.Resolution.PackageAction> > resolverAction =
                    PackageActionResolver.ResolveActionsAsync(identity, actionType, targetProjects, Solution);

                IEnumerable <Client.Resolution.PackageAction> actions = resolverAction.Result;

                if (WhatIf.IsPresent)
                {
                    foreach (VsProject proj in targetProjects)
                    {
                        IEnumerable <PreviewResult> previewResults = PreviewResult.CreatePreview(actions, proj);
                        if (previewResults.Count() == 0)
                        {
                            PowerShellPreviewResult prResult = new PowerShellPreviewResult();
                            prResult.Id          = identity.Id;
                            prResult.Action      = Resources.Log_NoActionsWhatIf;
                            prResult.ProjectName = proj.Name;
                            WriteObject(prResult);
                        }
                        else
                        {
                            foreach (var p in previewResults)
                            {
                                LogPreviewResult(p, proj);
                            }
                        }
                    }

                    return;
                }

                // Execute Actions
                if (actions.Count() == 0 && actionType == PackageActionType.Install)
                {
                    Log(MessageLevel.Info, NuGetResources.Log_PackageAlreadyInstalled, identity.Id);
                }
                else
                {
                    var            userAction = new UserAction(_actionType, identity);
                    ActionExecutor executor   = new ActionExecutor();
                    executor.ExecuteActions(actions, this, userAction);
                }
            }
            // TODO: Consider adding the rollback behavior if exception is thrown.
            catch (Exception ex)
            {
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    WriteError(ex.InnerException.Message);
                }
                else
                {
                    WriteError(ex.Message);
                }
            }
        }
 public override void RecordMetric(PackageActionType actionType, PackageIdentity packageIdentity, PackageIdentity dependentPackage, bool isUpdate, IInstallationTarget target)
 {
     // should not be called
     throw new NotImplementedException();
 }
 public PackageSolutionAction(PackageActionType actionType, IPackage package, IPackageManager packageManager) :
     base(actionType, package)
 {
     PackageManager = packageManager;
 }
예제 #32
0
        /// <summary>
        /// Resolve and execute actions for a single package for specified package action type.
        /// </summary>
        /// <param name="identity"></param>
        /// <param name="projects"></param>
        /// <param name="actionType"></param>
        protected void ExecuteSinglePackageAction(PackageIdentity identity, IEnumerable<VsProject> projects, PackageActionType actionType)
        {
            if (identity == null)
            {
                return;
            }

            try
            {
                // Resolve Actions
                List<VsProject> targetProjects = projects.ToList();
                Task<IEnumerable<Client.Resolution.PackageAction>> resolverAction =
                    PackageActionResolver.ResolveActionsAsync(identity, actionType, targetProjects, Solution);

                IEnumerable<Client.Resolution.PackageAction> actions = resolverAction.Result;

                if (WhatIf.IsPresent)
                {
                    foreach (VsProject proj in targetProjects)
                    {
                        IEnumerable<PreviewResult> previewResults = PreviewResult.CreatePreview(actions, proj);
                        if (previewResults.Count() == 0)
                        {
                            PowerShellPreviewResult prResult = new PowerShellPreviewResult();
                            prResult.Id = identity.Id;
                            prResult.Action = Resources.Log_NoActionsWhatIf;
                            prResult.ProjectName = proj.Name;
                            WriteObject(prResult);
                        }
                        else
                        {
                            foreach (var p in previewResults)
                            {
                                LogPreviewResult(p, proj);
                            }
                        }
                    }

                    return;
                }

                // Execute Actions
                if (actions.Count() == 0 && actionType == PackageActionType.Install)
                {
                    Log(MessageLevel.Info, NuGetResources.Log_PackageAlreadyInstalled, identity.Id);
                }
                else
                {
                    var userAction = new UserAction(_actionType, identity);
                    ActionExecutor executor = new ActionExecutor();
                    executor.ExecuteActions(actions, this, userAction);
                }
            }
            // TODO: Consider adding the rollback behavior if exception is thrown.
            catch (Exception ex)
            {
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    WriteError(ex.InnerException.Message);
                }
                else
                {
                    WriteError(ex.Message);
                }
            }
        }