Example #1
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);
        }
Example #2
0
        private async Task <PackageOperationResult> RunCommand(GetChocolatey choco, SerilogLogger logger)
        {
            Action <LogMessage> grabErrors;
            var errors = GetErrors(out grabErrors);

            using (logger.Intercept(grabErrors))
            {
                try
                {
                    await choco.RunAsync();
                }
                catch (Exception ex)
                {
                    return(new PackageOperationResult {
                        Successful = false, Messages = errors.ToArray(), Exception = ex
                    });
                }

                if (Environment.ExitCode != 0)
                {
                    Environment.ExitCode = 0;
                    return(new PackageOperationResult {
                        Successful = false, Messages = errors.ToArray()
                    });
                }

                return(PackageOperationResult.SuccessfulCached);
            }
        }
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; }));
        }
Example #4
0
#pragma warning disable SA1401 // Fields must be private
#pragma warning restore SA1401 // Fields must be private

        public ChocolateyService(IMapper mapper, IProgressService progressService, IChocolateyConfigSettingsService configSettingsService, IXmlService xmlService, IFileSystem fileSystem, IConfigService configService)
        {
            _mapper                = mapper;
            _progressService       = progressService;
            _configSettingsService = configSettingsService;
            _xmlService            = xmlService;
            _fileSystem            = fileSystem;
            _configService         = configService;
            _choco = Lets.GetChocolatey().SetCustomLogging(new SerilogLogger(Logger, _progressService));

            _localAppDataPath = _fileSystem.combine_paths(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), "Chocolatey GUI");
        }
        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);
        }
 /// <summary>
 /// Performs one-time initialization of the $provider.
 /// </summary>
 /// <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 InitializeProvider(Request request)
 {
     request.Debug("Entering '{0}::InitializeProvider' to set up a chocolatey with custom logging", PackageProviderName);
     _chocolatey = Lets.GetChocolatey().SetCustomLogging(new RequestLogger(request));
 }
Example #7
0
 public static Task <ICollection <PackageResult> > ListPackagesAsync(this GetChocolatey chocolatey)
 {
     return(Task.Run(() => (ICollection <PackageResult>)chocolatey.List <PackageResult>().ToList()));
 }
Example #8
0
 public static Task <ICollection <T> > ListAsync <T>(this GetChocolatey chocolatey)
 {
     return(Task.Run(() => (ICollection <T>)chocolatey.List <T>().ToList()));
 }
Example #9
0
 public static Task RunAsync(this GetChocolatey chocolatey)
 {
     return(Task.Run(() => chocolatey.Run()));
 }
 /// <summary>
 /// Performs one-time initialization of the $provider.
 /// </summary>
 /// <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 InitializeProvider(Request request)
 {
     request.Debug("Entering '{0}::InitializeProvider' to set up a chocolatey with custom logging", PackageProviderName);
     _chocolatey = Lets.GetChocolatey().SetCustomLogging(new RequestLogger(request));
 }
Example #11
0
 public override void Because()
 {
     _chocolatey1 = Lets.GetChocolatey();
     _chocolatey2 = Lets.GetChocolatey();
 }
Example #12
0
 public override void Because()
 {
     _chocolatey1 = Lets.GetChocolatey();
     _chocolatey2 = Lets.GetChocolatey();
 }