public async Task HandleMessage(Client client, INetworkStreamWrapper networkStream, byte[] bytes) { ICustomMessageHandler customMessageHandler = GetMessageHandler(client.Protocol); MessageInput messageInput = new MessageInput { Client = client, NetworkStream = networkStream, DataMessage = new DataMessage(bytes, client.Protocol.SplitMessageBy) }; logger.LogTrace( $"{client.Protocol}: received {HexUtil.ConvertHexStringArrayToHexString(messageInput.DataMessage.Hex)}"); int connectionMessageId = await connectionService.AddMessage(client.DeviceConnection.Id, messageInput.DataMessage.HexString); try { List <Location> locations = customMessageHandler.ParseRange(messageInput)?.ToList(); if (locations != null && locations.Any()) { // TODO refactor this await connectionService.SetDeviceId(client); await locationService.AddRange(locations, connectionMessageId); } } catch (Exception e) { logger.LogCritical(e, $"{customMessageHandler.GetType()}: Error parsing {messageInput.DataMessage.Hex} "); } }
public void Init() { _mockResponseHandler = MockRepository.GenerateStub <IExceptionResponseHandler>(); _controller = new HttpCallController(_mockResponseHandler); _mockProcessor = MockRepository.GenerateStub <IHttpCallProcessor>(); _mockProcessor.Stub(s => s.Method).Return("TEST"); _controller.RegisterCallProcessor(_mockProcessor); _mockWrapper = MockRepository.GenerateStub <INetworkStreamWrapper>(); }
virtual public IHttpResponse ProcessCall(INetworkStreamWrapper socketWrapper) { _socketWrapper = socketWrapper; _socketWrapper.SkipByteCount(_verbLength + 1); var httpCall = new HttpCall() { ServerSettings = ServerSettings, RequestHeader = GetHeaderFromSocket(), RawRequestBody = GetRequestBodyFromSocket() }; return(_firstCallResponder.Respond(httpCall)); }
public async Task HandleStream(CancellationToken cancellationToken, Client client, INetworkStreamWrapper networkStream) { byte[] buffer = new byte[ServerVariables.BufferLength]; int length; do { length = ReadMessage(networkStream, buffer, client.Protocol, cancellationToken); if (length > 0) { logger.LogDebug($"{client.Protocol}: received {length} bytes"); int startIndex = GetStartIndex(buffer, length, client.Protocol); await messageHandler.HandleMessage(client, networkStream, buffer[startIndex..length]);
public void ProcessCall(INetworkStreamWrapper socketWrapper) { var result = socketWrapper.PeekToString(9); Exception caughtException = null; IHttpResponse response = null; try { IHttpCallProcessor callProcessor = VerifyAndExtractProcessor(result); response = callProcessor.ProcessCall(socketWrapper); } catch (Exception ex) { if (_exceptionHandler.HasResponse(ex.GetType().Name) == false) { throw; } response = _exceptionHandler.GetResponseFromException(caughtException); } SendResponse(response, socketWrapper); }
private void SendResponse(IHttpResponse response, INetworkStreamWrapper socketWrapper) { socketWrapper.Send(response.GetResponseAsByteArray()); }