Beispiel #1
0
        private bool InstallProviderFromInstaller(Package provider, Link link, string fastPath, BootstrapRequest request)
        {
            switch (link.MediaType)
            {
            case Iso19770_2.MediaType.MsiPackage:
            case Iso19770_2.MediaType.MsuPackage:
                return(InstallPackageFile(provider, fastPath, request));

            case Iso19770_2.MediaType.PackageReference:
                // let the core figure out how to install this package
                var packages = PackageManagementService.FindPackageByCanonicalId(link.HRef.AbsoluteUri, request).ToArray();
                switch (packages.Length)
                {
                case 0:
                    request.Warning("Unable to resolve package reference '{0}'", link.HRef);
                    return(false);

                case 1:
                    return(InstallPackageReference(provider, fastPath, request, packages));

                default:
                    request.Warning("Package Reference '{0}' resolves to {1} packages.", link.HRef, packages.Length);
                    return(false);
                }

            case Iso19770_2.MediaType.NuGetPackage:
                return(InstallNugetPackage(provider, link, fastPath, request));

            default:
                request.Warning("Provider '{0}' with link '{1}' has unknown media type '{2}'.", provider.Name, link.HRef, link.MediaType);
                return(false);
            }
        }
Beispiel #2
0
        public void FindPackageTest()
        {
            using (CaptureConsole) {
                var packages = Provider.FindPackage("zlib", null, null, null, new BasicHostImpl()).ToArray();

                Assert.Equal(1, packages.Length);
                var pkg1 = packages[0];

                foreach (var pkg in packages)
                {
                    Console.WriteLine("PKG (zlib?) : {0}", pkg.SwidTagText);
                }

                Assert.Equal(1, pkg1.Dependencies.Count());

                Console.WriteLine("Getting Dependencies");
                packages = PackageManagementService.FindPackageByCanonicalId(pkg1.Dependencies.FirstOrDefault(), new BasicHostImpl()).ToArray();
                Assert.Equal(1, packages.Length);

                Console.WriteLine("Processing Dependencies");

                var pkg2 = packages[0];

                foreach (var pkg in packages)
                {
                    Console.WriteLine("PKG (zlib.redist?): {0}", pkg.SwidTagText);
                }
            }
        }
Beispiel #3
0
        protected override void ProcessPackage(PackageProvider provider, IEnumerable <string> searchKey, SoftwareIdentity package)
        {
            base.ProcessPackage(provider, searchKey, package);

            // return the object to the caller now.
            WriteObject(package);

            if (IncludeDependencies)
            {
                var missingDependencies = new HashSet <string>();
                foreach (var dep in package.Dependencies)
                {
                    // note: future work may be needed if the package sources currently selected by the user don't
                    // contain the dependencies.
                    var dependendcies = PackageManagementService.FindPackageByCanonicalId(dep, this);
                    var depPkg        = dependendcies.OrderByDescending(pp => pp, SoftwareIdentityVersionComparer.Instance).FirstOrDefault();

                    if (depPkg == null)
                    {
                        missingDependencies.Add(dep);
                        Warning(Constants.Messages.UnableToFindDependencyPackage, dep);
                    }
                    else
                    {
                        ProcessPackage(depPkg.Provider, searchKey.Select(each => each + depPkg.Name).ToArray(), depPkg);
                    }
                }
                if (missingDependencies.Any())
                {
                    Error(Constants.Errors.UnableToFindDependencyPackage, missingDependencies.JoinWithComma());
                }
            }
        }
Beispiel #4
0
        public IEnumerable <SoftwareIdentity> FindPackageByCanonicalId(string canonicalId, IRequest requestObject)
        {
            if (requestObject == null)
            {
                throw new ArgumentNullException("requestObject");
            }

            return(PackageManagementService.FindPackageByCanonicalId(canonicalId, requestObject));
        }
Beispiel #5
0
        /// <summary>
        /// Do a dfs visit. returns false if a cycle is encountered. Add the packageItem to the list at the end of each visit
        /// </summary>
        /// <param name="packageItem"></param>
        /// <param name="dependencyToBeInstalled"></param>
        /// <param name="permanentlyMarked"></param>
        /// <param name="temporarilyMarked"></param>
        /// <returns></returns>
        internal bool DepthFirstVisit(SoftwareIdentity packageItem, HashSet <SoftwareIdentity> temporarilyMarked,
                                      HashSet <SoftwareIdentity> permanentlyMarked, List <SoftwareIdentity> dependencyToBeInstalled)
        {
            // dependency loop detected because the element is temporarily marked
            if (temporarilyMarked.Contains(packageItem))
            {
                return(false);
            }

            // this is permanently marked. So we don't have to visit it.
            // This is to resolve a case where we have: A->B->C and A->C. Then we need this when we visit C again from either B or A.
            if (permanentlyMarked.Contains(packageItem))
            {
                return(true);
            }

            // Mark this node temporarily so we can detect cycle.
            temporarilyMarked.Add(packageItem);

            // Visit the dependency
            foreach (var dependency in packageItem.Dependencies)
            {
                var dependencies = PackageManagementService.FindPackageByCanonicalId(dependency, this);
                var depPkg       = dependencies.OrderByDescending(pp => pp, SoftwareIdentityVersionComparer.Instance).FirstOrDefault();

                if (!DepthFirstVisit(depPkg, temporarilyMarked, permanentlyMarked, dependencyToBeInstalled))
                {
                    // if dfs returns false then we have encountered a loop
                    return(false);
                }
                // otherwise visit the next dependency
            }

            // Add the package to the list so we can install later
            dependencyToBeInstalled.Add(packageItem);

            // Done with this node so mark it permanently
            permanentlyMarked.Add(packageItem);

            // Unmark it temporarily
            temporarilyMarked.Remove(packageItem);

            return(true);
        }
Beispiel #6
0
        protected override void ProcessPackage(PackageProvider provider, IEnumerable <string> searchKey, SoftwareIdentity package)
        {
            if (WhatIf)
            {
                // grab the dependencies and return them *first*

                foreach (var dep in package.Dependencies)
                {
                    // note: future work may be needed if the package sources currently selected by the user don't
                    // contain the dependencies.
                    var dependendcies = PackageManagementService.FindPackageByCanonicalId(dep, this);
                    foreach (var depPackage in dependendcies)
                    {
                        ProcessPackage(depPackage.Provider, searchKey.Select(each => each + depPackage.Name).ToArray(), depPackage);
                    }
                }
            }
            base.ProcessPackage(provider, searchKey, package);
        }
Beispiel #7
0
        protected override void ProcessPackage(PackageProvider provider, IEnumerable <string> searchKey, SoftwareIdentity package)
        {
            Debug("Calling ProcessPackage SearchKey = '{0}' and provider name ='{1}'", searchKey, package.ProviderName);
            try {
                base.ProcessPackage(provider, searchKey, package);

                // output to console
                WriteObject(AddPropertyToSoftwareIdentity(package));

                if (IncludeDependencies)
                {
                    var missingDependencies = new HashSet <string>();
                    foreach (var dep in package.Dependencies)
                    {
                        var dependendcies = PackageManagementService.FindPackageByCanonicalId(dep, this);
                        var depPkg        = dependendcies.OrderByDescending(pp => pp, SoftwareIdentityVersionComparer.Instance).FirstOrDefault();

                        if (depPkg == null)
                        {
                            missingDependencies.Add(dep);
                            Warning(Constants.Messages.UnableToFindDependencyPackage, dep);
                        }
                        else
                        {
                            ProcessPackage(depPkg.Provider, searchKey.Select(each => each + depPkg.Name).ToArray(), depPkg);
                        }
                    }
                    if (missingDependencies.Any())
                    {
                        Error(Constants.Errors.UnableToFindDependencyPackage, missingDependencies.JoinWithComma());
                    }
                }
            } catch (Exception ex) {
                Debug("Calling ProcessPackage {0}", ex.Message);
            }
        }