示例#1
0
        public async Task <IEnumerable <Package> > GetInstalledPackages()
        {
            _choco.Set(
                config =>
            {
                config.CommandName           = CommandNameType.list.ToString();
                config.ListCommand.LocalOnly = true;
            });

            var chocoConfig = _choco.GetConfiguration();

            // Not entirely sure what is going on here.  When there are no sources defined, for example, when they
            // are all disabled, the ListAsync command isn't returning any packages installed locally.  When in this
            // situation, use the nugetService directly to get the list of installed packages.
            if (chocoConfig.Sources != null)
            {
                var packages = await _choco.ListAsync <PackageResult>();

                return(packages
                       .Select(package => GetMappedPackage(_choco, package, _mapper, true))
                       .ToArray());
            }
            else
            {
                var nugetService = _choco.Container().GetInstance <INugetService>();
                var packages     = await Task.Run(() => nugetService.list_run(chocoConfig));

                return(packages
                       .Select(package => GetMappedPackage(_choco, package, _mapper, true))
                       .ToArray());
            }
        }
示例#2
0
        private static Package GetMappedPackage(GetChocolatey choco, PackageResult package, IMapper mapper, bool forceInstalled = false)
        {
            var mappedPackage = package == null ? null : mapper.Map <Package>(package.Package);

            if (mappedPackage != null)
            {
                var packageInfoService = choco.Container().GetInstance <IChocolateyPackageInformationService>();
                var packageInfo        = packageInfoService.get_package_information(package.Package);
                mappedPackage.IsPinned     = packageInfo.IsPinned;
                mappedPackage.IsInstalled  = !string.IsNullOrWhiteSpace(package.InstallLocation) || forceInstalled;
                mappedPackage.IsSideBySide = packageInfo.IsSideBySide;

                mappedPackage.IsPrerelease = !string.IsNullOrWhiteSpace(mappedPackage.Version.SpecialVersion);

                // Add a sanity check here for pre-release packages
                // By default, pre-release packages are marked as IsLatestVersion = false, however, IsLatestVersion is
                // what is used to show/hide the Out of Date message in the UI.  In these cases, if it is a pre-release
                // mark IsLatestVersion as true, and then the outcome of the call to choco outdated will correct whether
                // it is actually Out of Date or not
                if (mappedPackage.IsPrerelease && mappedPackage.IsAbsoluteLatestVersion && !mappedPackage.IsLatestVersion)
                {
                    mappedPackage.IsLatestVersion = true;
                }
            }

            return(mappedPackage);
        }
示例#3
0
        // This can take a while with many packages
        private static int GetOutdatedCount()
        {
            GetChocolatey chocolatey = Lets.GetChocolatey();

            chocolatey.SetCustomLogging(new chocolatey.infrastructure.logging.NullLog());
            chocolatey.Set(c => { c.CommandName = "outdated"; c.PackageNames = ApplicationParameters.AllPackages; });
            INugetService nuget = chocolatey.Container().GetInstance <INugetService>();

            ConcurrentDictionary <string, PackageResult> upgradeResults = nuget.upgrade_noop(chocolatey.GetConfiguration(), null);

            return(upgradeResults.Values.Count((v) => { return !v.Inconclusive; }));
        }
        private static Package GetMappedPackage(GetChocolatey choco, PackageResult package, IMapper mapper, bool forceInstalled = false)
        {
            var mappedPackage = package == null ? null : mapper.Map <Package>(package.Package);

            if (mappedPackage != null)
            {
                var packageInfoService = choco.Container().GetInstance <IChocolateyPackageInformationService>();
                var packageInfo        = packageInfoService.get_package_information(package.Package);
                mappedPackage.IsPinned     = packageInfo.IsPinned;
                mappedPackage.IsInstalled  = !string.IsNullOrWhiteSpace(package.InstallLocation) || forceInstalled;
                mappedPackage.IsSideBySide = packageInfo.IsSideBySide;
            }

            return(mappedPackage);
        }