public async Task <byte[]> WaitAsync(int count, WaitMode mode, AsyncOperationInfo operationInfo) { throwIfDisposed(); _responseReadTimeout.ThrowIfTimeout(); operationInfo.CancellationToken.ThrowIfCancellationRequested(); byte[] waitResult = null; try { using (_waitTimeout.RestartMode) { switch (mode) { case WaitMode.EXACT: var buffer = new List <byte>(count); while (buffer.Count != count) { _responseReadTimeout.ThrowIfTimeout(); var result = await _pipe.ReadAsync(new PipeReadParameters(count - buffer.Count), _cancellation); if (result.Status.IsOneOf(IOBase.ReadStatus.DONE, IOBase.ReadStatus.PATIALLY_DONE)) { buffer.AddRange(result.Data); } else { throw new NotSupportedException(); } } waitResult = buffer.ToArray(); break; case WaitMode.NO_MORE_THAN: { var result = await _pipe.ReadAsync(new PipeReadParameters(count), _cancellation); if (result.Status.IsOneOf(IOBase.ReadStatus.DONE, IOBase.ReadStatus.PATIALLY_DONE)) { waitResult = result.Data.ToArray(); } else { throw new NotSupportedException(); } } break; default: throw new NotSupportedException(); } } return(waitResult); } finally { await Logger.LogResponseAsync(waitResult ?? new byte[0], count); } }
public async Task HandleInputAsync() { var data = await _inputPipe.ReadAsync(_processService.CancellationToken); if (data.DataType == DataType.InputData) { _kernel32Api.WriteConsoleInput(((InputData)data).InputRecord); } else if (data.DataType == DataType.ResizeCommand) { ResizeTerminal((ResizeCommand)data); } else if (data.DataType == DataType.CloseCommand) { _processService.CloseTerminal(); } }