Exemple #1
0
        public void ReadCommandTest()
        {
            // read basic command with ACK
            var read     = new ReadCommands("login_ack", "System", "Login");
            var filePath = testHelper.CopyFileToTest("login_ack");

            read.Read();
            Assert.AreEqual("ACK", read.ResultValues[0]);
            // test file is deleted after been read
            Assert.AreEqual(false, File.Exists(filePath));

            // read basic command with NAK
            testHelper.CopyFileToTest("login_nak");

            read = new ReadCommands("login_nak", "System", "Login");
            read.Read();
            Assert.AreEqual("NAK", read.ResultValues[0]);

            // read complex command with list of params
            testHelper.CopyFileToTest("list_visit_card");

            read = new ReadCommands("list_visit_card", "Archive", "GetSubjectVisitList");
            read.Read();
            // test keys
            int index = 0;

            foreach (string key in read.ResultKeys)
            {
                if (index == 0)
                {
                    Assert.AreEqual("NumVisits", key);
                }
                else
                {
                    Assert.AreEqual("ID_00000000-0000-0000-0000-00000000000" + index.ToString(), key);
                }
                index += 1;
            }
            // test values
            index = 0;
            int firstVisit = 20131028;

            foreach (string value in read.ResultValues)
            {
                if (index == 0)
                {
                    Assert.AreEqual("4", value);
                }
                else
                {
                    Assert.AreEqual(firstVisit.ToString(), value);
                    firstVisit += 1;
                }
                index += 1;
            }
        }
Exemple #2
0
 public void Initialize()
 {
     MMWindow.Manager = this;
     ReadModels.Clear();
     WriteModels.Clear();
     ReadCommands.Clear();
     WriteCommands.Clear();
     _Add(LadderModels);
     if (MMWindow != null)
     {
         foreach (MonitorVariableTable mvtable in MMWindow.tables)
         {
             Initialize(mvtable);
         }
     }
     Arrange();
 }
Exemple #3
0
 private void _Thread_Run()
 {
     _Thread_IsAlive = true;
     while (_Thread_Alive)
     {
         while (_Thread_Alive && _Thread_Active)
         {
             if (CurrentCommand == null)
             {
                 if (WriteCommands.Count() > 0)
                 {
                     CurrentCommand = WriteCommands.Dequeue();
                 }
                 else
                 {
                     if (ReadCommands.Count() == 0)
                     {
                         CurrentCommand = null;
                     }
                     else
                     {
                         if (ReadCommandIndex >= ReadCommands.Count())
                         {
                             ReadCommandIndex = 0;
                         }
                         CurrentCommand = ReadCommands[ReadCommandIndex++];
                     }
                 }
             }
             bool hassend  = false;
             bool hasrecv  = false;
             int  sendtime = 0;
             int  recvtime = 0;
             if (CurrentCommand != null)
             {
                 while (_Thread_Alive && _Thread_Active &&
                        sendtime < 5)
                 {
                     if (Send(CurrentCommand))
                     {
                         hassend = true;
                         break;
                     }
                     sendtime++;
                 }
                 int itvtime = 20;
                 if (CurrentCommand is GeneralWriteCommand ||
                     CurrentCommand is IntrasegmentWriteCommand)
                 {
                     itvtime = 100;
                 }
                 //_Thread_WaitForActive(itvtime);
                 Thread.Sleep(itvtime);
                 while (hassend)
                 {
                     try
                     {
                         if (Recv(CurrentCommand))
                         {
                             hasrecv = true;
                             break;
                         }
                     }
                     catch (Exception e)
                     {
                     }
                     recvtime++;
                 }
             }
             if (_Thread_Alive && hassend && hasrecv)
             {
                 Execute(CurrentCommand);
                 CurrentCommand = null;
             }
             Thread.Sleep(10);
         }
         _Thread_WaitForActive();
     }
     _Thread_IsAlive = false;
 }