Ejemplo n.º 1
0
        public void ProcesaLosMensajesQueIngresan()
        {
            var messageQueuedIn = new MessageQueued();
            var messageDataIn = new MessageData();
            A.CallTo(() => messageDataFactory.Create(messageQueuedIn)).Returns(messageDataIn);

            worker.Procesar(messageQueuedIn);

            A.CallTo(() => dinamica.Ejecutar(messageDataIn)).MustHaveHappened();
        }
Ejemplo n.º 2
0
        public void Ejecutar(MessageData messageData)
        {
            var messageQueued = new MessageQueued
            {
                ClientKey = messageData.ClientKey,
                EntidadId = messageData.EntidadId,
                RawData = messageData.RawData
            };

            if (messageData.RawData.Contains("REQUEST"))
            {
                Console.WriteLine("Processing request message. Key: {0}", messageData.ClientKey);
                QueueSender.Send(messageData.ClientKey, messageQueued, QueueConstants.BANKAUTHORIZER_QUEQUE);
            }
            if (messageData.RawData.Contains("RESPONSE"))
            {
                Console.WriteLine("Processing response message. Key: {0}", messageData.ClientKey);
                QueueSender.Send(messageData.ClientKey, messageQueued, QueueConstants.CELLPHONE_QUEQUE);
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var socketThread = new Thread(() =>
                {
                    var socketHandler = new SocketListener(11000, (handler, content) =>
                        {
                            var clientKey = Guid.NewGuid().ToString();
                            connectedClients.GetOrAdd(clientKey, handler);
                            var messageQueued = new MessageQueued
                                {
                                    ClientKey = clientKey,
                                    EntidadId = ENTIDAD_ID,
                                    RawData = content
                                };
                            QueueSender.Send(clientKey, messageQueued, QueueConstants.REQUEST_QUEQUE, QueueConstants.CELLPHONE_QUEQUE);
                        });
                    socketHandler.StartListening();
                });
            socketThread.Start();

            var queueThread = new Thread(() =>
                {
                    var queueListener = new QueueListener(QueueConstants.CELLPHONE_QUEQUE, messageQueued =>
                        {
                            Socket handler;
                            connectedClients.TryRemove(messageQueued.ClientKey, out handler);
                            if (handler==null)
                            {
                                throw new ClienteConectadoNoReconocidoException(messageQueued.ClientKey);
                            }
                            SocketSender.Send(handler, messageQueued.RawData.ToString());
                        });
                    queueListener.Start();
                });
            queueThread.Start();

            Console.WriteLine("CELULAR service started....");
            socketThread.Join();
            queueThread.Join();
        }
        private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                var state = (StateObject)ar.AsyncState;
                var handler = state.WorkSocket;

                int bytesRead = handler.EndReceive(ar);

                if (bytesRead > 0)
                {
                    state.Sb.Append(Encoding.ASCII.GetString(state.Buffer, 0, bytesRead));

                    var frame = state.Sb.ToString().Substring(0, 4);
                    var clientKey = state.Sb.ToString().Substring(4, 36);
                    var content = state.Sb.ToString().Substring(40);
                    if (state.Sb.ToString().Substring(4).Length == int.Parse(frame))
                    {
                        Console.WriteLine("Receive {0} bytes from client. \n Data: {1}", state.Sb.Length, state.Sb);

                        var messageQueued = new MessageQueued
                        {
                            ClientKey = clientKey,
                            EntidadId = ENTIDAD_ID,
                            RawData = content
                        };

                        QueueSender.Send(clientKey, messageQueued, QueueConstants.RESPONSE_QUEQUE);
                        receiveDone.Set();
                    }
                    else
                    {
                        handler.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReceiveCallback, state);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 5
0
 public void Procesar(MessageQueued messageQueuedIn)
 {
     var messageDataIn = messageDataFactory.Create(messageQueuedIn);
     dinamica.Ejecutar(messageDataIn);
 }