Example #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);
            }
        }