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


C# IPackageRepository.Exists方法代码示例

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


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

示例1: IsPackageInstalled

 // Do a very quick check of whether a package in installed by checking whether the nupkg file exists
 private bool IsPackageInstalled(IPackageRepository repository, IFileSystem fileSystem, string packageId, SemanticVersion version)
 {
     if (!AllowMultipleVersions)
     {
         // If we allow side-by-side, we'll check if any version of a package is installed. This operation is expensive since it involves
         // reading package metadata, consequently we don't use this approach when side-by-side isn't used.
         return repository.Exists(packageId);
     }
     else if (version != null)
     {
         // If we know exactly what package to lookup, check if it's already installed locally. 
         // We'll do this by checking if the package directory exists on disk.
         var localRepository = repository as LocalPackageRepository;
         Debug.Assert(localRepository != null, "The PackageManager's local repository instance is necessarily a LocalPackageRepository instance.");
         var packagePaths = localRepository.GetPackageLookupPaths(packageId, version);
         return packagePaths.Any(fileSystem.FileExists);
     }
     return false;
 }
开发者ID:riteshparekh,项目名称:NuGet,代码行数:20,代码来源:InstallCommand.cs

示例2: UpdatePackages

        internal void UpdatePackages(IPackageRepository localRepository,
                                     IFileSystem sharedRepositoryFileSystem,
                                     ISharedPackageRepository sharedPackageRepository,
                                     IPackageRepository sourceRepository,
                                     IPackageConstraintProvider constraintProvider,
                                     IPackagePathResolver pathResolver,
                                     IProjectSystem project)
        {
            var packageManager = new PackageManager(sourceRepository, pathResolver, sharedRepositoryFileSystem, sharedPackageRepository);

            var projectManager = new ProjectManager(packageManager, pathResolver, project, localRepository)
                                 {
                                     ConstraintProvider = constraintProvider
                                 };

            // Fix for work item 2411: When updating packages, we did not add packages to the shared package repository. 
            // Consequently, when querying the package reference repository, we would have package references with no backing package files in
            // the shared repository. This would cause the reference repository to skip the package assuming that the entry is invalid.
            projectManager.PackageReferenceAdded += (sender, eventArgs) =>
            {
                PackageExtractor.InstallPackage(packageManager, eventArgs.Package);
            };

            projectManager.Logger = project.Logger = this;

            foreach (var package in GetPackages(localRepository))
            {
                if (localRepository.Exists(package.Id))
                {
                    using (sourceRepository.StartOperation(RepositoryOperationNames.Update, package.Id, mainPackageVersion: null))
                    {
                        try
                        {
                            // If the user explicitly allows prerelease or if the package being updated is prerelease we'll include prerelease versions in our list of packages
                            // being considered for an update.
                            bool allowPrerelease = Prerelease || !package.IsReleaseVersion();
                            var resolver = new ActionResolver()
                            {
                                AllowPrereleaseVersions = allowPrerelease
                            };
                            var updateUtility = new UpdateUtility(resolver)
                            {
                                AllowPrereleaseVersions = allowPrerelease,
                                Safe = Safe
                            };

                            var operations = updateUtility.ResolveActionsForUpdate(package.Id, null, new[] { projectManager }, false);
                            var userOperationExecutor = new ActionExecutor();
                            userOperationExecutor.Execute(operations);
                        }
                        catch (InvalidOperationException e)
                        {
                            if (Console.Verbosity == NuGet.Verbosity.Detailed)
                            {
                                Console.WriteWarning(e.ToString());
                            }
                            else
                            {
                                Console.WriteWarning(e.Message);
                            }
                        }
                    }
                }
            }
        }
开发者ID:rikoe,项目名称:nuget,代码行数:65,代码来源:UpdateCommand.cs

示例3: EnsurePackage

        internal void EnsurePackage(IPackageRepository cacheRepository)
        {
            // OData caches instances of DataServicePackage while updating their property values. As a result, 
            // the ZipPackage that we downloaded may no longer be valid (as indicated by a newer hash). 
            // When using MachineCache, once we've verified that the hashes match (which happens the first time around),
            // we'll simply verify the file exists between successive calls.
            IPackageMetadata packageMetadata = this;
            bool refreshPackage = _package == null || 
                                  !String.Equals(OldHash, PackageHash, StringComparison.OrdinalIgnoreCase) || 
                                  (_usingMachineCache && !cacheRepository.Exists(Id, packageMetadata.Version));
            if (refreshPackage
                && TryGetPackage(cacheRepository, packageMetadata, out _package)
                && _package.GetHash(HashProvider).Equals(PackageHash, StringComparison.OrdinalIgnoreCase))
            {
                OldHash = PackageHash;

                // Reset the flag so that we no longer need to download the package since it exists and is valid.
                refreshPackage = false;

                // Make a note that we the backing store for the ZipPackage is the machine cache.
                _usingMachineCache = true;
            }

            if (refreshPackage)
            {
                // We either do not have a package available locally or they are invalid. Download the package from the server.
                _package = Downloader.DownloadPackage(DownloadUrl, this);

                // Make a note that we are using an in-memory instance of the package.
                _usingMachineCache = false;

                // Add the package to the cache
                cacheRepository.AddPackage(_package);

                OldHash = PackageHash;

                // Clear any cached items for this package
                ZipPackage.ClearCache(_package);
            }
        }
开发者ID:nickfloyd,项目名称:NuGet,代码行数:40,代码来源:DataServicePackage.cs

示例4: UpdatePackages

        internal void UpdatePackages(IPackageRepository localRepository,
                                     IPackageRepository sourceRepository,
                                     IPackageConstraintProvider constraintProvider,
                                     IPackagePathResolver pathResolver,
                                     IProjectSystem project)
        {
            var projectManager = new ProjectManager(sourceRepository, pathResolver, project, localRepository)
                                 {
                                     ConstraintProvider = constraintProvider
                                 };

            if (Verbose)
            {
                projectManager.Logger = Console;
            }

            foreach (var package in GetPackages(localRepository))
            {
                if (localRepository.Exists(package.Id))
                {
                    try
                    {
                        // If the user explicitly allows prerelease or if the package being updated is prerelease we'll include prerelease versions in our list of packages
                        // being considered for an update.
                        bool allowPrerelease = Prerelease || !package.IsReleaseVersion();
                        if (Safe)
                        {
                            IVersionSpec safeRange = VersionUtility.GetSafeRange(package.Version);
                            projectManager.UpdatePackageReference(package.Id, safeRange, updateDependencies: true, allowPrereleaseVersions: allowPrerelease);
                        }
                        else
                        {
                            projectManager.UpdatePackageReference(package.Id, version: null, updateDependencies: true, allowPrereleaseVersions: allowPrerelease);
                        }
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteWarning(e.Message);
                    }
                }
            }
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:42,代码来源:UpdateCommand.cs

示例5: UpdatePackages

 private void UpdatePackages(IPackageRepository localRepository, Action<IPackage> updateAction, ILogger logger)
 {
     // BUGBUG: TargetFramework should be passed for more efficient package walking
     var packageSorter = new PackageSorter(targetFramework: null);
     // Get the packages in reverse dependency order then run update on each one i.e. if A -> B run Update(A) then Update(B)
     var packages = packageSorter.GetPackagesByDependencyOrder(localRepository).Reverse();
     foreach (var package in packages)
     {
         // While updating we might remove packages that were initially in the list. e.g.
         // A 1.0 -> B 2.0, A 2.0 -> [], since updating to A 2.0 removes B, we end up skipping it.
         if (localRepository.Exists(package.Id))
         {
             try
             {
                 updateAction(package);
             }
             catch (PackageNotInstalledException e)
             {
                 logger.Log(MessageLevel.Warning, ExceptionUtility.Unwrap(e).Message);
             }
             catch (Exception e)
             {
                 logger.Log(MessageLevel.Error, ExceptionUtility.Unwrap(e).Message);
             }
         }
     }
 }
开发者ID:Mailaender,项目名称:xamarin-nuget,代码行数:27,代码来源:VSPackageManager.cs

示例6: UpdatePackages

        internal void UpdatePackages(IPackageRepository localRepository,
                                     IFileSystem sharedRepositoryFileSystem,
                                     ISharedPackageRepository sharedPackageRepository,
                                     IPackageRepository sourceRepository,
                                     IPackageConstraintProvider constraintProvider,
                                     IPackagePathResolver pathResolver,
                                     IProjectSystem project)
        {
            var packageManager = new PackageManager(sourceRepository, pathResolver, sharedRepositoryFileSystem, sharedPackageRepository);

            var projectManager = new ProjectManager(sourceRepository, pathResolver, project, localRepository)
                                 {
                                     ConstraintProvider = constraintProvider
                                 };

            // Fix for work item 2411: When updating packages, we did not add packages to the shared package repository. 
            // Consequently, when querying the package reference repository, we would have package references with no backing package files in
            // the shared repository. This would cause the reference repository to skip the package assuming that the entry is invalid.
            projectManager.PackageReferenceAdded += (sender, eventArgs) =>
            {
                PackageExtractor.InstallPackage(packageManager, eventArgs.Package);
            };

            projectManager.Logger = project.Logger = this;

            using (sourceRepository.StartOperation(RepositoryOperationNames.Update))
            {
                foreach (var package in GetPackages(localRepository))
                {
                    if (localRepository.Exists(package.Id))
                    {
                        try
                        {
                            // If the user explicitly allows prerelease or if the package being updated is prerelease we'll include prerelease versions in our list of packages
                            // being considered for an update.
                            bool allowPrerelease = Prerelease || !package.IsReleaseVersion();
                            if (Safe)
                            {
                                IVersionSpec safeRange = VersionUtility.GetSafeRange(package.Version);
                                projectManager.UpdatePackageReference(package.Id, safeRange, updateDependencies: true, allowPrereleaseVersions: allowPrerelease);
                            }
                            else
                            {
                                projectManager.UpdatePackageReference(package.Id, version: null, updateDependencies: true, allowPrereleaseVersions: allowPrerelease);
                            }
                        }
                        catch (InvalidOperationException e)
                        {
                            Console.WriteWarning(e.Message);
                        }
                    }
                }
            }
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:54,代码来源:UpdateCommand.cs

示例7: GetReferences

        internal IEnumerable<PackageDependency> GetReferences(IPackageRepository localRepository,
                                     IFileSystem sharedRepositoryFileSystem,
                                     ISharedPackageRepository sharedPackageRepository,
                                     IPackageRepository sourceRepository,
                                     IPackageConstraintProvider constraintProvider,
                                     IPackagePathResolver pathResolver,
                                     IProjectSystem project)
        {
            var packageManager = new PackageManager(sourceRepository, pathResolver, sharedRepositoryFileSystem, sharedPackageRepository);

            var projectManager = new ProjectManager(sourceRepository, pathResolver, project, localRepository)
            {
                ConstraintProvider = constraintProvider
            };

            // Fix for work item 2411: When updating packages, we did not add packages to the shared package repository. 
            // Consequently, when querying the package reference repository, we would have package references with no backing package files in
            // the shared repository. This would cause the reference repository to skip the package assuming that the entry is invalid.
            projectManager.PackageReferenceAdded += (sender, eventArgs) =>
            {
                PackageExtractor.InstallPackage(packageManager, eventArgs.Package);
            };

            projectManager.Logger = project.Logger = new NugetUpdateTask.VerboseLogger(this);

            using (sourceRepository.StartOperation(RepositoryOperationNames.Update))
            {
                foreach (var package in GetPackages(localRepository))
                {
                    if (localRepository.Exists(package.Id))
                    {
                        if (projectManager.IsInstalled(package))
                        {
                            Log(Level.Debug, "Found installed package {0} version {1}", package.Id, package.Version);
                            yield return new PackageDependency(package.Id, new VersionSpec(package.Version));
                        }
                    }
                }
            }
        }
开发者ID:Alxandr,项目名称:NAnt.Nuget.Tasks,代码行数:40,代码来源:NugetGetDependenciesTask.cs

示例8: UpdatePackages

        internal void UpdatePackages(IPackageRepository localRepository,
                                     IProjectManager projectManager)
        {
            foreach (var package in GetPackages(localRepository))
            {
                if (localRepository.Exists(package.Id))
                {
                    try
                    {
                        // If the user explicitly allows prerelease or if the package being updated is prerelease we'll include prerelease versions in our list of packages
                        // being considered for an update.
                        bool allowPrerelease = Prerelease || !package.IsReleaseVersion();
                        
                        PackageUpdateMode updateMode = PackageUpdateMode.Newest;

                        if (Safe)
                        {
                            updateMode = PackageUpdateMode.Safe;
                        }
                        else if (Minor)
                        {
                            updateMode = PackageUpdateMode.Minor;
                        }

                        var spec = VersionUtility.GetUpgradeVersionSpec(package.Version, updateMode);
                        projectManager.UpdatePackageReference(package.Id, spec, updateDependencies: true, allowPrereleaseVersions: allowPrerelease);
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteWarning(e.Message);
                    }
                }
            }
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:34,代码来源:UpdateCommand.cs


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