Exemplo n.º 1
0
        private BackwardReply Procesar(IMessage msg)
        {
            if (msg == null)
            {
                return(BackwardReply.None);
            }
            var msgType = msg.GetType();

            if (msgType.FullName == null)
            {
                return(BackwardReply.None);
            }

            var ev   = msg as Event;
            var hash = ev != null
                                ? String.Format("{0}:{1:yyyy/MM/dd HH:mm:ss}:{2} {3} {4}:{5}", ev.DeviceId, ev.GetDateTime(), ev.Code, ev.GetData(), ev.GetData2(), msgType.Name)
                                : String.Format("{0}:{1:yyyy/MM/dd HH:mm:ss}:{2}", msg.DeviceId, msg.GetDateTime(), msgType.Name);

            if (PersisteFlag)
            {
                var controlaRepetidosFlag = DaoFactory.DetalleDispositivoDAO.GetDeviceDetail(msg.DeviceId, "GTE_FILTRAR_REPETIDOS").AsBoolean(false);
                if (controlaRepetidosFlag)
                {
                    if (DaoFactory.ReportsCacheDAO.ExistsValue(msg.DeviceId, hash))
                    {
                        STrace.Debug(typeof(FiltrarRepetidos).FullName, msg.DeviceId, String.Format("Ignorando reporte repetido (Base): {0}", hash));
                        return(BackwardReply.None);
                    }
                    var cache = new ReportsCache {
                        Dispositivo = msg.DeviceId, DateTime = msg.GetDateTime(), Value = hash
                    };
                    DaoFactory.ReportsCacheDAO.Save(cache);
                }
            }
            else
            {
                lock (_lista)
                {
                    if (!_lista.ContainsKey(msg.DeviceId))
                    {
                        _lista.Add(msg.DeviceId, new List <string>());
                    }
                    else if (_lista[msg.DeviceId].Contains(hash))
                    {
                        STrace.Debug(typeof(FiltrarRepetidos).FullName, msg.DeviceId, String.Format("Ignorando reporte repetido (Memoria): {0}", hash));
                        return(BackwardReply.None);
                    }

                    var cache = _lista[msg.DeviceId];
                    cache.Insert(0, hash);
                    if (cache.Count > 40)
                    {
                        cache.RemoveRange(25, 15);
                    }
                }
            }

            //STrace.Debug(typeof(FiltrarRepetidos).FullName, msg.DeviceId, "Despachando: {0}", hash);
            return(_dispatcher.Dispatch(msg));
        }
Exemplo n.º 2
0
        public static void DispatchResetStateMachine(int NodeCode, int TrackingId, String TrackingExtraData, IDispatcherLayer Dispatcher)
        {
            var userMessage = new UserMessage(NodeCode, (ulong)TrackingId);

            userMessage.UserSettings.Add("user_message_code", "FSM_RESET");
            userMessage.UserSettings.Add("trackingId", TrackingId.ToString());
            userMessage.UserSettings.Add("trackingExtraData", TrackingExtraData);
            Dispatcher.Dispatch(userMessage);
        }
Exemplo n.º 3
0
        public static int RejectCommand(int NodeCode, int TrackingId, String TrackingExtraData, IDispatcherLayer Dispatcher, Uri request)
        {
            STrace.Debug(typeof(CommanderReader).FullName, NodeCode, "Comando Rechazado: " + request);
            var userMessage = new UserMessage(NodeCode, (ulong)TrackingId);

            userMessage.UserSettings.Add("user_message_code", "NACK");
            userMessage.UserSettings.Add("nack_reason", "REJECTED");
            userMessage.UserSettings.Add("original_request", request.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped));
            userMessage.UserSettings.Add("trackingId", TrackingId.ToString());
            userMessage.UserSettings.Add("trackingExtraData", TrackingExtraData);
            Dispatcher.Dispatch(userMessage);
            return(1);
        }
Exemplo n.º 4
0
        private static bool UrbetrackUT_Evento(object sender, Evento pdu)
        {
            var d = Devices.I().FindById(pdu.IdDispositivo);

            if (d == null)
            {
                return(false);
            }

            if (DataTransportLayer.IsRetransmission(d.Id, pdu.Seq))
            {
                return(false);
            }


            DecorateFixWithZone(pdu.Posicion);
            var data  = pdu.Datos;
            var extra = pdu.Extra;

            var codigo = (MessageIdentifier)pdu.CodigoEvento;

            if (((pdu.CodigoEvento > 0xD0 && pdu.CodigoEvento < 0xD6) || pdu.CodigoEvento == 85))
            {
                codigo = MessageIdentifier.GenericMessage;
            }

            var msg = codigo.FactoryEvent(d.Id, pdu.Seq, pdu.Posicion, pdu.Posicion.GetDate(), pdu.RiderIdentifier, new List <int>(2)
            {
                data, extra
            });

            msg.Payload     = pdu.Payload;
            msg.PayloadSize = pdu.PayloadSize;

            Dispatcher.Dispatch(msg);
            return(true);
        }
Exemplo n.º 5
0
 private bool InChannelMessageReceived(byte[] data)
 {
     try
     {
         ReceivedMessages.Inc(1);
         ReceivedBytes.Inc((ulong)data.GetLength(0));
         var message = (OpaqueMessage.OpaqueMessage)GZip.DecompressAndDeserialize(data);
         if (message == null)
         {
             return(false);
         }
         _dispatcher.Dispatch(message);
         var outbuff = GZip.SerializeAndCompress(new OpaqueMessageReply(message));
         _outChannel.Send(outbuff);
         SentBytes.Inc((ulong)outbuff.GetLength(0));
         return(true);
     }
     catch (Exception e)
     {
         STrace.Exception(GetType().FullName, e);
     }
     return(false);
 }
Exemplo n.º 6
0
        private void MessagePeeked(IAsyncResult ar)
        {
            try
            {
                var t = new TimeElapsed();
                MessageQueue.EndPeek(ar);
                var ts = t.getTimeElapsed().TotalSeconds;
                if (ts > 1)
                {
                    STrace.Debug("DispatcherLock", "Queue.EndPeek: " + ts);
                }
                //transaction.Begin();
                // Create a transaction.
                //var msg = Queue.Receive(transaction);
                System.Messaging.Message msg = null;
                lock (peekLock)
                {
                    t.Restart();
                    msg = MessageQueue.Receive(System.Messaging.MessageQueueTransactionType.None);
                    ts  = t.getTimeElapsed().TotalSeconds;
                    if (ts > 1)
                    {
                        STrace.Debug("DispatcherLock", String.Format("Queue.Receive: {0}", ts));
                    }
                }

                if (msg == null)
                {
                    //transaction.Abort();
                    return;
                }
                var payload = (IMessage)msg.Body;
                if (payload == null)
                {
                    STrace.Debug(GetType().FullName, String.Format("MessageConsumer: IMessage no castea. Body.ToString='{0}'", msg.Body));
                    if (DeadMessageQueue != null)
                    {
                        DeadMessageQueue.Send(msg);
                    }

                    //transaction.Commit();
                    return;
                }
                if (DispatcherLayer.Dispatch(payload).Action != ReplyAction.None)
                {
                    //if (AbortOnFailure)
                    //transaction.Abort();
                    //else
                    if (DeadMessageQueue != null)
                    {
                        DeadMessageQueue.Send(msg);
                    }

                    return;
                }
                //var t = new TimeElapsed();
                //transaction.Commit();
                //if (t.getTimeElapsed().TotalSeconds > 1) STrace.Debug("DispatcherLock", "transaction.Commit: " + t.getTimeElapsed().TotalSeconds);
            }
            catch (System.Messaging.MessageQueueException e)
            {
                if (e.MessageQueueErrorCode != System.Messaging.MessageQueueErrorCode.IOTimeout)
                {
                    //if (transaction != null)
                    //{
                    //    if (AbortOnFailure)
                    //        transaction.Abort();
                    //    else
                    //        transaction.Commit();
                    //}
                    STrace.Exception(GetType().FullName, e);
                }
            }
            catch (Exception e)
            {
                //if (transaction != null)
                //{
                //    if (AbortOnFailure)
                //        transaction.Abort();
                //    else
                //        transaction.Commit();
                //}
                STrace.Exception(GetType().FullName, e);
            }
            finally
            {
                if (!CountMore(MessageQueue, MinMessagesToSleep))
                {
                    //STrace.Debug(GetType().FullName, "Sleep");
                    Thread.Sleep(SleepTime);
                }
                if (MessageQueue != null)
                {
                    MessageQueue.BeginPeek(AsyncTimeout, null, MessagePeeked);
                }
            }
        }
Exemplo n.º 7
0
 public void DispatchMessage(INode device, IMessage message)
 {
     DispatcherLayer.Dispatch(message);
 }