Example #1
0
        public void TestReplies0()
        {
            string reply = "<REPLY queryObjects(10, addr, name, protocol)>\r\n";

            reply += "1002 name[\"kleine Schwarze\"] addr[2] protocol[MM14]\r\n";
            reply += "1005 name[\"Dampf #2\"] addr[20] protocol[MM14]\r\n";
            reply += "1007 name[\"Kompressorlok\"] addr[78] protocol[MM14]\r\n";
            reply += "1004 name[\"Schwarz Diesel\"] addr[2] protocol[MM14]\r\n";
            reply += "1006 name[\"DIESEL rot\"] addr[21] protocol[MM14]\r\n";
            reply += "1008 name[\"BR10\"] addr[10] protocol[MM14]\r\n";
            reply += "1000 name[\"Ae3 /6II SBB\"] addr[1000] protocol[DCC28]\r\n";
            reply += "1009 name[\"DAMPF2\"] addr[20] protocol[MM14]\r\n";
            reply += "1001 name[\"Kompressor\"] addr[78] protocol[MM14]\r\n";
            reply += "1003 name[\"kleine Schwarze\"] addr[2] protocol[MM14]\r\n";
            reply += "<END 0 (OK)>\r\n";

            var  msg = new ReplyBlock();
            bool r   = msg.Parse(reply);

            r.Should().BeTrue();
            msg.ListEntries.Count.ShouldBeEquivalentTo(10);
            msg.Result.ErrorCode.Should().Be(0);
            msg.Result.ErrorMessage.ShouldBeEquivalentTo("OK");
            msg.Command.Name.ShouldBeEquivalentTo("queryObjects");
        }
Example #2
0
        public void TestReplies2()
        {
            string reply = "<REPLY get(26, state)>\r\n";

            reply += "<END 11 (unknown option at 9)>\r\n";

            var  msg = new ReplyBlock();
            bool r   = msg.Parse(reply);

            r.Should().BeTrue();
            msg.ListEntries.Count.ShouldBeEquivalentTo(0);
            msg.Result.ErrorCode.Should().Be(11);
            msg.Result.ErrorMessage.ShouldBeEquivalentTo("unknown option at 9");
            msg.Command.Name.ShouldBeEquivalentTo("get");
        }
Example #3
0
        public static IReadOnlyList <IBlock> GetBlocks(IList <string> lines)
        {
            var blocks     = new List <IBlock>();
            var blockLines = new List <string>();

            foreach (var currentLine in lines)
            {
                if (string.IsNullOrEmpty(currentLine))
                {
                    continue;
                }
                var line = currentLine.TrimStart(CR, LF);
                if (!line.ToUpper().StartsWith("<END "))
                {
                    blockLines.Add(line + CRLF);
                    continue;
                }

                blockLines.Add(line + CRLF);

                var    firstLine = blockLines[0].ToUpper();
                IBlock instance;
                if (firstLine.StartsWith("<EVENT "))
                {
                    instance = new EventBlock();
                }
                else if (firstLine.StartsWith("<REPLY "))
                {
                    instance = new ReplyBlock();
                }
                else
                {
                    continue;
                }

                if (!instance.Parse(blockLines))
                {
                    return(null);
                }
                blocks.Add(instance);
                blockLines.Clear();
            }

            return(blocks);
        }
Example #4
0
        public void TestReplies1()
        {
            string reply = "<REPLY get(100)>\r\n";

            reply += "100 objectclass[feedback - module]\r\n";
            reply += "100 view[objectclass, view, listview, control, ports, state, railcom]\r\n";
            reply += "100 listview[none]\r\n";
            reply += "100 control[none]\r\n";
            reply += "100 ports[16]\r\n";
            reply += "100 state[0x0]\r\n";
            reply += "100 railcom[...]\r\n";
            reply += "<END 0 (OK)>\r\n";

            var  msg = new ReplyBlock();
            bool r   = msg.Parse(reply);

            r.Should().BeTrue();
            msg.ListEntries.Count.ShouldBeEquivalentTo(7);
            msg.Result.ErrorCode.Should().Be(0);
            msg.Result.ErrorMessage.ShouldBeEquivalentTo("OK");
            msg.Command.Name.ShouldBeEquivalentTo("get");
        }