public override Task SendConnectionAsync(string connectionId, string methodName, object[] args, CancellationToken cancellationToken = default) { if (IsInvalidArgument(connectionId)) { throw new ArgumentException(NullOrEmptyStringErrorMessage, nameof(connectionId)); } if (IsInvalidArgument(methodName)) { throw new ArgumentException(NullOrEmptyStringErrorMessage, nameof(methodName)); } var message = AppendMessageTracingId(new MultiConnectionDataMessage(new[] { connectionId }, SerializeAllProtocols(methodName, args))); if (message.TracingId != null) { MessageLog.StartToSendMessageToConnections(Logger, message); } return(WriteAsync(message)); }
private ServiceMessage CreateMessage(string connectionId, string methodName, object[] args, ClientConnectionContext serviceConnectionContext) { if (serviceConnectionContext.Protocol != null) { var message = new ConnectionDataMessage(connectionId, SerializeProtocol(serviceConnectionContext.Protocol, methodName, args)).WithTracingId(); if (message.TracingId != null) { MessageLog.StartToSendMessageToConnection(Logger, message); } return(message); } else { var message = new MultiConnectionDataMessage(new[] { connectionId }, SerializeAllProtocols(methodName, args)).WithTracingId(); if (message.TracingId != null) { MessageLog.StartToSendMessageToConnections(Logger, message); } return(message); } }
public override async Task SendConnectionAsync(string connectionId, string methodName, object[] args, CancellationToken cancellationToken = default) { if (IsInvalidArgument(connectionId)) { throw new ArgumentException(NullOrEmptyStringErrorMessage, nameof(connectionId)); } if (IsInvalidArgument(methodName)) { throw new ArgumentException(NullOrEmptyStringErrorMessage, nameof(methodName)); } if (_clientConnectionManager.ClientConnections.TryGetValue(connectionId, out var serviceConnectionContext)) { var message = new MultiConnectionDataMessage(new[] { connectionId }, SerializeAllProtocols(methodName, args)).WithTracingId(); if (message.TracingId != null) { MessageLog.StartToSendMessageToConnections(Logger, message); } try { // Write directly to this connection await serviceConnectionContext.ServiceConnection.WriteAsync(message); if (message.TracingId != null) { MessageLog.SucceededToSendMessage(Logger, message); } return; } catch (Exception ex) { MessageLog.FailedToSendMessage(Logger, message, ex); throw; } } await base.SendConnectionAsync(connectionId, methodName, args, cancellationToken); }