Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        public async Task <PackageOperationResult> InstallPackage(
            string id,
            string version = null,
            Uri source     = null,
            bool force     = false)
        {
            using (await Lock.WriteLockAsync())
            {
                var logger = new SerilogLogger(Logger, _progressService);
                var choco  = Lets.GetChocolatey().SetCustomLogging(logger);
                choco.Set(
                    config =>
                {
                    config.CommandName  = CommandNameType.install.ToString();
                    config.PackageNames = id;
                    config.Features.UsePackageExitCodes = false;

                    if (version != null)
                    {
                        config.Version = version.ToString();
                    }

                    if (source != null)
                    {
                        config.Sources = source.ToString();
                    }

                    if (force)
                    {
                        config.Force = true;
                    }
                });

                Action <LogMessage> grabErrors;
                var errors = GetErrors(out grabErrors);

                using (logger.Intercept(grabErrors))
                {
                    await choco.RunAsync();

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

                    return(PackageOperationResult.SuccessfulCached);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <PackageOperationResult> InstallPackage(
            string id,
            string version = null,
            Uri source     = null,
            bool force     = false,
            AdvancedInstall advancedInstallOptions = null)
        {
            using (await Lock.WriteLockAsync())
            {
                var logger = new SerilogLogger(Logger, _progressService);
                var choco  = Lets.GetChocolatey(initializeLogging: false).SetCustomLogging(logger, logExistingMessages: false, addToExistingLoggers: true);
                choco.Set(
                    config =>
                {
                    config.CommandName  = CommandNameType.install.ToString();
                    config.PackageNames = id;
                    config.Features.UsePackageExitCodes = false;

                    if (version != null)
                    {
                        config.Version = version.ToString();
                    }

                    if (source != null)
                    {
                        config.Sources = source.ToString();
                    }

                    if (force)
                    {
                        config.Force = true;
                    }

                    if (advancedInstallOptions != null)
                    {
                        config.InstallArguments  = advancedInstallOptions.InstallArguments;
                        config.PackageParameters = advancedInstallOptions.PackageParameters;
                        config.CommandExecutionTimeoutSeconds = advancedInstallOptions.ExecutionTimeoutInSeconds;

                        if (!string.IsNullOrEmpty(advancedInstallOptions.LogFile))
                        {
                            config.AdditionalLogFileLocation = advancedInstallOptions.LogFile;
                        }

                        config.Prerelease        = advancedInstallOptions.PreRelease;
                        config.ForceX86          = advancedInstallOptions.Forcex86;
                        config.OverrideArguments = advancedInstallOptions.OverrideArguments;
                        config.NotSilent         = advancedInstallOptions.NotSilent;
                        config.ApplyInstallArgumentsToDependencies  = advancedInstallOptions.ApplyInstallArgumentsToDependencies;
                        config.ApplyPackageParametersToDependencies = advancedInstallOptions.ApplyPackageParametersToDependencies;
                        config.AllowDowngrade                     = advancedInstallOptions.AllowDowngrade;
                        config.AllowMultipleVersions              = advancedInstallOptions.AllowMultipleVersions;
                        config.IgnoreDependencies                 = advancedInstallOptions.IgnoreDependencies;
                        config.ForceDependencies                  = advancedInstallOptions.ForceDependencies;
                        config.SkipPackageInstallProvider         = advancedInstallOptions.SkipPowerShell;
                        config.Features.ChecksumFiles             = !advancedInstallOptions.IgnoreChecksums;
                        config.Features.AllowEmptyChecksums       = advancedInstallOptions.AllowEmptyChecksums;
                        config.Features.AllowEmptyChecksumsSecure = advancedInstallOptions.AllowEmptyChecksumsSecure;

                        if (advancedInstallOptions.RequireChecksums)
                        {
                            config.Features.AllowEmptyChecksums       = false;
                            config.Features.AllowEmptyChecksumsSecure = false;
                        }

                        if (!string.IsNullOrEmpty(advancedInstallOptions.CacheLocation))
                        {
                            config.CacheLocation = advancedInstallOptions.CacheLocation;
                        }

                        config.DownloadChecksum       = advancedInstallOptions.DownloadChecksum;
                        config.DownloadChecksum64     = advancedInstallOptions.DownloadChecksum64bit;
                        config.DownloadChecksumType   = advancedInstallOptions.DownloadChecksumType;
                        config.DownloadChecksumType64 = advancedInstallOptions.DownloadChecksumType64bit;
                    }
                });

                Action <LogMessage> grabErrors;
                var errors = GetErrors(out grabErrors);

                using (logger.Intercept(grabErrors))
                {
                    await choco.RunAsync();

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

                    return(PackageOperationResult.SuccessfulCached);
                }
            }
        }