Example #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());
            }
        }
        /// <summary>
        /// This is called when the user is adding (or updating) a package source
        /// </summary>
        /// <param name="name">The name of the package source. If this parameter is null or empty the PROVIDER should use the location as the name (if the PROVIDER actually stores names of package sources)</param>
        /// <param name="location">The location (ie, directory, URL, etc) of the package source. If this is null or empty, the PROVIDER should use the name as the location (if valid)</param>
        /// <param name="trusted">A boolean indicating that the user trusts this package source. Packages returned from this source should be marked as 'trusted'</param>
        /// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
        public void AddPackageSource(string name, string location, bool trusted, Request request)
        {
            // TODO: Make chocolatey store "trusted" property on the sources
            request.Debug("Entering {0} source add -n={1} -s'{2}' (we don't support trusted = '{3}')", PackageProviderName, name,
                          location, trusted);

            _chocolatey.Set(conf =>
            {
                conf.CommandName           = "Source";
                conf.SourceCommand.Command = SourceCommandType.add;
                conf.SourceCommand.Name    = name;
                conf.Sources = location;
                conf.AllowUnofficialBuild = true;
            }).Run();
        }
Example #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; }));
        }