protected override async Task <int> DoExecuteAsync(ITaskContextInternal context) { DoLogInfo($"Connecting to host {_userName}@{_host}"); string password = _password.GetPassword(); using (SshClient client = new SshClient(_host, _userName, password)) { client.Connect(); StringBuilder cmdText = new StringBuilder(); foreach (string command in _commands) { DoLogInfo($"Executing command {command}"); cmdText.Append($"{command} &&"); } cmdText.Remove(cmdText.Length - 2, 2); using (SshCommand cmd = client.CreateCommand(cmdText.ToString())) { Task <string> task = Task.Factory.FromAsync <string, string>((p, c, st) => cmd.BeginExecute(p, c, st), cmd.EndExecute, cmdText.ToString(), null); using (StreamReader reader = new StreamReader(cmd.OutputStream)) { while (true) { if (task.Wait(1000)) { DoLogInfo($"Command response [{task.Result ?? cmd.Error}]"); break; } string data = await reader.ReadToEndAsync(); if (!string.IsNullOrEmpty(data)) { DoLogInfo(data); } } if (!string.IsNullOrEmpty(cmd.Error)) { context.LogError(cmd.Error); } } } client.Disconnect(); return(0); } }
protected override int DoExecute(ITaskContextInternal context) { var findPackageTask = new FindNuGetPackageInUserRepositoryTask(_packageId); findPackageTask.Execute(context); if (findPackageTask.PackageVersion != null && _packageVersion != null && findPackageTask.PackageVersion > _packageVersion) { PackageDirectory = findPackageTask.PackageDirectory; return(0); } if (findPackageTask.PackageDirectory != null) { PackageDirectory = findPackageTask.PackageDirectory; return(0); } var task = new NuGetCmdLineTask("install") .WithArguments(_packageId) .WithArguments($"-Source {PackageSource}") .WithArguments("-NonInteractive") .WithArguments($"-OutputDirectory {NuGetPackagesCacheDir}"); if (_packageVersion != null) { task.WithArguments($"-Version {_packageVersion}"); } if (ConfigFile != null) { task.WithArguments($"-ConfigFile {ConfigFile}"); } if (Verbosity.HasValue) { task.Verbosity = Verbosity.Value; } task.Execute(context); findPackageTask.Execute(context); PackageDirectory = findPackageTask.PackageDirectory; context.LogError( PackageDirectory == null ? $"Something is wrong, after downloading it the NuGet package '{_packageId}' still could not be found." : "Package downloaded to '{packageDirectory}'"); return(0); }