Exemplo n.º 1
0
        public void PauseResumeClientTest()
        {
            ClientManager cmn = new ClientManager();

            // Pasando configuracion.
            cmn.SetClientConfig(new SendClientConfig(CreateClientConfig()));
            cmn.SetSystemConfig(new SendSystemConfig(CreateSystemConfig()));
            cmn.Start();

            // Generando HB para el cliente.
            HeartBeat hb = HeartBeat.CreateHeartBeat(Client1_ID);

            cmn.ReceiveHB(new SendHeartbeat(hb));

            // Comprobar cliente en lista de trabajo
            Assert.AreEqual(1, cmn.ClientList.Count);
            Assert.AreEqual(1, cmn.WorkList.Count);

            // Pausar cliente
            cmn.PauseClient(new RequestPauseClient(Client1_Guid));

            // Comprobar cliente en lista de pausa
            Assert.AreEqual(0, cmn.WorkList.Count);
            Assert.AreEqual(1, cmn.PausedList.Count);

            // Continuar cliente
            cmn.ResumeClient(new RequestResumeClient(Client1_Guid));

            // Comprobar cliente en lista de trabajo
            Assert.AreEqual(1, cmn.WorkList.Count);
            Assert.AreEqual(0, cmn.PausedList.Count);

            // Fin
            cmn.Stop();
        }
Exemplo n.º 2
0
        static private void IniciaServidor()
        {
            Console.WriteLine("Simulador iniciado. Servidor Pipe atiende: " + name);
            Console.WriteLine(messg);
            Console.CancelKeyPress += Console_CancelKeyPress;

            Encd        = new ASCIIEncoding();
            _pipeServer = new NamedPipeServerStream(name, PipeDirection.In, maxconn, PipeTransmissionMode.Message, PipeOptions.Asynchronous, bufferSize, bufferSize);


            int numBytes = 0;

            keepLoop = true;

            while (keepLoop)
            {
                string message = String.Empty;
                buffer = new byte[bufferSize];

                _pipeServer.WaitForConnection();

                do
                {
                    numBytes = _pipeServer.Read(buffer, 0, bufferSize);
                    //Console.WriteLine("LEidos: " + numBytes.ToString());
                } while (numBytes != 0);

                HeartBeat hb = HeartBeat.CreateHeartBeat(buffer);
                message = string.Format("Cliente: {0}  Pipe: {1}  TS: {2}  Serial: {3}", hb.ClientID, name, hb.Timestamp, hb.Serial);
                Console.WriteLine(message);

                _pipeServer.Disconnect();
            }
        }
Exemplo n.º 3
0
        public void IdCreationTest()
        {
            string ExpectedClientID     = "TEST01";
            string ExpectedTimestamp    = DateTime.Now.ToString(HeartBeat.DefaultFormat);
            string ExpectedSerial       = null;
            ulong  ExpectedSerialNumber = 0;

            HeartBeat TxHB = HeartBeat.CreateHeartBeat(ExpectedClientID);
            HeartBeat RxHB = HeartBeat.CreateHeartBeat(TxHB.ByteSequence);

            string ActualClientID     = RxHB.ClientID;
            string ActualTimestamp    = RxHB.Timestamp;
            string ActualSerial       = RxHB.Serial;
            ulong  ActualSerialNumber = RxHB.SerialNumber;

            Assert.AreEqual(ExpectedClientID, ActualClientID);
            Assert.AreEqual(ExpectedSerial, ActualSerial);
            Assert.AreEqual(ExpectedSerialNumber, ActualSerialNumber);
            Assert.AreEqual(ExpectedTimestamp, ActualTimestamp);
        }
Exemplo n.º 4
0
        public void TimestampFormatCreationTest()
        {
            string format               = "dd/MM/yyyy HH:mm";
            string ExpectedClientID     = null;
            string ExpectedSerial       = null;
            ulong  ExpectedSerialNumber = 0;
            string ExpectedTimestamp    = DateTime.Now.ToString(format);

            HeartBeat TxHB = HeartBeat.CreateHeartBeat(ExpectedClientID, format);
            HeartBeat RxHB = HeartBeat.CreateHeartBeat(TxHB.ByteSequence);

            string ActualClientID     = RxHB.ClientID;
            string ActualTimestamp    = RxHB.Timestamp;
            string ActualSerial       = RxHB.Serial;
            ulong  ActualSerialNumber = RxHB.SerialNumber;

            Assert.AreEqual(ExpectedClientID, ActualClientID);
            Assert.AreEqual(ExpectedSerial, ActualSerial);
            Assert.AreEqual(ExpectedSerialNumber, ActualSerialNumber);
            Assert.AreEqual(ExpectedTimestamp, ActualTimestamp);
        }
Exemplo n.º 5
0
        static private void ReadOp(IAsyncResult ar)
        {
            string text = String.Empty;

            IPEndPoint ipRemoteEp = new IPEndPoint(IPAddress.Any, 0);
            EndPoint   epRemote   = (EndPoint)ipRemoteEp;

            try
            {
                string message, ipadr, port;

                if (_skListener.EndReceiveFrom(ar, ref epRemote) > 0)
                {
                    text = Encd.GetString((byte[])ar.AsyncState);

                    ipRemoteEp = (IPEndPoint)epRemote;

                    HeartBeat hb = HeartBeat.CreateHeartBeat((byte[])ar.AsyncState);

                    port  = ipRemoteEp.Port.ToString();
                    ipadr = ipRemoteEp.Address.ToString();

                    message = string.Format("Cliente: {0}  IP: {1}  Puerto: {2}  TS: {3}  Serial: {4}", hb.ClientID, ipadr, port, hb.Timestamp, hb.Serial);
                    Console.WriteLine(message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Ha ocurrido una excepcion: " + ex.Message);
                throw;
            }

            buffer = new byte[bufferSize];

            if (_skListener != null)
            {
                _skListener.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(ReadOp), buffer);
            }
        }