Example #1
0
        /// <summary>
        /// Determines if the givenn action applies for the specified message.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="accion"></param>
        /// <returns></returns>
        protected static Boolean ApplyAction(Object context, Accion accion)
        {
            if (String.IsNullOrEmpty(accion.Condicion))
            {
                return(true);
            }

            try
            {
                var expression = ExpressionContext.CreateExpression(accion.Condicion, context);

                var cachedResult = LogicCache.Retrieve <Object>(typeof(Boolean), expression);

                if (cachedResult != null)
                {
                    return(Convert.ToBoolean(cachedResult));
                }

                var result = Logictracker.ExpressionEvaluator.ExpressionEvaluator.Evaluate <bool>(expression);

                LogicCache.Store(typeof(Boolean), expression, result);

                return(result);
            }
            catch (Exception e)
            {
                STrace.Exception(typeof(BaseEventSaver).FullName, e, String.Format("Error procesando condicion: {0} | Accion: {1}", accion.Condicion, accion.Descripcion));

                return(false);
            }
        }
Example #2
0
        private static Boolean ApplyAction(LogMensajeBase log, Accion accion)
        {
            if (accion == null || accion.Condicion == null || accion.Condicion.Trim() == string.Empty)
            {
                return(true);
            }

            try
            {
                var context = new EventContext
                {
                    Dispositivo        = log.Dispositivo.Codigo,
                    Duracion           = log.Duracion,
                    Exceso             = log.Exceso,
                    Interno            = log.Coche.Interno,
                    Legajo             = log.Chofer != null ? log.Chofer.Legajo : string.Empty,
                    Texto              = log.Texto,
                    TieneTicket        = log.Horario != null,
                    VelocidadAlcanzada = log.VelocidadAlcanzada.HasValue ? log.VelocidadAlcanzada.Value : -1,
                    VelocidadPermitida = log.VelocidadPermitida.HasValue ? log.VelocidadPermitida.Value : -1,
                    Fecha              = log.Fecha,
                    FechaFin           = log.FechaFin
                };

                var expression   = ExpressionContext.CreateExpression(accion.Condicion, context);
                var cachedResult = LogicCache.Retrieve <Object>(typeof(Boolean), expression);
                if (cachedResult != null)
                {
                    return(Convert.ToBoolean(cachedResult));
                }
                var result = Logictracker.ExpressionEvaluator.ExpressionEvaluator.Evaluate <bool>(expression);
                LogicCache.Store(typeof(Boolean), expression, result);
                return(result);
            }
            catch (Exception e)
            {
                STrace.Exception(typeof(BaseEventSaver).FullName, e, String.Format("Error procesando condicion: {0} | Accion: {1}", accion.Condicion, accion.Descripcion));
                return(false);
            }
        }