示例#1
0
        private void DispatchMessage(TcpProtocolDtoBase data, ICommunicationChannel responseChannel)
        {
            if (!_dispatchers.TryGetValue(data.ServiceName, out var serviceRecord))
            {
                SessionLog.WriteLine("No dispatcher for " + data.ServiceName);
                return;
            }

            if (data is RpcCall rpcCall)
            {
                SessionLog.WriteLine("Processing call to " + rpcCall.Id);
                var result = serviceRecord.Dispatcher.Dispatch(serviceRecord.ServiceInstance, rpcCall.Id, rpcCall.Parameters);
                if (result != null)
                {
                    var callResult = RpcCallResult.Respond(rpcCall, result);
                    responseChannel.Write(callResult);
                }
            }
            else if (data is RpcCallResult result)
            {
                SessionLog.WriteLine("Saving response to " + result.Id);
                lock (_responses)
                {
                    _responses.Enqueue(result);
                }
                _responseAvailable.Set();
            }
        }
示例#2
0
 public static RpcCallResult <Unit> ToUnit(this RpcCallResult <Void> callResult)
 {
     return(new RpcCallResult <Unit>(Unit.Void, callResult.Attempts, callResult.Duration, callResult.WaitForConnectionDuration));
 }