Esempio n. 1
0
        private static ParserResult AnswerParser(IEnumerable <string> parser)
        {
            var result = new ParserResult();
            //Dim result1 As Dictionary(Of String, String) = (From str In arr Where str.Length >= 2).ToDictionary(Function(str) str.Substring(0, 2), Function(str) s.Substring(2))
            var resultOfParsing =
                parser.Where(str => str.Length >= 2)
                .ToDictionary(str => str.Substring(0, 2).ToUpper(), str => str.Substring(2).ToUpper());


            if (resultOfParsing.ContainsKey("P#"))
            {
                result.Ticket = TypeParser.Int32TryParse(resultOfParsing["P#"]);
            }
            if (!resultOfParsing.ContainsKey("AS"))
            {
                return(result);
            }
            switch (resultOfParsing["AS"])
            {
            case "OK":
                result.Command = Command.AsOk;
                break;

            case "NG":
                result.Command = Command.AsNg;
                break;

            default:
                result.Command = Command.UnKnown;
                break;
            }

            return(result);
        }
Esempio n. 2
0
        private static ParserResult AnswerParser(IEnumerable <string> parser)
        {
            var result = new ParserResult();

            var resultOfParsing =
                parser.Where(str => str.Length >= 2)
                .ToDictionary(str => str.Substring(0, 2).ToUpper(), str => str.Substring(2).ToUpper());


            if (resultOfParsing.ContainsKey("P#"))
            {
                result.Ticket = TypeParser.Int32TryParse(resultOfParsing["P#"]);
            }
            //if (!resultOfParsing.ContainsKey("AN") || !resultOfParsing.ContainsKey("AS")) return result;
            string answ = resultOfParsing.ContainsKey("AN") ? resultOfParsing["AN"] : resultOfParsing.ContainsKey("AS") ? resultOfParsing["AS"] : "";

            switch (answ)
            {
            case "OK":
                result.Command = Command.AsOk;
                break;

            case "NG":
                result.Command = Command.AsNg;
                break;

            default:
                result.Command = Command.UnKnown;
                break;
            }
            return(result);
        }