コード例 #1
0
        /// <summary>
        /// Generates an installation plan
        /// </summary>
        /// <param name="productPackages">Current product</param>
        /// <param name="packages">Packages to install</param>
        /// <returns><see cref="InstallationPlan" /></returns>
        public async Task <InstallationPlan> PlanInstallation(IPackageGraph productPackages, ICollection <PackageId> packages)
        {
            var plan = new InstallationPlan();
            var resolvedPackagesDictionary = new Dictionary <PackageId, DeploymentPackageInfo>();
            var resolvedPackages           = await NuGetEngine.ResolvePackages(packages);

            NuGetEngine.AnalyzePackages(resolvedPackages);

            var graphBuilder = new PackageGraphBuilder();

            foreach (var innerNode in resolvedPackages.InnerNodes)
            {
                TranslateNuGetGraphNode(innerNode, graphBuilder, resolvedPackagesDictionary);
            }

            plan.TargetPackageGraph = graphBuilder.Build();
            var resolvedPackagesList = plan.TargetPackageGraph.FlattenMostDependentFirst();
            var productPackagesList  = productPackages.FlattenMostDependentFirst();

            var deploymentActions = new List <DeploymentAction>();

            foreach (var packageId in resolvedPackagesList)
            {
                var packageMatch = productPackagesList.FirstOrDefault(x => x.Id == packageId.Id);
                var isUpdate     = (packageMatch != null) && (packageMatch.Version != packageId.Version);
                var install      = (packageMatch == null) || isUpdate;

                if (isUpdate)
                {
                    deploymentActions.Add(new DeletePackageAction(DeploymentContext, true, packageMatch));
                    plan.UpdateCount++;
                }

                if (install)
                {
                    var packageInfo = resolvedPackagesDictionary[packageId];
                    deploymentActions.Add(new DownloadPackageAction(DeploymentContext, isUpdate,
                                                                    packageInfo, NuGetEngine, PackagesFolderPath));
                    deploymentActions.Add(new InstallPackageAction(DeploymentContext, isUpdate, packageInfo,
                                                                   DeploymentStrategyProvider));

                    if (!isUpdate)
                    {
                        plan.InstallCount++;
                    }
                }
                else
                {
                    plan.RemainingPackages.Add(packageId);
                }
            }

            plan.Actions = deploymentActions.Where(x => x is DownloadPackageAction)
                           .Concat(deploymentActions.Where(x => x is DeletePackageAction))
                           .Concat(deploymentActions.Where(x => x is InstallPackageAction))
                           .ToList();

            return(plan);
        }
コード例 #2
0
        protected virtual async Task OnResolvePackages()
        {
            MergeWithProductPackages();

            var resolvedPackages = await NuGetEngine.ResolvePackages(WorkflowContext.InputPackages);

            NuGetEngine.AnalysePackages(resolvedPackages);

            foreach (var innerNode in resolvedPackages.InnerNodes)
            {
                FlattenPackageNode(innerNode, null);
            }

            while (WorkflowContext.FlatteningCache.Any())
            {
                var nextNode = WorkflowContext.FlatteningCache.Dequeue();
                FlattenPackageNode(nextNode.Item1, nextNode.Item2);
            }

            PrepareInstallationAndDeletionLists();
        }