예제 #1
0
 public static ServicePriceResponse FromProtoServicePriceResponse(Proto.ServicePriceResponse response)
 {
     return(new ServicePriceResponse
     {
         Success = response.ResponseCode == 0,
         ConcentratorId = response.ConcentratorId,
         GameControllerId = response.ControllerId,
         CardId = response.CardId,
         TransactionId = response.TransactionId,
         EGMId = response.ServiceId,
         MessageLine1 = response.ResponseCode == 0 ? response.ServiceName : $"Err {response.ResponseCode}",
         MessageLine2 = response.ResponseCode == 0 ? $"{response.Price:F2}" : "",
     });
 }
예제 #2
0
        // метода се извиква при всяко запитване на конектнатия клиент
        public byte[] ProccessRequest(byte[] message)
        {
            //извличане на входните данни
            var splittedMessage = SplitByteArray(message, 0x1F).ToArray();

            if (splittedMessage.Count() == 0)
            {
                return new byte[] { 0x45, 0x52, 0x52, 0x4F, 0x52 }
            }
            ;                                                       //ERROR

            // how many tokens
            int tokensCount = splittedMessage.GetLength(0);
            // command
            string cmd = tokensCount >= 1 ? new string(
                splittedMessage[0]
                .Where(b => b != 0x1F && b != 0x1E)     // except:  0x1F - unit separator char(31), 0x1E - record separator char(30)
                .Select(b => (char)b)
                .ToArray()) : string.Empty;

            if (cmd.Equals("RG", StringComparison.InvariantCultureIgnoreCase))
            {
                CanPlayRequest request = CanPlayRequest.DeserializeASCII(splittedMessage);

                _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize(request));
                Proto.CanPlayRequest proto_request = request.ToProtoCanPlayRequest();
                CanPlayResponse      response;
                try
                {
                    Proto.CanPlayResponse proto_response = _cardService.CanPlayAsync(proto_request).Result;
                    if (proto_response != null)
                    {
                        response = CanPlayResponse.FromProtoCanPlayResponse(proto_response);
                    }
                    else
                    {
                        response = new CanPlayResponse {
                            Success = false, MessageLine1 = "Err 109", MessageLine2 = "Internal server"
                        };
                        _logger.LogError("TextMessageService.ProccessRequest => Proto.CanPlayResponse is null");
                    }
                }
                catch (Exception ex)
                {
                    response = new CanPlayResponse {
                        Success = false, MessageLine1 = "Err 109", MessageLine2 = "Internal server"
                    };
                    _logger.LogError($"TextMessageService.ProccessRequest throws: {ex}");
                }
                _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize(response));
                return(response.SerializeASCII());
            }
            else if (cmd.Equals("RP", StringComparison.InvariantCultureIgnoreCase))
            {
                ServicePriceRequest request = ServicePriceRequest.DeserializeASCII(splittedMessage);
                _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize(request));
                Proto.ServicePriceRequest proto_request = request.ToProtoServicePriceRequest();
                ServicePriceResponse      response;
                try
                {
                    Proto.ServicePriceResponse proto_response = _cardService.ServicePriceAsync(proto_request).Result;
                    if (proto_response != null)
                    {
                        response = ServicePriceResponse.FromProtoServicePriceResponse(proto_response);
                    }
                    else
                    {
                        response = new ServicePriceResponse {
                            Success = false, MessageLine1 = "Err 109", MessageLine2 = "Internal server"
                        };
                        _logger.LogError("TextMessageService.ProccessRequest => Proto.ServicePriceRequest is null");
                    }
                }
                catch (Exception ex)
                {
                    response = new ServicePriceResponse {
                        Success = false, MessageLine1 = "Err 109", MessageLine2 = "Internal server"
                    };
                    _logger.LogError($"TextMessageService.ProccessRequest throws: {ex}");
                }
                _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize(response));
                return(response.SerializeASCII());
            }
            else if (cmd.Equals("T", StringComparison.InvariantCultureIgnoreCase))
            {
                return(Encoding.ASCII.GetBytes($"{DateTime.Now:dd.MM.yyyy HH:mm}\x1E"));
            }
            else
            {
                return(Encoding.ASCII.GetBytes($"{DateTime.Now:dd.MM.yyyy HH:mm}\x1E"));
            }
        }