// Called on the VsLinkServer thread - should not block public static void VsLinkMessageHandler(VsLinkMessage message) { var registerXllMessage = message as RegisterAddInMessage; if (registerXllMessage != null) { if (registerXllMessage.AddInPath.EndsWith(".xll")) { ExcelAsyncUtil.QueueAsMacro(() => ExcelIntegration.RegisterXLL(registerXllMessage.AddInPath)); } else if (registerXllMessage.AddInPath.EndsWith(".dll")) { ExcelAsyncUtil.QueueAsMacro(() => AddInLoader.RegisterDll(registerXllMessage.AddInPath)); } } }
// TODO: Timeout and CancellationToken // TODO: Receive all messages / blocking receive? public async Task <VsLinkMessage> ReceiveMessageAsync() { var messageBytes = new List <byte>(); do { var numBytes = await PipeStream.ReadAsync(_buffer, 0, _buffer.Length /*, cancellationToken*/); if (numBytes == 0) { // End-of-stream (pipe closed?) if (messageBytes.Count > 0) { throw new InvalidOperationException("Pipe closed while transmitting message"); } return(null); } // normal case - add to the message bytes messageBytes.AddRange(_buffer.Take(numBytes)); }while (!PipeStream.IsMessageComplete); return(VsLinkMessage.FromBytes(messageBytes.ToArray())); }
public Task SendMessageAsync(VsLinkMessage message) { byte[] messageBytes = message.ToBytes(); return(PipeStream.WriteAsync(messageBytes, 0, messageBytes.Length)); }
public Task SendMessageAsync(VsLinkMessage message) { byte[] messageBytes = message.ToBytes(); return PipeStream.WriteAsync(messageBytes, 0, messageBytes.Length); }