public virtual LogPosicionBase RetrieveNewestReceivedPosition() { var key = MakeNewestDeviceStatusKey(Dispositivo.Id); var deviceStatus = LogicCache.Retrieve <DeviceStatus>(typeof(DeviceStatus), key); return(new LogPosicionBase(deviceStatus.Position, this)); }
/// <summary> /// Finds the message with the givenn code for the specified location and base. /// </summary> /// <param name="codigo"></param> /// <param name="device"></param> /// <returns></returns> public MensajeVO GetByCodigo(String codigo, int device) { if (device == 0) { return(null); } if (String.IsNullOrEmpty(codigo)) { return(null); } var vehicle = new CocheDAO().FindMobileByDevice(device); var emp = vehicle.Empresa != null ? vehicle.Empresa.Id : vehicle.Linea != null ? vehicle.Linea.Empresa != null ? vehicle.Linea.Empresa.Id : -1 : -1; var lin = vehicle.Linea != null ? vehicle.Linea.Id : -1; var key = String.Format("message:{0}:{1}:{2}", emp, lin, codigo); if (!LogicCache.KeyExists(typeof(MensajeVO), key)) { var result = FindByEmpresaYLineaAndUser(vehicle.Empresa, vehicle.Linea, null).FirstOrDefault(m => Convert.ToInt32(m.Codigo) == Convert.ToInt32(codigo)); var mensajeVo = result != null ? new MensajeVO(result) : null; LogicCache.Store(typeof(MensajeVO), key, mensajeVo); return(mensajeVo); } return(LogicCache.Retrieve <MensajeVO>(typeof(MensajeVO), key)); }
public Sensor FindByCode(int dispositivo, string code) { lock (CacheByCodeLock) { var key = GetByCodeCacheKey(dispositivo, code); var sensorCache = LogicCache.Retrieve <string>(typeof(string), key); if (!string.IsNullOrEmpty(sensorCache)) { var sensorId = Convert.ToInt32(sensorCache); var sensor = sensorId == 0 ? null : FindById(sensorId); return(sensor == null || sensor.Dispositivo.Id != dispositivo ? null : sensor); } try { var sensor = Query .Where(s => !s.Baja && s.Dispositivo.Id == dispositivo && s.Codigo == code) .SafeFirstOrDefault(); if (sensor != null) { LogicCache.Store(typeof(string), key, sensor.Id); } return(sensor); } catch (Exception e) { STrace.Exception(typeof(SensorDAO).FullName, e, dispositivo); return(null); } } }
public Geocerca FindGeocerca(ReferenciaGeografica rg) { var geo = new Geocerca(rg); LogicCache.Store(typeof(Geocerca), GetGeocercaByIdKey(rg.Id), geo, DateTime.UtcNow.AddMinutes(Config.Dispatcher.DispatcherGeocercasRefreshRate)); return(geo); }
/// <summary> /// Finds the message with the givenn code for the specified location and base. /// </summary> /// <param name="codigo"></param> /// <param name="empresa"></param> /// <param name="linea"></param> /// <returns></returns> public MensajeVO GetByCodigo(String codigo, Empresa empresa, Linea linea) { if (String.IsNullOrEmpty(codigo)) { return(null); } var emp = empresa != null ? empresa.Id : linea != null ? linea.Empresa != null ? linea.Empresa.Id : -1 : -1; var lin = linea != null ? linea.Id : -1; var key = String.Format("message:{0}:{1}:{2}", emp, lin, codigo); if (!LogicCache.KeyExists(typeof(MensajeVO), key)) { var result = FindByEmpresaYLineaAndUser(empresa, linea, null).FirstOrDefault(m => Convert.ToInt32(m.Codigo) == Convert.ToInt32(codigo)); var mensajeVo = result != null ? new MensajeVO(result) : null; LogicCache.Store(typeof(MensajeVO), key, mensajeVo); return(mensajeVo); } return(LogicCache.Retrieve <MensajeVO>(typeof(MensajeVO), key)); }
/// <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); } }
// public PedidoDAO(ISession session) : base(session) { } #region Find Methods public int FindNextId() { const string cacheKey = "AutoGenCode"; int maxId; if (LogicCache.KeyExists(typeof(Pedido), cacheKey)) { maxId = (int)LogicCache.Retrieve <object>(typeof(Pedido), cacheKey); } else { maxId = Session.Query <Pedido>().Any() ? Session.Query <Pedido>().Max(p => p.Id) : 1; } while (FindByCode(-1, maxId.ToString()) != null) { maxId++; } LogicCache.Store(typeof(Pedido), cacheKey, maxId, DateTime.Now.AddMinutes(5)); return(maxId); }
private void DeleteCache(string key) { if (LogicCache.KeyExists(typeof(MensajeVO), key)) { LogicCache.Delete(typeof(MensajeVO), key); } }
public SubEntidad FindBySensor(int sensor) { lock (CacheBySensorLock) { var key = GetBySensorCacheKey(sensor); var subEntidadCache = LogicCache.Retrieve <string>(typeof(string), key); if (!string.IsNullOrEmpty(subEntidadCache)) { var subEntidadId = Convert.ToInt32(subEntidadCache); var subEntidad = subEntidadId == 0 ? null : FindById(subEntidadId); return(subEntidad == null || subEntidad.Sensor.Id != sensor ? null : subEntidad); } try { var subEntidad = Query.Where(s => !s.Baja && s.Sensor.Id == sensor).SafeFirstOrDefault(); if (subEntidad != null) { LogicCache.Store(typeof(string), key, subEntidad.Id); } return(subEntidad); } catch (Exception e) { STrace.Exception(typeof(SensorDAO).FullName, e); return(null); } } }
/// <summary> /// Setea el estado inicial (dentro/fuera) de todas las geocercas del ticket a partir de la ultima posicion del vehiculo. /// </summary> protected void FirstPosition() { try { var position = DaoFactory.LogPosicionDAO.GetLastOnlineVehiclePosition(Vehiculo); if (position == null) { return; } // Pongo todas las geocercas en Desconocido var geocercas = Geocercas.Select(geocerca => GetKeyGeocerca(geocerca)); foreach (var key in geocercas) { LogicCache.Store(typeof(EstadosEntrega), key, new EstadosEntrega(EstadosGeocerca.Desconocido), DateTime.UtcNow.AddHours(5)); } // Proceso la primera posicion var positionEvent = new PositionEvent(position.FechaMensaje, position.Latitud, position.Longitud); ProcessGeocercas(positionEvent); } catch (Exception ex) { STrace.Exception(typeof(CicloLogisticoFactory).FullName, ex); } }
/// <summary> /// Elimina el estado de todas las geocercas de este ticket de la cache /// </summary> protected void ClearGeocercasCache() { foreach (var key in Geocercas.Select(g => GetKeyGeocerca(g)).Where(key => LogicCache.KeyExists(typeof(EstadosEntrega), key))) { LogicCache.Delete(typeof(EstadosEntrega), key); } }
public void ResetLastModQtree(int empresa, int linea) { var key = GetGeocercaQtreeKey(empresa, linea); LogicCache.Store(typeof(Geocerca), key, DateTime.UtcNow); STrace.Trace("QtreeReset", string.Format("Reset para ({0}, {1})", empresa, linea)); }
/// <summary> /// Adds or refreshes the devices parameters dictionary. /// </summary> private void CalculateDeviceParameters() { var key = String.Format("deviceParameters:{0}", Dispositivo.Id); var parameters = LogicCache.Retrieve <DeviceParameters>(typeof(DeviceParameters), key); if (parameters != null) { if (parameters.NeedsUpdate) { parameters.UpdateParameters(Dispositivo); LogicCache.Store(typeof(DeviceParameters), key, parameters); } DeviceParameters = parameters; } else { parameters = new DeviceParameters(Dispositivo); LogicCache.Store(typeof(DeviceParameters), key, parameters); DeviceParameters = parameters; } }
private static void StoreDevKey(int deviceId, Coche cocheObj) { if (cocheObj == null) { return; //si estan configurando un dispositivo nuevo y reporta antes de darlo de alta es mejor no guardar nada y esperar a que lo den de alta } var id = cocheObj.Id.ToString("#0"); LogicCache.Store(typeof(String), "DeviceVehicle:" + deviceId, id); }
public virtual LogUltimaPosicionVo RetrieveNewestReceivedPositionVo() { var key = MakeNewestDeviceStatusKey(Dispositivo.Id); var deviceStatus = LogicCache.Retrieve <DeviceStatus>(typeof(DeviceStatus), key); var pos = new LogPosicionBase(deviceStatus.Position, this); var ret = new LogUltimaPosicionVo(pos); return(ret); }
public virtual Boolean IsNewestPositionReceivedInCache() { if (Dispositivo == null) { return(false); } var key = MakeNewestDeviceStatusKey(Dispositivo.Id); return(LogicCache.KeyExists(typeof(DeviceStatus), key)); }
/// <summary> /// Procesa una posicion y genera los eventos de entrada y salida de geocerca. /// </summary> /// <param name="data"></param> protected void ProcessGeocercas(PositionEvent data) { try { var geocercas = Puntos; var point = new GPSPoint(data.Date, (float)data.Latitud, (float)data.Longitud); foreach (var geocerca in geocercas) { var key = GetKeyGeocerca(geocerca); if (Regeneracion) { key = "recalc_" + key; } var lastState = LogicCache.KeyExists(typeof(EstadosEntrega), key) ? LogicCache.Retrieve <EstadosEntrega>(typeof(EstadosEntrega), key).Estado : EstadosGeocerca.Desconocido; var geo = DaoFactory.ReferenciaGeograficaDAO.FindGeocerca(geocerca); var p = new PointF(point.Lon, point.Lat); var inside = geo.IsInBounds(p) && geo.Contains(p.Y, p.X); var newState = inside ? EstadosGeocerca.Dentro : EstadosGeocerca.Fuera; if (lastState != newState) { var state = new EstadosEntrega(newState); LogicCache.Store(typeof(EstadosEntrega), key, state, Regeneracion ? DateTime.UtcNow.AddMinutes(5) : DateTime.UtcNow.AddHours(5)); IEvent evento = null; if (lastState == EstadosGeocerca.Dentro && newState == EstadosGeocerca.Fuera) { evento = EventFactory.GetEvent(DaoFactory, point, MessageCode.OutsideGeoRefference.GetMessageCode(), geocerca, 0, null, Empleado); } else if (lastState == EstadosGeocerca.Fuera && newState == EstadosGeocerca.Dentro) { evento = EventFactory.GetEvent(DaoFactory, point, MessageCode.InsideGeoRefference.GetMessageCode(), geocerca, 0, null, Empleado); } if (evento == null) { continue; } ProcessEvent(evento, true); } } } catch (Exception ex) { STrace.Exception(typeof(CicloLogisticoFactory).FullName, ex); } }
public static DateTime GetLastUpdate(int empresa, int linea) { var key = GetGeocercaQtreeKey(empresa, linea); if (!LogicCache.KeyExists(typeof(Geocerca), key)) { return(DateTime.MinValue); } return((DateTime)LogicCache.Retrieve <object>(typeof(Geocerca), key)); }
public Geocerca GetGeocercaById(int id) { var rg = Session.CreateCriteria <ReferenciaGeografica>("rg") .Add(Restrictions.Eq("Id", id)) .UniqueResult <ReferenciaGeografica>(); var geo = new Geocerca(rg); LogicCache.Store(typeof(Geocerca), GetGeocercaByIdKey(rg.Id), geo, DateTime.UtcNow.AddMinutes(Config.Dispatcher.DispatcherGeocercasRefreshRate)); return(geo); }
private static void setETAEstimated(Int32 Id, DateTime?value) { var key = makeIDFor(Id, "ETA_Estimated"); if (value == null) { LogicCache.Delete(key); } else { LogicCache.Store(typeof(String), key, value.Value.ToString("O")); } }
private static void setETADistanceTo(Int32 Id, UInt32?value) { var key = makeIDFor(Id, "ETA_DistanceTo"); if (value == null) { LogicCache.Delete(key); } else { LogicCache.Store(typeof(String), key, value.Value.ToString()); } }
public static EstadoGeocerca GetEstadoGeocerca(Coche vehiculo, Geocerca geocerca) { var key = string.Format("device[{0}].geocercas", vehiculo.Dispositivo.Id); var dentro1 = LogicCache.Retrieve <int[]>(key); if (dentro1 == null) { return(null); } var dentro = dentro1; return(dentro.Contains(geocerca.Id) ? GetEstadoGeocercaDentro(vehiculo, geocerca) : null); }
private static string GetEmployeeRfidAction(string rfid) { var key = string.Format("employeeRfid:{0}", rfid); if (LogicCache.KeyExists(typeof(string), key)) { LogicCache.Delete(typeof(string), key); return(MessageCode.RfidEmployeeLogout.GetMessageCode()); } LogicCache.Store(typeof(string), key, rfid); return(MessageCode.RfidEmployeeLogin.GetMessageCode()); }
public virtual DateTime?EtaEstimated() { var key = string.Empty; DateTime?dt = null; if (Dispositivo != null) { key = "device_" + Dispositivo.Id + "_ETA_Estimated"; } if (LogicCache.KeyExists(typeof(string), key)) { var ret = LogicCache.Retrieve <string>(typeof(string), key); dt = DateTime.ParseExact(ret, "O", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal); } return(dt); }
public virtual int EtaDistanceTo() { var key = string.Empty; var dist = 0; if (Dispositivo != null) { key = "device_" + Dispositivo.Id + "_ETA_DistanceTo"; } if (LogicCache.KeyExists(typeof(string), key)) { var ret = LogicCache.Retrieve <string>(key); int.TryParse(ret, out dist); } return(dist); }
/// <summary> /// Updates the cache to store the message being created. /// </summary> /// <param name="obj"></param> private void UpdateCache(Mensaje obj) { const string keyformat = "message:{0}:{1}:{2}"; var key = String.Format(keyformat, -1, -1, obj.Codigo); DeleteCache(key); var empresa = obj.Empresa != null ? obj.Empresa.Id : -1; var linea = obj.Linea != null ? obj.Linea.Id : -1; if (empresa == -1) { foreach (var lin in new LineaDAO().FindAll()) { key = String.Format(keyformat, lin.Empresa.Id, lin.Id, obj.Codigo); DeleteCache(key); key = String.Format(keyformat, lin.Empresa.Id, -1, obj.Codigo); DeleteCache(key); } } else if (linea == -1) { key = String.Format(keyformat, empresa, -1, obj.Codigo); DeleteCache(key); foreach (var lin in new LineaDAO().FindList(new[] { empresa })) { key = String.Format(keyformat, empresa, lin.Id, obj.Codigo); DeleteCache(key); } } else { key = String.Format(keyformat, empresa, linea, obj.Codigo); DeleteCache(key); } LogicCache.Store(typeof(MensajeVO), key, new MensajeVO(obj)); }
public override void SaveOrUpdate(SubEntidad obj) { var oldSensor = obj.OldSensor; base.SaveOrUpdate(obj); lock (CacheBySensorLock) { if (oldSensor != null) // si cambia el sensor, borro la cache vieja { LogicCache.Delete(typeof(string), GetBySensorCacheKey(oldSensor.Id)); } if (obj.Baja) // si se elimina la subEntidad, borro la cache { LogicCache.Delete(typeof(string), GetBySensorCacheKey(obj.Sensor.Id)); } if (!obj.Baja) // si no se elimino la subEntidad, agrego el id a la cache { LogicCache.Store(typeof(string), GetBySensorCacheKey(obj.Sensor.Id), obj.Id); } } }
public override void SaveOrUpdate(Sensor obj) { var oldDev = obj.OldDispositivo; base.SaveOrUpdate(obj); lock (CacheByCodeLock) { if (oldDev != null) // si cambia el dispo, borro la cache vieja { LogicCache.Delete(typeof(string), GetByCodeCacheKey(oldDev.Id, obj.OldCodigo)); } if (obj.Baja) // si se elimina el sensor, borro la cache { LogicCache.Delete(typeof(string), GetByCodeCacheKey(obj.Dispositivo.Id, obj.Codigo)); } if (!obj.Baja) // si no se elimino el sensor, agrego el id a la cache { LogicCache.Store(typeof(string), GetByCodeCacheKey(obj.Dispositivo.Id, obj.Codigo), obj.Id); } } }
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); } }
public int FindNextOrdenDiario(int empresa, int linea, DateTime date) { var cacheKey = string.Format("DailyOrder[{0}][{1}]", empresa, linea); int maxId; if (LogicCache.KeyExists(typeof(Ticket), cacheKey)) { maxId = (int)LogicCache.Retrieve <object>(typeof(Ticket), cacheKey); } else { var max = Query.FilterEmpresa(Session, new[] { empresa }, null) .FilterLinea(Session, new[] { empresa }, new[] { linea }, null) .Where(t => t.FechaTicket >= date.Date && t.FechaTicket < date.Date.AddDays(1) && t.OrdenDiario.HasValue && t.Estado != Ticket.Estados.Eliminado) .Max(t => t.OrdenDiario); maxId = max.HasValue ? max.Value : 0; } maxId++; LogicCache.Store(typeof(Pedido), cacheKey, maxId, DateTime.Now.AddMinutes(5)); return(maxId); }