コード例 #1
0
        private static (string License, LicenseType LicenseType) GetLicense(XElement nuspecElement, string packageDirectory)
        {
            SoupDiscoverException.ThrowIfNull(nuspecElement, $"{nameof(nuspecElement)} must be not null!");
            var licenseExpression = nuspecElement.Elements(XName.Get("license", nuspecElement.Name.NamespaceName)).FirstOrDefault(e => e.Attribute("type").Value == "expression")?.Value;

            if (licenseExpression != null)
            {
                return(licenseExpression, LicenseType.Expression);
            }

            var licenseFile = nuspecElement.Elements(XName.Get("license", nuspecElement.Name.NamespaceName)).FirstOrDefault(e => e.Attribute("type").Value == "file")?.Value;

            if (licenseFile != null)
            {
                licenseFile = Path.Combine(packageDirectory, licenseFile);
                if (!File.Exists(licenseFile))
                {
                    return(ISearchPackage.NoneLicenseExpression, LicenseType.None);
                }
                return(File.ReadAllText(licenseFile), LicenseType.File);
            }
            var licenseUrl = nuspecElement.Element(XName.Get("licenseUrl", nuspecElement.Name.NamespaceName))?.Value;

            if (licenseUrl != null)
            {
                return(licenseUrl, LicenseType.Url);
            }
            return(ISearchPackage.NoneLicenseExpression, LicenseType.None);
        }
コード例 #2
0
        private static string GetNugetCacheDirectory(string packageId, string version)
        {
            SoupDiscoverException.ThrowIfNullOrEmpty(packageId, $"{nameof(packageId)} must be not null or empty!");
            SoupDiscoverException.ThrowIfNullOrEmpty(version, $"{nameof(version)} must be not null or empty!");
            var packageDirectory = $"{packageId}.{version}";

            return(Path.Combine(NugetCacheDirectory, packageId, version, $"{packageId}.nuspec").ToLower(CultureInfo.InvariantCulture));
        }
コード例 #3
0
        /// <summary>
        /// Retrieve metadata of the package, in cache, in directory %userprofile%/.nuget/packages
        /// </summary>
        /// <returns>The Xml node of the nuspec file of the package</returns>
        private static XElement GetPackageMetadataOnLocalCache(string packageId, string version)
        {
            SoupDiscoverException.ThrowIfNullOrEmpty(packageId, $"{nameof(packageId)} must be not null or empty!");
            SoupDiscoverException.ThrowIfNullOrEmpty(version, $"{nameof(version)} must be not null or empty!");
            var packageDirectory = GetNugetCacheDirectory(packageId, version);

            if (!File.Exists(packageDirectory))
            {
                return(null); // package not found in cache
            }
            var nuspecFile = XDocument.Load(packageDirectory);

            return(nuspecFile.Root.Element(XName.Get("metadata", nuspecFile.Root.Name.NamespaceName)));
        }