Exemple #1
0
        public Task SendEventAsync <TParams, TRegistrationOptions>(
            NotificationType <TParams, TRegistrationOptions> eventType,
            TParams eventParams)
        {
            OutputEventBody outputEvent = eventParams as OutputEventBody;

            if (outputEvent != null)
            {
                this.OutputEvents.Add(outputEvent);
            }

            return(Task.FromResult(true));
        }
Exemple #2
0
        public Task SendEvent <TParams>(
            EventType <TParams> eventType,
            TParams eventParams)
        {
            OutputEventBody outputEvent = eventParams as OutputEventBody;

            if (outputEvent != null)
            {
                this.OutputEvents.Add(outputEvent);
            }

            return(Task.FromResult(true));
        }
Exemple #3
0
        public async Task ServiceExecutesReplCommandAndReceivesOutput()
        {
            await this.SendRequestWithoutWait(
                EvaluateRequest.Type,
                new EvaluateRequestArguments
            {
                Expression = "1 + 2"
            });

            OutputEventBody outputEvent = this.WaitForEvent(OutputEvent.Type);

            this.WaitForResponse(EvaluateRequest.Type, this.messageId);

            Assert.Equal("3\r\n", outputEvent.Output);
            Assert.Equal("stdout", outputEvent.Category);
        }
Exemple #4
0
        public async Task <string> ReadLine(string expectedOutputCategory = "stdout", bool waitForNewLine = true)
        {
            try
            {
                bool     lineHasNewLine   = false;
                string[] outputLines      = null;
                string   nextOutputString = string.Empty;

                // Wait no longer than 7 seconds for output to come back
                CancellationToken cancellationToken =
                    Debugger.IsAttached
                        ? CancellationToken.None
                        : new CancellationTokenSource(7000).Token;

                // Any lines in the buffer?
                if (this.bufferedOutput.Count > 0)
                {
                    Assert.Equal(expectedOutputCategory, this.currentOutputCategory);

                    // Return the first buffered line
                    var lineTuple = this.bufferedOutput.Dequeue();
                    nextOutputString = lineTuple.Item1;
                    lineHasNewLine   = lineTuple.Item2;
                }

                // Loop until we get a full line of output
                while (!lineHasNewLine)
                {
                    // Execution reaches this point if a buffered line wasn't available
                    Task <OutputEventBody> outputTask =
                        this.outputQueue.DequeueAsync(
                            cancellationToken);
                    OutputEventBody nextOutputEvent = await outputTask;

                    // Verify that the output is of the expected type
                    Assert.Equal(expectedOutputCategory, nextOutputEvent.Category);
                    this.currentOutputCategory = nextOutputEvent.Category;

                    // Split up the output into multiple lines
                    outputLines =
                        nextOutputEvent.Output.Split(
                            new string[] { "\n", "\r\n" },
                            StringSplitOptions.None);

                    // Add the first bit of output to the existing string
                    nextOutputString += outputLines[0];

                    // Have we found a newline now?
                    lineHasNewLine =
                        outputLines.Length > 1 ||
                        nextOutputEvent.Output.EndsWith("\n");

                    // Buffer any remaining lines for future reads
                    if (outputLines.Length > 1)
                    {
                        for (int i = 1; i < outputLines.Length; i++)
                        {
                            this.bufferedOutput.Enqueue(
                                new Tuple <string, bool>(
                                    outputLines[i],

                                    // The line has a newline if it's not the last segment or
                                    // if the last segment is not an empty string and the
                                    // complete output string ends with a newline
                                    i < outputLines.Length - 1 ||
                                    (outputLines[outputLines.Length - 1].Length > 0 &&
                                     nextOutputEvent.Output.EndsWith("\n"))));
                        }
                    }

                    // At this point, the state of lineHasNewLine will determine
                    // whether the loop continues to wait for another output
                    // event that completes the current line.
                    if (!waitForNewLine)
                    {
                        break;
                    }
                }

                return(nextOutputString);
            }
            catch (TaskCanceledException)
            {
                throw new TimeoutException("Timed out waiting for an input line.");
            }
        }
Exemple #5
0
 private async Task OnOutputEvent(OutputEventBody outputEvent, EventContext context)
 {
     await this.outputQueue.EnqueueAsync(outputEvent);
 }
 public OutputEvent(OutputEventBody body)
     : base("output", body)
 {
 }