protected override async void OnRequestReceived(ITransport transport, Message message) { var msgType = message.MessageType; switch (msgType) { case MessageType.Connect: { /*TODO*/ break; } case MessageType.OneWayRequest: { try { var instanceContext = _instanceContextFactory.CreateInstanceContext(this); await instanceContext.HandleRequest(message, this); } catch (Exception ex) { LogError(ex, $"Failed to handle {msgType.ToString()}"); } break; } case MessageType.Request: { RequestHandleResult result; try { var instanceContext = _instanceContextFactory.CreateInstanceContext(this); result = await instanceContext.HandleRequest(message, this); } catch (Exception ex) { LogError(ex, $"Failed to handle {msgType.ToString()}"); var error = _msgBuilder.CreateError(message.Id, "Server Error"); result = new RequestHandleResult(error, true); } if (result.HasResponse) { await this.Transport.SendResponse(result.Response); } break; } default: { throw new Exception($"Wrong protocol usage, Server can't accept messages of type {msgType}"); } } }
protected override async void OnRequestReceived(ISocket socket, Message message) { var msgType = message.MessageType; switch (msgType) { case MessageType.Connect: { /*TODO*/ break; } case MessageType.OneWayRequest: { try { var instanceContext = _instanceContextFactory.CreateInstanceContext(this); await instanceContext.HandleRequest(message, this); } catch (Exception ex) { _logger.LogError(ex, $"Connection {Id} failed to handle {msgType.ToString()}"); } break; } case MessageType.Request: { Message?response = null; try { var instanceContext = _instanceContextFactory.CreateInstanceContext(this); response = await instanceContext.HandleRequest(message, this); } catch (Exception ex) { _logger.LogError(ex, $"Connection {Id} failed to handle {msgType.ToString()}"); response = _msgBuilder.CreateError(message.Id, "Server Error"); } if (response.HasValue) { await this.Socket.SendResponse(response.Value); } break; } default: { throw new Exception($"Wrong protocol usage, Server can't accept messages of type {msgType}"); } } }
protected override async void OnRequestReceived(ITransport transport, Message message) { var instanceContext = _instanceContextFactory.CreateInstanceContext(this); await instanceContext.HandleRequest(message, null); }