public string LastPosition(string messageXml)
        {
            LastPositionResponseTypeMessage responseMsg;
            LastPositionRequestTypeMessage  request = null;

            try
            {
                $"<LastPositionRequestType>{messageXml}</LastPositionRequestType>".XDocValidate(Utils.GetSchemas());
                request = messageXml.DeserializeFromXmlString <LastPositionRequestTypeMessage>();
                Logger.LogInformation(AvlLogEvent.LastPositionCall, request.Header.SessionID, null);
                responseMsg = BL.LastPosition(request);
            }
            catch (XmlSchemaValidationException ex)
            {
                Logger.LogError(ex, request != null ? request.Header.SessionID : 0, "LastPosition request validation error.");
                responseMsg = new LastPositionResponseTypeMessage()
                {
                    Header = new Header()
                    {
                        MessageIDSpecified = true,
                        SessionIDSpecified = true,
                        MessageID          = -1,
                        SessionID          = -1
                    },
                    Body = new LastPositionResponseTypeMessageBody()
                    {
                        LastPositionResponse = new LastPositionResponseTypeMessageBodyLastPositionResponse()
                        {
                            Status      = false,
                            Description = "XML syntax error in request",
                            VehicleList = new LastPositionResponseTypeMessageBodyLastPositionResponseVehicle[] { }
                        }
                    }
                };
            }
            string responseStr = responseMsg.SerializeToXmlString();

            $"<LastPositionResponseType>{responseStr}</LastPositionResponseType>".XDocValidate(Utils.GetSchemas());
            Logger.LogDebug(AvlLogEvent.LastPositionCall, responseMsg.Header.SessionID, "Response sent: {responseStr}", responseStr);
            return(responseStr);
        }
Exemplo n.º 2
0
        public async Task Invoke(HttpContext context)
        {
            var requestLog            = $"REQUEST HttpMethod: {context.Request.Method}, Path: {context.Request.Path}";
            var injectedRequestStream = new MemoryStream();

            using (var bodyReader = new StreamReader(context.Request.Body))
            {
                var bodyAsText = bodyReader.ReadToEnd();
                if (string.IsNullOrWhiteSpace(bodyAsText) == false)
                {
                    requestLog += $", Body : {bodyAsText}";
                }

                var bytesToWrite = Encoding.UTF8.GetBytes(bodyAsText);
                injectedRequestStream.Write(bytesToWrite, 0, bytesToWrite.Length);
                injectedRequestStream.Seek(0, SeekOrigin.Begin);
                context.Request.Body = injectedRequestStream;
            }
            _logger.LogDebug(AvlLogEvent.AvlRequest, 0, requestLog);
            await _next.Invoke(context);
        }