Exemple #1
0
        private List <TL1DataLine> parsePartialResult(IEnumerable <string> rawLines)
        {
            List <TL1DataLine> lines = new List <TL1DataLine>();

            using (var en = rawLines.GetEnumerator())
            {
                int i = 0;
                while (en.MoveNext())
                {
                    var line = (TL1DataLine)PartialResultResponseLine.ParseIfMatches(en.Current, i)
                               ?? CommentResponseLine.ParseIfMatches(en, i);
                    if (line == null)
                    {
                        throw new FormatException($"Unexpected line format when parsing the 'PRTL' response. Line is \"{en.Current}\".");
                    }

                    lines.Add(line);
                    i++;
                }
                if (i == 0)
                {
                    throw new FormatException("No description lines found when parsing the 'PRTL' response.");
                }
            }

            return(lines);
        }
Exemple #2
0
        private List <TL1DataLine> parseCompletedResult(IEnumerable <string> rawLines)
        {
            var lines = new List <TL1DataLine>();

            using (var en = rawLines.GetEnumerator())
                while (en.MoveNext())
                {
                    lines.Add(CommentResponseLine.ParseIfMatches(en, lines.Count) ?? new TL1DataLine(lines.Count, en.Current));
                }

            return(lines);
        }
Exemple #3
0
        private List <TL1DataLine> parseDenyResult(IEnumerable <string> rawLines)
        {
            List <TL1DataLine> lines = new List <TL1DataLine>(1);

            using (var en = rawLines.GetEnumerator())
            {
                int i = 0;
                while (en.MoveNext())
                {
                    Match match;
                    switch (i)
                    {
                    case 0:
                        match = ErrorCodeRegex.Match(en.Current);
                        if (!match.Success)
                        {
                            throw new FormatException("Couldn't parse error code properly.");
                        }
                        ErrorCode = match.Groups["errcode"].Value;
                        break;

                    case 1:
                        match = ErrorVariablesRegex.Match(en.Current);
                        if (match.Success)
                        {
                            ErrorParameters = match.Groups["errvars"].Value.Split(':');
                        }
                        break;

                    default:
                        var line = CommentResponseLine.ParseIfMatches(en, i - 2);     // Expecting only comments by now.
                        if (line != null)
                        {
                            lines.Add(line);
                        }
                        else
                        {
                            throw new FormatException($"Got invalid line when parsing the 'DENY' response. Line is \"{en.Current}\"");
                        }
                        break;
                    }
                    i++;
                }
                if (i < 2)
                {
                    throw new FormatException("Expected more lines when parsing the 'DENY' response.");
                }
            }
            return(lines);
        }