Ejemplo n.º 1
0
        public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, PackageSourceListRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (!ValidatePackageManagementVersion(request))
            {
                return;
            }

            request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, string.Format(CultureInfo.InvariantCulture, "FindPackage' - name='{0}', requiredVersion='{1}',minimumVersion='{2}', maximumVersion='{3}'", name, requiredVersion, minimumVersion, maximumVersion));

            // no package name or the name with wildcard
            if (string.IsNullOrWhiteSpace(name) || WildcardPattern.ContainsWildcardCharacters(name))
            {
                // In the case of the package name is null or contains wildcards, error out if a user puts version info
                if (!string.IsNullOrWhiteSpace(requiredVersion) || !string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrWhiteSpace(maximumVersion))
                {
                    request.Warning(Resources.Messages.WildCardCharsAreNotSupported, name);
                    return;
                }

                var packages = request.GetPackages(name);
                if (request.GetOptionValue("AllVersions").IsTrue())
                {
                    // if version is specified then name can not be empty or with wildcard. in this case the cmdlet has been errored out already.
                    // here we just return all packages we can find
                    if (request.FilterOnVersion(packages, requiredVersion, minimumVersion, maximumVersion, minInclusive: true, maxInclusive: true, latest: false).OrderBy(p => p.Name).Any(p => !request.YieldFromSwidtag(p, p.Name)))
                    {
                        return;
                    }
                    return;
                }

                //return the latest version
                if (packages.GroupBy(p => p.Name)
                    .Select(each => each.OrderByDescending(pp => pp.Version).FirstOrDefault()).OrderBy(p => p.Name).Any(item => !request.YieldFromSwidtag(item, item.Name)))
                {
                    return;
                }
            }
            else
            {
                // a user specifies name
                // asked for a specific version?
                if (!string.IsNullOrWhiteSpace(requiredVersion))
                {
                    request.YieldFromSwidtag(request.GetPackage(name, requiredVersion), name);
                    return;
                }

                var allVersion = request.GetOptionValue("AllVersions").IsTrue();
                // asked for a version range?
                if (!string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrEmpty(maximumVersion) || allVersion)
                {
                    var packages = request.GetPackagesWithinVersionRange(name, minimumVersion, maximumVersion);
                    if (allVersion)
                    {
                        if (packages.Any(p => !request.YieldFromSwidtag(p, name)))
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (request.YieldFromSwidtag(packages.FirstOrDefault(), name))
                        {
                            return;
                        }
                    }

                    return;
                }

                // just return by name
                request.YieldFromSwidtag(request.GetPackage(name), name);
            }
        }
Ejemplo n.º 2
0
        public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, PackageSourceListRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (!ValidatePackageManagementVersion(request))
            {
                return;
            }

            request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, string.Format(CultureInfo.InvariantCulture, "FindPackage' - name='{0}', requiredVersion='{1}',minimumVersion='{2}', maximumVersion='{3}'", name, requiredVersion, minimumVersion, maximumVersion));

            // no package name or the name with wildcard
            if (string.IsNullOrWhiteSpace(name) || WildcardPattern.ContainsWildcardCharacters(name))
            {
                // In the case of the package name is null or contains wildcards, error out if a user puts version info
                if (!string.IsNullOrWhiteSpace(requiredVersion) || !string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrWhiteSpace(maximumVersion))
                {
                    request.Warning(Resources.Messages.WildCardCharsAreNotSupported, name);
                    return;
                }
       
                var packages = request.GetPackages(name);
                if (request.GetOptionValue("AllVersions").IsTrue())
                {
                    // if version is specified then name can not be empty or with wildcard. in this case the cmdlet has been errored out already.
                    // here we just return all packages we can find
                    if (request.FilterOnVersion(packages, requiredVersion, minimumVersion, maximumVersion, minInclusive: true, maxInclusive: true, latest: false).OrderBy(p => p.Name).Any(p => !request.YieldFromSwidtag(p, p.Name)))
                    {
                        return;
                    }
                    return;
                }

                //return the latest version
                if (packages.GroupBy(p => p.Name)
                        .Select(each => each.OrderByDescending(pp => pp.Version).FirstOrDefault()).OrderBy(p=>p.Name).Any( item =>!request.YieldFromSwidtag(item, item.Name)))
                {
                    return;
                }
                
            } else {
 
                // a user specifies name
                // asked for a specific version?
                if (!string.IsNullOrWhiteSpace(requiredVersion))
                {
                    request.YieldFromSwidtag(request.GetPackage(name, requiredVersion), name);
                    return;
                }

                var allVersion = request.GetOptionValue("AllVersions").IsTrue();
                // asked for a version range?
                if (!string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrEmpty(maximumVersion) || allVersion)
                {
                    var packages = request.GetPackagesWithinVersionRange(name, minimumVersion, maximumVersion);
                    if (allVersion)
                    {
                        if (packages.Any(p => !request.YieldFromSwidtag(p, name)))
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (request.YieldFromSwidtag(packages.FirstOrDefault(), name))
                        {
                            return;
                        }
                    }

                    return;
                }

                // just return by name
                request.YieldFromSwidtag(request.GetPackage(name), name);
            }
        }