public async Task <PackageOperationResult> PinPackage(string id, string version) { using (await Lock.WriteLockAsync()) { _choco.Set( config => { config.CommandName = "pin"; config.PinCommand.Command = PinCommandType.add; config.PinCommand.Name = id; config.Version = version; }); try { await _choco.RunAsync(); } catch (Exception ex) { return(new PackageOperationResult { Successful = false, Exception = ex }); } return(PackageOperationResult.SuccessfulCached); } }
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); } }