예제 #1
0
        public static TL1ReceivedMessage Parse <TResponse, TAutonomous, TAckCodesEnum>(TextReader reader)
            where TResponse : TL1Response, new()
            where TAutonomous : TL1AutonomousMessage, new()
            where TAckCodesEnum : struct
        {
            try
            {
                var firstLine = reader.ReadLine();

                if (TL1ReceivedHeaderedMessage.MatchesFormat(firstLine))
                {
                    return(TL1ReceivedHeaderedMessage.Parse <TResponse, TAutonomous>(firstLine, reader));
                }
                else if (TL1Acknowledgement <TAckCodesEnum> .MatchesFormat(firstLine))
                {
                    return(TL1Acknowledgement <TAckCodesEnum> .Parse(firstLine, reader));
                }
                else
                {
                    throw new FormatException($"Unknwon incomming message - Second line was \"{firstLine}\"");
                }
            }
            catch (Exception ex)
            {
                throw new FormatException("Given response is in an incorrect format.", ex);
            }
        }
예제 #2
0
        public static TL1Acknowledgement <TAckCodesEnum> Parse(string firstLine, TextReader reader)
        {
            var match = FirstLineRegex.Match(firstLine);
            var ack   = new TL1Acknowledgement <TAckCodesEnum>
            {
                AcknowledgementCode = (TAckCodesEnum)Enum.Parse(typeof(TAckCodesEnum), match.Groups["ack_code"].Value),
                CorrelationTag      = match.Groups["ctag"].Value
            };

            if (firstLine.EndsWith("<"))
            {
                return(ack);
            }
            if ((firstLine = reader.ReadLine()) != "<")
            {
                throw new FormatException($"Unexpected acknowledgement message format. Second line is \"{firstLine}\".");
            }
            return(ack);
        }