Ejemplo n.º 1
0
 public Task ForwardVisualStudioDataToMonoAsync(byte[] debuggerData, uint userData, CancellationToken cancellationToken = default)
 {
     return(_meadowDevice.ForwardVisualStudioDataToMonoAsync(
                debuggerData,
                userData,
                cancellationToken));
 }
Ejemplo n.º 2
0
            private async Task SendToMeadowAsync()
            {
                try
                {
                    using var md5 = MD5.Create();
                    // Receive from Visual Studio and send to Meadow
                    var receiveBuffer = ArrayPool <byte> .Shared.Rent(490);

                    var meadowBuffer = Array.Empty <byte>();
                    while (!_cts.IsCancellationRequested)
                    {
                        if (_networkStream != null && _networkStream.CanRead)
                        {
                            int bytesRead;
                            do
                            {
                                bytesRead = await _networkStream.ReadAsync(receiveBuffer, 0, receiveBuffer.Length, _cts.Token);

                                if (bytesRead == 0 || _cts.IsCancellationRequested)
                                {
                                    continue;
                                }

                                var destIndex = meadowBuffer.Length;
                                Array.Resize(ref meadowBuffer, destIndex + bytesRead);
                                Array.Copy(receiveBuffer, 0, meadowBuffer, destIndex, bytesRead);

                                // Ensure we read all the data in this message before passing it along
                                // I'm not sure this is actually needed, the whole message should get read at once.
                            } while (_networkStream.DataAvailable);

                            // Forward to Meadow
                            _logger.LogTrace("Received {count} bytes from VS will forward to HCOM. {hash}",
                                             meadowBuffer.Length,
                                             BitConverter.ToString(md5.ComputeHash(meadowBuffer))
                                             .Replace("-", string.Empty)
                                             .ToLowerInvariant());
                            await _meadow.ForwardVisualStudioDataToMonoAsync(meadowBuffer, 0).ConfigureAwait(false);

                            meadowBuffer = Array.Empty <byte>();
                        }
                        else
                        {
                            // User probably hit stop
                            _logger.LogInformation("Unable to Read Data from Visual Studio");
                            _logger.LogTrace("Unable to Read Data from Visual Studio");
                        }
                    }
                }
                catch (IOException ioe)
                {
                    // VS client probably died
                    _logger.LogInformation("Visual Studio has Disconnected");
                    _logger.LogTrace(ioe, "Visual Studio has Disconnected");
                }
                catch (ObjectDisposedException ode)
                {
                    // User probably hit stop
                    _logger.LogInformation("Visual Studio has stopped debugging");
                    _logger.LogTrace(ode, "Visual Studio has stopped debugging");
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Error receiving data from Visual Studio");
                    throw;
                }
            }