internal static int AppMain(Arguments arguments, IOStreams streams) { if (!arguments.IsSet(PasswordSwitch)) { throw new CmdLineException("ERROR: No vault password specified [--password]"); } string password = arguments.Value(PasswordSwitch); var ciphertext = new List <string>(); if (!arguments.IsSet(InFileSwitch)) { string input; while ((input = streams.StdIn.ReadLine()) != null) { ciphertext.Add(input); } } else { var inputFile = arguments.Value(InFileSwitch); ciphertext = File.ReadAllLines(inputFile) .ToList(); } var plaintext = Decrypter.Decypt(ciphertext, password); if (!arguments.IsSet(OutFileSwitch)) { streams.StdOut.Write(plaintext); } else { var outputFile = arguments.Value(OutFileSwitch); File.WriteAllText(outputFile, plaintext, Encoding.ASCII); } return(ExitCode.Success); }
public async Task Kernel_can_be_interacted_using_kernel_client() { await _kernelClient.Start(); var gate = _io.OutputStream .TakeUntilCommandHandled(); _io.WriteToInput(new SubmitCode(@"var x = 123;"), 0); await gate; var events = _events .Select(e => e.ToString(Formatting.None)); var expectedEvents = new List <string> { IOStreams.ToStreamKernelEvent(new CommandHandled(new SubmitCode(@"var x = 123;")), 0).Serialize(), }; events.Should() .ContainInOrder(expectedEvents); }
public async Task Kernel_can_be_interacted_using_kernel_client() { await _kernelClient.Start(); _io.WriteToInput(new SubmitCode(@"var x = 123;"), 0); var events = _events .Where(e => e["eventType"].Value <string>() == nameof(CommandHandled)) .Take(1) .Timeout(20.Seconds()) .Select(e => e.ToString(Formatting.None)) .ToEnumerable() .ToList(); var expectedEvents = new List <string> { IOStreams.ToStreamKernelEvent(new CommandHandled(new SubmitCode(@"var x = 123;")), 0).Serialize(), }; events.Should() .ContainInOrder(expectedEvents); }
public KernelClientTests(ITestOutputHelper output) { _output = output; var displayIdSeed = 0; _configuration = new Configuration() .UsingExtension("json"); _configuration = _configuration.SetInteractive(Debugger.IsAttached); Microsoft.DotNet.Interactive.Kernel.DisplayIdGenerator = () => Interlocked.Increment(ref displayIdSeed).ToString(); var kernel = new CompositeKernel { new CSharpKernel() .UseKernelHelpers() .UseNugetDirective() .UseDefaultRendering() }; _io = new IOStreams(); _kernelClient = new KernelStreamClient( kernel, _io, _io); _events = _io.OutputStream .Where(s => !string.IsNullOrWhiteSpace(s)) .Select(JObject.Parse) .ToSubscribedList(); _disposables.Add(_kernelClient); _disposables.Add(_output.SubscribeToPocketLogger()); _disposables.Add(kernel.LogEventsToPocketLogger()); _disposables.Add(kernel); _disposables.Add(() => Microsoft.DotNet.Interactive.Kernel.DisplayIdGenerator = null); }
public void Dispose() { IOStreams.SafelyDispose(InputStream, OutputStream); }
private void DisposeStreamAndCloseConnection(string message) { IOStreams.SafelyDispose(_currentOutputStream); _currentOutputStream = null; CloseConnection(e => Log.Debug(message + "\nException: {e}", e.Message)); }
internal static int AppMain(string[] args, IOStreams streams) { var parser = new CommandLineParser(args, Switches); return(Bootstrapper.Run(AppMain, parser, streams)); }