/// <summary>
        /// True if the VersionBase objects are equal based on the given comparison mode.
        /// </summary>
        public virtual bool Equals(SemanticVersion other, VersionComparison versionComparison)
        {
            var comparer = new VersionComparer(versionComparison);

            return(comparer.Equals(this, other));
        }
        /// <summary>
        /// Compares NuGetVersion objects using the given comparison mode.
        /// </summary>
        public virtual int CompareTo(SemanticVersion other, VersionComparison versionComparison)
        {
            var comparer = new VersionComparer(versionComparison);

            return(comparer.Compare(this, other));
        }
Esempio n. 3
0
        private static int Compare(SemanticVersion version1, SemanticVersion version2)
        {
            IVersionComparer comparer = new VersionComparer();

            return(comparer.Compare(version1, version2));
        }
        /// <summary>
        /// Compares the given versions using the VersionComparison mode.
        /// </summary>
        public static int Compare(SemanticVersion version1, SemanticVersion version2, VersionComparison versionComparison)
        {
            IVersionComparer comparer = new VersionComparer(versionComparison);

            return(comparer.Compare(version1, version2));
        }
Esempio n. 5
0
        /// <summary>
        /// Compares NuGetVersion objects using the given comparison mode.
        /// </summary>
        public virtual int CompareTo(SimpleVersion other, VersionComparison versionComparison)
        {
            VersionComparer comparer = new VersionComparer(versionComparison);

            return(comparer.Compare(this, other));
        }
Esempio n. 6
0
 /// <summary>
 /// Compares the given versions using the VersionComparison mode.
 /// </summary>
 public static int Compare(SemanticVersion version1, SemanticVersion version2, VersionComparison versionComparison)
 {
     IVersionComparer comparer = new VersionComparer(versionComparison);
     return comparer.Compare(version1, version2);
 }
        public async Task<PackageVersionResponse> PackageVersion(PackageVersionRequest request)
        {
            var projectPath = request.ProjectPath;
            if (request.ProjectPath.EndsWith(".json"))
            {
                projectPath = Path.GetDirectoryName(projectPath);
            }

            if (!string.IsNullOrWhiteSpace(projectPath))
            {
                if (request.Sources == null)
                    request.Sources = Enumerable.Empty<string>();
                    
                var token = CancellationToken.None;

                var filter = new SearchFilter
                {
                    IncludePrerelease = request.IncludePrerelease
                };
                var foundVersions = new List<NuGetVersion>();
                var repositoryProvider = new OmniSharpSourceRepositoryProvider(projectPath);
                var repos = repositoryProvider.GetRepositories().ToArray();
                if (request.Sources.Any())
                {
                    // Reduce to just the sources we requested
                    repos = repos.Join(request.Sources, x => x.PackageSource.Source, x => x, (x, y) => x).ToArray();
                }
                foreach (var repo in repos)
                {
                    // TODO: Swap when bug is fixed
                    // https://github.com/NuGet/NuGet3/pull/90
                    /*
                    var resource = await repo.GetResourceAsync<FindPackageByIdResource>();
                    if (resource != null)
                    {
                        resource.Logger = NullLogger.Instance;
                        resource.NoCache = true;
                        foundVersions.AddRange(await resource.GetAllVersionsAsync(request.Id, token));
                    }*/
                    var resource = await repo.GetResourceAsync<SimpleSearchResource>();
                    if (resource != null)
                    {
                        var result = await resource.Search(request.Id, filter, 0, 50, token);
                        var package = result.FirstOrDefault(metadata => metadata.Identity.Id == request.Id);
                        if (package != null)
                            foundVersions.AddRange(package.AllVersions);
                    }
                }

                var comparer = new VersionComparer();
                var versions = Enumerable.Distinct<NuGetVersion>(foundVersions, comparer)
                    .OrderByDescending(version => version, comparer)
                    .Select(version => version.ToNormalizedString());

                return new PackageVersionResponse()
                {
                    Versions = versions
                };
            }

            return new PackageVersionResponse();
        }
 // A versions file is of the form https://github.com/dotnet/versions/blob/master/build-info/dotnet/corefx/master/Latest_Packages.txt
 private Dictionary<string, PackageItem> GatherPackageInformationFromVersionsFile(string versionsFile, VersionComparer comparer = null)
 {
     Dictionary<string, PackageItem> packageItems = new Dictionary<string, PackageItem>();
     if (!File.Exists(versionsFile))
     {
         Log.LogError("Specified versions file ({0}) does not exist.", versionsFile);
     }
     var lines = File.ReadAllLines(versionsFile);
     foreach(string line in lines)
     { 
         if(!string.IsNullOrWhiteSpace(line))
         {
             string [] packageVersionTokens = line.Split(' ');
             PackageItem packageItem = CreatePackageItem(packageVersionTokens[0], packageVersionTokens[1]);
             AddPackageItemToDictionary(packageItems, packageItem);
         }
     }
     return packageItems;
 }
 private void AddPackageItemToDictionary(Dictionary<string, PackageItem> packageItems, PackageItem packageItem)
 {
     if (packageItems.ContainsKey(packageItem.Name))
     {
         if (comparer == null)
         {
             comparer = new VersionComparer(VersionComparison.VersionRelease);
         }
         if (comparer.Compare(packageItems[packageItem.Name].Version, packageItem.Version) != 0 && UseNewestAvailablePackages != true)
         {
             Log.LogError("Package named {0} already exists.  Cannot have multiple packages with the same name.\n", packageItem.Name);
             Log.LogError("To permit package name clashes and take latest, specify 'UseNewestAvailablePackages=true'.\n");
             Log.LogError("Package {0} version {1} clashes with {2}", packageItem.Name, packageItems[packageItem.Name].Version.ToFullString(), packageItem.Version.ToFullString());
         }
         else if (UseNewestAvailablePackages == true)
         {
             PackageItem item = (comparer.Compare(packageItems[packageItem.Name].Version, packageItem.Version) < 0) ? packageItem : packageItems[packageItem.Name];
             packageItems[packageItem.Name] = item;
         }
     }
     else
     {
         packageItems.Add(packageItem.Name, packageItem);
     }
 }