public static IAsyncEnumerable <TestCaseResult> TasteProcess( Uri connectionString, string command, string arguments = "", string?workingDirectory = null, string?windowsName = null, string?windowsArgs = null, Action <IDictionary <string, string> >?configureEnvironment = null, Action <TastyProcessCommander>?configureCommander = null) { using var commander = new TastyProcessCommander( connectionString, new Func <ProcessStartInfo>(() => ProcessStartInfoHelper.Create( command, arguments, workingDirectory, windowsName: windowsName, windowsArgs: windowsArgs, configureEnvironment: configureEnvironment ))); configureCommander?.Invoke(commander); return(commander.Run()); }
public string ConvertToMobi(string filePath, CancellationToken cancellationToken) { var generateMobiArguments = string.Concat(kindlegenPath, " '", filePath, "'"); using (var process = ProcessStartInfoHelper.Create(generateMobiArguments, cancellationToken)) { process.Start(); process.WaitForExit(); if (process.ExitCode != 0 && process.ExitCode != 1) { throw new Exception("No se pudo generar el archivo .mobi"); } } return(Directory.GetFiles(Path.GetDirectoryName(filePath)).First(f => Path.GetExtension(f) == ".mobi")); }
public string DownloadMagnetLink(MagnetLink magnetLink, CancellationToken cancellationToken) { var downloadMagnetLinkArguments = string.Concat(aria2cPath, " --dir='", magnetLink.DownloadDirectory, "' '", magnetLink.Link, "' --seed-time=0"); using (var process = ProcessStartInfoHelper.Create(downloadMagnetLinkArguments, cancellationToken)) { process.Start(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception("No se pudo descargar el archivo"); } } return(Directory.GetFiles(magnetLink.DownloadDirectory)[0]); }
public static async Task <int> Interactive(string project, CancellationToken cancellationToken) { try { var path = Path.GetFullPath(project); if (!string.IsNullOrEmpty(path) && Directory.Exists(path)) { var directoryName = new DirectoryInfo(path).Name; var csProjFileName = Path.Combine(path, $"{directoryName}.csproj"); if (File.Exists(csProjFileName)) { var connectionString = NamedPipesConnectionStringBuilder.CreateNewConnection(); Console.WriteLine(csProjFileName); var progress = new Progress <(string line, bool isError, int?exitCode)>(p => { Console.WriteLine(p.line); }); var commander = new TastyProcessCommander(connectionString, new Func <ProcessStartInfo>(() => ProcessStartInfoHelper.Create("dotnet", $"run --no-build --no-restore -c Debug -f netcoreapp3.1 --project {csProjFileName}", configureEnvironment: env => { env[EnvironmentVariables.InteractiveMode] = "true"; })), progress); commander.UseNamedPipesTransport() .RegisterReporter(ConsoleReporter.Report) .RegisterReporter(ConsoleReporter.ReportSummary); Console.WriteLine("Connecting to remote"); var remoteTask = await commander.ConnectAsync(cancellationToken).ConfigureAwait(true); Console.WriteLine("Connected to remote"); try { var uiTask = Task.Run(async() => { var commands = await commander.ListCommands(cancellationToken).ConfigureAwait(false); await Task.Run(async() => await WaitForInput(commands, commander).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); Console.WriteLine("UI-Task ended"); }, cancellationToken); await Task.WhenAll(remoteTask, uiTask).ConfigureAwait(false); } catch (TaskCanceledException) { return(0); } catch (SimpleExec.NonZeroExitCodeException e) { return(e.ExitCode); } finally { commander.Dispose(); } } } return(0); } catch (TaskCanceledException) { return(1); } }