예제 #1
0
        public TestScriptDocument Parse()
        {
            TestScriptStatementList statements = ParseStatements();

            TestScriptDocument document = new TestScriptDocument(statements);

            return(document);
        }
예제 #2
0
        public static TestScriptValue Do(TestScriptDocument script, TestScriptEvalContext context)
        {
            Eval(script.Statements, context);

            Socket socket = context.Sock;

            TestScriptValue list = TestScriptValue.CreateList();

            System.Threading.Thread.Sleep(1000);

            while (socket.Available > 0)
            {
                byte[] head = new byte[4];

                int received = 0;

                while (received != 4)
                {
                    received += socket.Receive(head);
                }

                Array.Reverse(head);

                int length = BitConverter.ToInt32(head, 0);

                received = 0;

                byte[] data = new byte[length];

                while (received != length)
                {
                    received += socket.Receive(data, received, length - received, SocketFlags.None);
                }

                ProtoSpecModule recvModule = context.ProtoSpec.Modules.GetById(data[0].ToString());

                if (recvModule == null)
                {
                    Error("数据接收失败,无法找到ID为“" + data[0] + "”的模块");
                }

                ProtoSpecAction recvAction = recvModule.Actions.GetById(data[1].ToString());

                if (recvAction == null)
                {
                    Error("数据接收失败,在模块“" + recvModule.Name + "”中无法找到ID位“" + data[1] + "”的操作");
                }

                if (recvAction.Output.Columns.Count > 0)
                {
                    int parseOffset = 2;

                    TestScriptValue recvValue = TestScriptValue.CreateObject();

                    ParseResponse(recvModule.Name, data, ref parseOffset, recvAction.Output, recvValue);

                    TestScriptValue actionResult = TestScriptValue.CreateActionResult(recvModule.Name, recvAction.Name, recvValue);

                    list.AddItem(actionResult);
                }
            }

            return(list);
        }
예제 #3
0
        public static void Run(TestScriptDocument script, TestScriptEvalContext context)
        {
            Eval(script.Statements, context);

            #region OLD

            /*
             * Socket socket = context.Sock;
             *
             * TestScriptValue list = TestScriptValue.CreateList();
             *
             * System.Threading.Thread.Sleep(1000);
             *
             * while (socket.Available > 0)
             * {
             *  byte[] head = new byte[2];
             *
             *  int received = 0;
             *
             *  while (received != 2)
             *  {
             *      received += socket.Receive(head);
             *  }
             *
             *  byte temp = head[0];
             *
             *  head[0] = head[1];
             *  head[1] = temp;
             *
             *  short length = BitConverter.ToInt16(head, 0);
             *
             *  received = 0;
             *
             *  byte[] data = new byte[length];
             *
             *  while (received != length)
             *  {
             *      received += socket.Receive(data, received, length - received, SocketFlags.None);
             *  }
             *
             *  ProtoSpecModule recvModule = context.ProtoSpec.Modules.GetById(data[0].ToString());
             *
             *  if (recvModule == null)
             *      Error("数据接收失败,无法找到ID为“" + data[0] + "”的模块");
             *
             *  ProtoSpecAction recvAction = recvModule.Actions.GetById(data[1].ToString());
             *
             *  if (recvAction == null)
             *      Error("数据接收失败,在模块“" + recvModule.Name + "”中无法找到ID位“" + data[1] + "”的操作");
             *
             *  if (recvAction.Output.Columns.Count > 0)
             *  {
             *      int parseOffset = 2;
             *
             *      TestScriptValue recvValue = TestScriptValue.CreateObject();
             *
             *      ParseResponse(recvModule.Name, data, ref parseOffset, recvAction.Output, recvValue);
             *
             *      TestScriptValue actionResult = TestScriptValue.CreateActionResult(recvModule.Name, recvAction.Name, recvValue);
             *
             *      list.AddItem(actionResult);
             *  }
             * }
             *
             * return list;
             */
            #endregion
        }