/// <summary> /// Controla que la dif entre real y teorico no supere el porcentaje configurado de la capacidad. /// Devuelve True en caso de que no la haya superado y False en caso de que sí. /// </summary> /// <param name="tank"></param> /// <param name="vol"></param> /// <param name="tankVolumeDifferenceAlarm"></param> /// <param name="hasBeenBelowPercentageSinceLastEvent"></param> private bool ControlsTeoricVsRealDifference(Tanque tank, VolumenHistorico vol, double tankVolumeDifferenceAlarm, bool hasBeenBelowPercentageSinceLastEvent) { if (tankVolumeDifferenceAlarm != 0 && tankVolumeDifferenceAlarm != HighValue) { return(true); } var lastRealLevel = DaoFactory.VolumenHistoricoDAO.GetLastTankRealLevel(tank, vol.Fecha); if (Math.Abs((vol.Volumen - lastRealLevel.Volumen)) > tankVolumeDifferenceAlarm) { if (hasBeenBelowPercentageSinceLastEvent) { FuelMessageSaver.CreateNewEvent(null, tank.Codigo, CodeTDifRealVsTeoricoSuperada, String.Format(MsgTDifRealVsTeoricoSuperada, lastRealLevel.Volumen, vol.Volumen), vol.Fecha); STrace.Trace(GetType().FullName, String.Format("Teorical versus real levels warning refference reached for tank: {0} (real: {1} - teorical: {2} - date: {3}).", tank.Descripcion, lastRealLevel.Volumen, vol.Volumen, vol.Fecha)); } else { STrace.Trace(GetType().FullName, String.Format( @"Teorical versus real levels warning refference reached for tank: {0} (real: {1} - teorical: {2} - date: {3}) || A previos warning already exists (no event was raised).", tank.Descripcion, lastRealLevel.Volumen, vol.Volumen, vol.Fecha)); } return(false); } return(true); }
/// <summary> /// Controla que el volumen teorico no pase de positivo a negativo. /// </summary> /// <param name="tank"></param> /// <param name="actualVolume"></param> /// <param name="vol"></param> private void ControlsNegativeTeoricVolume(Tanque tank, double actualVolume, VolumenHistorico vol) { if (actualVolume < 0 || vol.Volumen >= 0) { return; } FuelMessageSaver.CreateNewEvent(null, tank.Codigo, CodeTTeoricoNegativo, String.Format(MsgTTeoricoNegativo, vol.Volumen), vol.Fecha); STrace.Trace(GetType().FullName, String.Format("Negative volume detected for tank: {0} (volume: {1})", tank.Descripcion, vol.Volumen)); }
/// <summary> /// Controla que el volumen teorico no supere la capacidad del tanque. /// </summary> /// <param name="tank"></param> /// <param name="vol"></param> private void ControlsTeoricVolumeExceededTankCapacity(Tanque tank, VolumenHistorico vol) { if (vol.Volumen <= tank.Capacidad) { return; } if (HasBeenUnderCapacitySinceLastEvent(tank, vol)) { FuelMessageSaver.CreateNewEvent(null, tank.Codigo, CodeTTeoricoSuperaCapacidad, String.Format(MsgTTeoricoSuperaCapacidad, tank.Capacidad, vol.Volumen), vol.Fecha); STrace.Trace(GetType().FullName, String.Format("Teorical max volume exceded for tank: {0} (volume: {1} - capacity: {2}).", tank.Descripcion, vol.Volumen, tank.Capacidad)); } else { STrace.Trace(GetType().FullName, String.Format("Teorical max volume exceded for tank: {0} (volume: {1} - capacity: {2}) || A previos warning already exists (no event was raised)", tank.Descripcion, vol.Volumen, tank.Capacidad)); } }
/// <summary> /// Checks if any tank has exceded its no report refference time. /// </summary> private void CheckTanksNoReportTime() { STrace.Trace(GetType().FullName, String.Format("Checking if any tank hash reached its no report warning zone.")); foreach (var tanque in DaoFactory.TanqueDAO.FindAll()) { var lastLevel = DaoFactory.VolumenHistoricoDAO.GetLastTankRealLevel(tanque, DateTime.MaxValue); if (!tanque.TiempoSinReportar.HasValue || tanque.TiempoSinReportar.Value.Equals(0)) { STrace.Trace(GetType().FullName, String.Format("The tank {0} does not checks for no report intervals.", tanque.Descripcion)); continue; } if (lastLevel == null || DateTime.Now.Subtract(lastLevel.Fecha).TotalMinutes > tanque.TiempoSinReportar.Value) { var lastMessage = DaoFactory.TanqueDAO.FindLastMessageByCode(tanque.Id, TankNoReportEventCode); if (lastMessage == null || (lastLevel != null && lastMessage.Fecha < lastLevel.Fecha)) { STrace.Trace(GetType().FullName, String.Format("The tank {0} hash reached its no report time span ({1} minutes).", tanque.Descripcion, tanque.TiempoSinReportar.Value)); var lastReport = lastLevel != null?String.Concat(lastLevel.Fecha.ToShortDateString(), " ", lastLevel.Fecha.ToShortTimeString()) : "Sin fecha de ultimo reporte"; var text = String.Format(" - Tanque: {0} - Ultimo Reporte: {1}", tanque.Descripcion, lastReport); FuelMessageSaver.CreateNewEvent(null, tanque.Codigo, TankNoReportEventCode, text, DateTime.Now); continue; } STrace.Trace(GetType().FullName, String.Format("The tank {0} hash reached its no report time span ({1} minutes), but a previos warning already exists.", tanque.Descripcion, tanque.TiempoSinReportar.Value)); continue; } STrace.Trace(GetType().FullName, String.Format("The tank {0} is reporting correctly.", tanque.Descripcion)); } }
/// <summary> /// Checks if any engine has exceded its no report refference time. /// </summary> private void CheckEnginesNoReportTime() { STrace.Trace(GetType().FullName, "Checking if any engine hash reached its no report warning zone."); foreach (var motor in DaoFactory.CaudalimetroDAO.FindAll()) { var lastMovement = DaoFactory.MovimientoDAO.GetLastEngineMovement(motor); if (motor.TiempoSinReportar.Equals(0)) { STrace.Trace(GetType().FullName, String.Format("The engine {0} does not checks for no report intervals.", motor.Descripcion)); continue; } if (lastMovement == null || DateTime.Now.Subtract(lastMovement.Fecha).TotalMinutes > motor.TiempoSinReportar) { var lastMessage = DaoFactory.CaudalimetroDAO.FindLastMessageByCode(motor.Id, EngineNoReportEventCode); if (lastMessage == null || (lastMovement != null && lastMessage.Fecha < lastMovement.Fecha)) { STrace.Trace(GetType().FullName, String.Format("The engine {0} hash reached its no report time span ({1} minutes).", motor.Descripcion, motor.TiempoSinReportar)); var lastReport = lastMovement != null?String.Concat(lastMovement.Fecha.ToShortDateString(), " ", lastMovement.Fecha.ToShortTimeString()) : "Sin fecha de ultimo reporte"; var text = String.Format(" - Motor: {0} - Ultimo Reporte: {1}", motor.Descripcion, lastReport); FuelMessageSaver.CreateNewEvent(motor.Codigo, null, EngineNoReportEventCode, text, DateTime.Now); continue; } STrace.Trace(GetType().FullName, String.Format("The engine {0} hash reached its no report time span ({1} minutes), but a previos warning already exists.", motor.Descripcion, motor.TiempoSinReportar)); continue; } STrace.Trace(GetType().FullName, String.Format("The engine {0} is reporting correctly.", motor.Descripcion)); } }