예제 #1
0
        private static async Task <bool> ParseHeadingLineAsync(StreamReader reader,
                                                               Action <string, string, string> onHeadingLine)
        {
            var line = await reader.ReadLineAsync();

            return(RawParser.ParseHeadingLine(line, onHeadingLine));
        }
예제 #2
0
        public static bool ParseMessage(Stream stream,
                                        Action <string, string, string> onHeadingLine,
                                        Action <string, string> onHeaderLine)
        {
            // why Debug.Assert? in production code there's no excuse to pass null delegates
            Debug.Assert(onHeadingLine != null);
            Debug.Assert(onHeaderLine != null);

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            var reader = new StreamReader(stream);

            var headingParsing = RawParser.ParseHeadingLine(reader.ReadLine(), onHeadingLine);

            if (!headingParsing)
            {
                return(false);
            }

            while (true)
            {
                var headerLine = reader.ReadLine();
                headerLine = headerLine ?? string.Empty;
                if (headerLine.Length == 0)
                {
                    break;
                }
                var headerParsing = RawParser.ParseHeaderLine(headerLine, onHeaderLine);
                if (!headerParsing)
                {
                    return(false);
                }
            }

            return(true);
        }