当前位置: 首页>>代码示例>>C#>>正文


C# SourceRepository.GetPackageMetadata方法代码示例

本文整理汇总了C#中SourceRepository.GetPackageMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# SourceRepository.GetPackageMetadata方法的具体用法?C# SourceRepository.GetPackageMetadata怎么用?C# SourceRepository.GetPackageMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SourceRepository的用法示例。


在下文中一共展示了SourceRepository.GetPackageMetadata方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolvePackage

        /// <summary>
        /// Resolve package from online and local repository
        /// Used for Install-Package and Update-Package command to verify the specified package version exists in the repo.
        /// </summary>
        /// <param name="sourceRepository"></param>
        /// <param name="localRepository"></param>
        /// <param name="identity"></param>
        /// <param name="allowPrereleaseVersions"></param>
        /// <returns></returns>
        public static PackageIdentity ResolvePackage(SourceRepository sourceRepository, IPackageRepository localRepository,
            PackageIdentity identity, bool allowPrereleaseVersions)
        {
            string packageId = identity.Id;
            NuGetVersion nVersion = identity.Version;
            string version = identity.Version.ToNormalizedString();

            if (String.IsNullOrEmpty(identity.Id))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "packageId");
            }

            PackageIdentity resolvedIdentity = null;

            // If we're looking for an exact version of a package then try local first
            if (version != null)
            {
                SemanticVersion sVersion = new SemanticVersion(version);
                IPackage package = localRepository.FindPackage(packageId, sVersion, allowPrereleaseVersions, allowUnlisted: false);
                if (package != null)
                {
                    resolvedIdentity = new PackageIdentity(packageId, NuGetVersion.Parse(package.Version.ToString()));
                }
            }

            if (resolvedIdentity == null)
            {
                if (nVersion == null)
                {
                    throw new InvalidOperationException(
                        String.Format(CultureInfo.CurrentCulture,
                        NuGetResources.UnknownPackageSpecificVersion, packageId, version));
                }
                else
                {
                    Task<JObject> task = sourceRepository.GetPackageMetadata(packageId, nVersion);
                    JObject package = task.Result;
                    if (package == null)
                    {
                        if (version != null)
                        {
                            throw new InvalidOperationException(
                                String.Format(CultureInfo.CurrentCulture,
                                NuGetResources.UnknownPackageSpecificVersion, packageId, version));
                        }
                        throw new InvalidOperationException(
                            String.Format(CultureInfo.CurrentCulture,
                            NuGetResources.UnknownPackage, packageId));
                    }
                    else
                    {
                        resolvedIdentity = new PackageIdentity(packageId, nVersion);
                    }
                }
            }

            return resolvedIdentity;
        }
开发者ID:sistoimenov,项目名称:NuGet2,代码行数:67,代码来源:PackageRepositoryHelper.cs

示例2: GetPackageByIdAndVersion

        /// <summary>
        /// Get the JObject of a package with known packageId and version
        /// </summary>
        /// <param name="sourceRepository"></param>
        /// <param name="packageId"></param>
        /// <param name="version"></param>
        /// <param name="allowPrereleaseVersions"></param>
        /// <returns></returns>
        public static JObject GetPackageByIdAndVersion(SourceRepository sourceRepository, string packageId, string version, bool allowPrereleaseVersions)
        {
            NuGetVersion nVersion = GetNuGetVersionFromString(version);
            if (String.IsNullOrEmpty(packageId))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "packageId");
            }

            Task<JObject> task = sourceRepository.GetPackageMetadata(packageId, nVersion);
            JObject package = task.Result;

            if (package == null)
            {
                throw new InvalidOperationException(
                    String.Format(CultureInfo.CurrentCulture,
                    NuGetResources.UnknownPackageSpecificVersion, packageId, version));
            }
            return package;
        }
开发者ID:sistoimenov,项目名称:NuGet2,代码行数:27,代码来源:PowerShellPackage.cs

示例3: GetLastestJObjectsForPackage

        /// <summary>
        /// Get latest JObject for package identity
        /// </summary>
        /// <param name="repo"></param>
        /// <param name="identity"></param>
        /// <param name="allowPrerelease"></param>
        /// <returns></returns>
        public static List<JObject> GetLastestJObjectsForPackage(SourceRepository repo, JObject jObject, VsProject project, bool allowPrerelease, int skip, int take, bool takeAllVersions)
        {
            List<JObject> jObjects = new List<JObject>();
            string id = jObject.Value<string>(Properties.PackageId);
            string version = jObject.Value<string>(Properties.Version);
            NuGetVersion nVersion = GetNuGetVersionFromString(version);

            if (!takeAllVersions)
            {
                string latestVersion = GetLastestVersionForPackage(repo, id, project.GetSupportedFrameworks(), allowPrerelease, nVersion, false);
                if (latestVersion != null)
                {
                    NuGetVersion laVersion = GetNuGetVersionFromString(latestVersion);
                    if (laVersion > nVersion)
                    {
                        Task<JObject> task = repo.GetPackageMetadata(id, laVersion);
                        JObject latestJObject = task.Result;
                        jObjects.Add(latestJObject);
                    }
                }
            }
            else
            {
                JObject package = GetJObjectForPackageId(repo, id, project.GetSupportedFrameworks(), allowPrerelease, skip, take);
                IEnumerable<NuGetVersion> versionList = GetAllVersionsForPackageId(package).OrderByDescending(v => v);
                // Work around a bug in repo.Search(), where prerelease versions are not filtered out.
                if (!allowPrerelease)
                {
                    versionList = versionList.Where(p => p > nVersion && p.IsPrerelease == false);
                }
                else
                {
                    versionList = versionList.Where(p => p > nVersion);
                }

                foreach (NuGetVersion updateVersion in versionList)
                {
                    JObject updateObject = GetPackageByIdAndVersion(repo, id, updateVersion.ToNormalizedString(), allowPrerelease);
                    jObjects.Add(updateObject);
                }
            }
            return jObjects;
        }
开发者ID:sistoimenov,项目名称:NuGet2,代码行数:50,代码来源:PowerShellPackage.cs


注:本文中的SourceRepository.GetPackageMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。