コード例 #1
0
        Command NotebookParser()
        {
            var notebookParserCommand = new Command(
                "notebook-parser",
                "Starts a process to parse and serialize notebooks.");

            notebookParserCommand.Handler = CommandHandler.Create(async() =>
            {
                Console.InputEncoding    = Encoding.UTF8;
                Console.OutputEncoding   = Encoding.UTF8;
                var notebookParserServer = new NotebookParserServer(Console.In, Console.Out);
                await startNotebookParser(notebookParserServer);
            });
            return(notebookParserCommand);
        }
        private static async IAsyncEnumerable <NotebookParserServerResponse> GetResponseObjectsEnumerable(string inputText)
        {
            using var input = new StringReader(inputText);
            var stream       = new SimplexStream();
            var output       = new StreamWriter(stream);
            var server       = new NotebookParserServer(input, output);
            var _            = Task.Run(() => server.RunAsync()); // start server listener in the background
            var outputReader = new StreamReader(stream);

            while (true)
            {
                var responseText = await outputReader.ReadLineAsync();

                var responseObject = NotebookParserServerResponse.FromJson(responseText);
                yield return(responseObject);
            }
        }
コード例 #3
0
        public void Notebook_parser_server_returns_an_error_on_unsupported_document_type()
        {
            var request = new NotebookParseRequest(
                "the-id",
                serializationType: (DocumentSerializationType)42,
                defaultLanguage: "csharp",
                rawData: Array.Empty <byte>());
            var response = NotebookParserServer.HandleRequest(request);

            response
            .Should()
            .BeOfType <NotebookErrorResponse>()
            .Which
            .ErrorMessage
            .Should()
            .Contain($"Unable to parse an interactive document with type '{(int)request.SerializationType}'");
        }
コード例 #4
0
        public void Notebook_parser_server_can_parse_file_based_on_document_type(DocumentSerializationType serializationType, string contents)
        {
            var request = new NotebookParseRequest(
                "the-id",
                serializationType,
                defaultLanguage: "csharp",
                rawData: Encoding.UTF8.GetBytes(contents));
            var response = NotebookParserServer.HandleRequest(request);

            response
            .Should()
            .BeOfType <NotebookParseResponse>()
            .Which
            .Document
            .Elements
            .Should()
            .ContainSingle()
            .Which
            .Contents
            .Should()
            .Be("var x = 1;");
        }
コード例 #5
0
        public void Notebook_parser_server_can_serialize_file_based_on_document_type(DocumentSerializationType serializationType, string expected)
        {
            var request = new NotebookSerializeRequest(
                "the-id",
                serializationType,
                defaultLanguage: "csharp",
                newLine: "\n",
                document: new InteractiveDocument(new List <InteractiveDocumentElement>()
            {
                new InteractiveDocumentElement("csharp", "var x = 1;")
            })
                );
            var response = NotebookParserServer.HandleRequest(request);

            response
            .Should()
            .BeOfType <NotebookSerializeResponse>()
            .Which
            .RawData
            .AsUtf8String()
            .Should()
            .Contain(expected);
        }
コード例 #6
0
 public static Task Do(NotebookParserServer parserServer)
 {
     return(parserServer.RunAsync());
 }