public async Task <object> EnviarEvento([FromBody] SendEvent_DTO evento) { try { object result = new { sucess = await _reader_REP_LOCAL.EnviarEventoGenerico(evento), status = 200, data = "Done" }; return(result); } catch (Exception ex) { object result = new { sucess = false, status = 400, data = ex.Message }; return(BadRequest(result)); } }
private EvaluacionEventoDC_DTO GetDescripcion(tipoEvento tipo, SendEvent_DTO evento) { bool eventoAlarmado = false; List <string> descripcion = new List <string> { tipo.ToString(), //NOMBRE DEL EVENTO (bool)evento.tapabocas ? "0" : "1", //ALERTA DE TAPABOCAS (evento.temperatura <= evento.tempRef) ? "0" : "1", //ALERTA DE TEMPERATURA (bool)evento.validaIdentidad? "0" : "1", //ALERTA DOCUMENTO Y BADGE NO COINCIDEN (bool)evento.ecoPassVigente? "0" : "1", (bool)evento.PersonaConocida? "0" : "1", (bool)evento.BiomeConectado? "0" : "1" }; for (int i = 1; i < descripcion.Count; i++) { if (descripcion[i] == "1") { eventoAlarmado = true; } } return(new EvaluacionEventoDC_DTO { descripcionEvento = descripcion[0] + "|" + descripcion[1] + "|" + descripcion[2] + "|" + evento.documento.ToString() + "|" + evento.temperatura.ToString() + "|" + evento.tempRef.ToString() + "|" + descripcion[3] + "|" + descripcion[4] + "|" + descripcion[5] + "|" + descripcion[6], alarmaEvento = eventoAlarmado }); }
public async Task <bool> EnviarEventoGenerico(SendEvent_DTO evento) { try { return(await _reader_REP.SendIncomingEvent(evento, _path, _user, _pass)); } catch (Exception ex) { throw new Exception("no se pudo crear el evento " + ex.Message); } }
public async Task <object> EnviarEvento([FromBody] SendEvent_DTO evento) { try { return(await _reader_REP_LOCAL.EnviarEventoGenerico(evento)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <bool> SendIncomingEvent(SendEvent_DTO evento, string path, string user, string pass) { try { ManagementScope eventScope = _dataConduITMgr.GetManagementScope(path, user, pass); ManagementClass eventClass = new ManagementClass(eventScope, new ManagementPath("Lnl_IncomingEvent"), null); ManagementObject eventInstance = eventClass.CreateInstance(); ManagementBaseObject inParams = eventClass.GetMethodParameters("SendIncomingEvent"); inParams.Properties["Source"].Value = evento.source; if (!string.IsNullOrEmpty(evento.device)) { inParams.Properties["Device"].Value = evento.device; } if (!string.IsNullOrEmpty(evento.subdevice)) { inParams.Properties["SubDevice"].Value = evento.subdevice; } inParams.Properties["Description"].Value = evento.description; if (evento.isAccessGranted != null) { inParams.Properties["IsAccessGrant"].Value = evento.isAccessGranted; } if (evento.isAccessDeny != null) { inParams.Properties["IsAccessDeny"].Value = evento.isAccessDeny; } if (evento.badgeID != null) { inParams.Properties["BadgeID"].Value = evento.badgeID; } // Execute the method eventClass.InvokeMethod("SendIncomingEvent", inParams, null); return(true); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// Devuelve resultado del analisis de temperatura y tapabocas /// </summary> /// <param name="entrada"></param> /// <param name="evento"></param> /// <returns></returns> private EvaluacionEvento_DTO GetDescripcion(bool entrada, SendEvent_DTO evento) { List <string> descripcion = new List <string> { entrada ? "IB" : "SB", //NOMBRE DEL EVENTO (bool)evento.tapabocas ? "0" : "1", //ALERTA DE TAPABOCAS (evento.temperatura <= evento.tempRef) ? "0" : "1", //ALERTA DE TEMPERATURA }; return(new EvaluacionEvento_DTO { descripcionEvento = descripcion[0] + "|" + descripcion[1] + "|" + descripcion[2] + "|" + evento.badgeID.ToString() + "|" + evento.temperatura.ToString() + "|" + evento.tempRef.ToString(), alarmaEvento = (descripcion[1] == "1" || descripcion[2] == "1") }); }
/// <summary> /// Devuelve resultado del analisis de temperatura y tapabocas /// </summary> /// <param name="tipo"> /// 0-Ingreso Biometrico, 1-Ingreso Biometrico No Identificado, /// 2-Salida Biometrico, 3-Salida Biometrico No identificado /// </param> /// <param name="evento"></param> /// <returns></returns> private EvaluacionEvento_DTO GetDescripcion(tipoEvento tipo, SendEvent_DTO evento) { List <string> descripcion = new List <string> { tipo.ToString(), //NOMBRE DEL EVENTO (bool)evento.tapabocas ? "0" : "1", //ALERTA DE TAPABOCAS (evento.temperatura <= evento.tempRef) ? "0" : "1", //ALERTA DE TEMPERATURA (bool)evento.validaIdentidad? "0" : "1" //ALERTA DOCUMENTO Y BADGE NO COINCIDEN }; return(new EvaluacionEvento_DTO { descripcionEvento = descripcion[0] + "|" + descripcion[1] + "|" + descripcion[2] + "|" + evento.documento.ToString() + "|" + evento.temperatura.ToString() + "|" + evento.tempRef.ToString() + "|" + descripcion[3], alarmaEvento = (descripcion[1] == "1" || descripcion[2] == "1" || descripcion[3] == "1") }); }
public async Task <object> AutorizarIngreso([FromBody] SendEvent_DTO evento) { try { EvaluacionEvento_DTO eval = GetDescripcion(true, evento); evento.description = eval.descripcionEvento; bool enviado = await _reader_REP_LOCAL.EnviarEventoGenerico(evento); if (enviado) { return(eval); } else { throw new Exception("No se pudo enviar el evento"); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <object> AutorizarIngreso([FromBody] SendEvent_DTO evento) { try { object result = new { sucess = true, status = 200, data = await _reader_REP_LOCAL.AutorizacionIngreso(evento, 15, 3, 2000), }; return(result); } catch (Exception ex) { object result = new { sucess = false, status = 400, data = ex.Message }; return(BadRequest(result)); } }
public async Task <object> AutorizacionIngreso(SendEvent_DTO evento, int gap, int intentos, int timeOut, string path, string user, string password) { GetCardHolderDC_DTO persona = new GetCardHolderDC_DTO(); List <GetBadgeDC_DTO> tarjetas = new List <GetBadgeDC_DTO>(); int badgekey = 0; string badgeID = ""; bool salir = false; bool success = false; string resultado = "OK"; ResLastLocationDC_DTO lastEvent = new ResLastLocationDC_DTO(); List <LastLocation_DTO> listLocations = new List <LastLocation_DTO>(); ManagementScope IngresoScope = _dataConduITMgr.GetManagementScope(path, user, password); #region OBTENER PERSONA if (evento.documento != "" && evento.documento != null && evento.esVisitante == false) { try { ObjectQuery cardHolderSearcher = new ObjectQuery(@"SELECT * FROM Lnl_CardHolder WHERE OPHONE = '" + evento.documento + /*"' AND SSNO = '" + ssno +*/ "'"); ManagementObjectSearcher getCardHolder = new ManagementObjectSearcher(IngresoScope, cardHolderSearcher); foreach (ManagementObject queryObj in getCardHolder.Get()) { persona.id = int.Parse(queryObj["ID"].ToString()); try { persona.apellidos = queryObj["LASTNAME"].ToString(); } catch { persona.apellidos = null; } try { persona.nombres = queryObj["FIRSTNAME"].ToString(); } catch { persona.nombres = null; } try { persona.ssno = queryObj["SSNO"].ToString(); } catch { persona.ssno = null; } try { persona.status = queryObj["STATE"].ToString(); } catch { persona.status = null; } try { persona.documento = queryObj["OPHONE"].ToString(); } catch { persona.documento = null; } try { persona.empresa = queryObj["TITLE"].ToString(); } catch { persona.empresa = null; } try { persona.ciudad = queryObj["DEPT"].ToString(); } catch { persona.ciudad = null; } try { persona.instalacion = queryObj["BUILDING"].ToString(); } catch { persona.instalacion = null; } try { persona.piso = queryObj["FLOOR"].ToString(); } catch { persona.piso = null; } try { persona.area = queryObj["DIVISION"].ToString(); } catch { persona.area = null; } try { persona.email = queryObj["EMAIL"].ToString(); } catch { persona.email = null; } persona.permiteVisitantes = (bool)queryObj["ALLOWEDVISITORS"]; #region OBTENER BADGE ACTIVO ObjectQuery badgeSearcher = new ObjectQuery(@"SELECT * FROM Lnl_Badge WHERE PERSONID = '" + queryObj["ID"].ToString() + "' AND STATUS = 1"); ManagementObjectSearcher getBadge = new ManagementObjectSearcher(IngresoScope, badgeSearcher); foreach (ManagementObject queryObjBadge in getBadge.Get()) { GetBadgeDC_DTO item = new GetBadgeDC_DTO(); item.badgeID = queryObj["ID"].ToString(); try { item.activacion = DateTime.ParseExact(queryObjBadge["ACTIVATE"].ToString().Substring(0, 14), "yyyyMMddHHmmss", null); } catch { item.activacion = null; } try { item.desactivacion = DateTime.ParseExact(queryObjBadge["DEACTIVATE"].ToString().Substring(0, 14), "yyyyMMddHHmmss", null); } catch { item.desactivacion = null; } try { item.estado = queryObjBadge["STATUS"].ToString(); } catch { item.desactivacion = null; } try { item.type = int.Parse(queryObjBadge["TYPE"].ToString()); } catch { item.type = null; } try { item.badgekey = int.Parse(queryObjBadge["BADGEKEY"].ToString()); } catch { item.badgekey = 0; } tarjetas.Add(item); } #endregion persona.Badges = tarjetas; } if (persona.id == 0) { evento.PersonaConocida = false; } //throw new Exception("no se encontró una persona registrada con esos datos"); if (persona.Badges.Count > 0) { badgekey = persona.Badges[0].badgekey; badgeID = persona.Badges[0].badgeID; } else { throw new Exception("la persona no tiene un badge activo"); } } catch (Exception ex) { evento.PersonaConocida = false; //throw new Exception(ex.Message); } } else { if (evento.documento == "" || evento.documento == null) { evento.PersonaConocida = false; } } #endregion #region EVENTO EvaluacionEventoDC_DTO eval = new EvaluacionEventoDC_DTO(); SendEvent_DTO acceso = new SendEvent_DTO { source = evento.source, device = evento.device, subdevice = evento.subdevice }; ReaderPathDC_DTO lectora = new ReaderPathDC_DTO { panelID = evento.panelId, readerID = evento.readerId, }; if (evento.documento != null && evento.documento != "") { eval = GetDescripcion(tipoEvento.IB, evento); } else { eval = GetDescripcion(tipoEvento.IBNI, evento); } evento.description = eval.descripcionEvento; //EVENTO PARA LA PGR bool enviado = SendIncomingEvent(IngresoScope, evento); //LOGICA DE ACCESO if (eval.alarmaEvento == false) { acceso.isAccessGranted = true; acceso.isAccessDeny = null; acceso.badgeId = int.Parse(badgeID); SendIncomingEvent(IngresoScope, acceso); OpenDoor(IngresoScope, lectora.panelID, lectora.readerID); } else { acceso.isAccessGranted = null; acceso.isAccessDeny = true; acceso.badgeId = evento.badgeId; SendIncomingEvent(IngresoScope, acceso); if ((bool)evento.validaIdentidad == false) { #region ULTIMA UBICACION try { int intento = 1; do { ManagementObjectSearcher LastLocation = GetLastLocationByDoor(IngresoScope, int.Parse(evento.panelId), int.Parse(evento.readerId), gap); foreach (ManagementObject queryObj in LastLocation.Get()) { LastLocation_DTO lastLocation = new LastLocation_DTO(); try { lastLocation.badgeId = queryObj["BADGEID"].ToString(); } catch { lastLocation.badgeId = "0"; } try { lastLocation.eventTime = queryObj["EVENTTIME"].ToString(); } catch { lastLocation.eventTime = null; } try { lastLocation.panelId = (int)queryObj["PANELID"]; } catch { lastLocation.panelId = 0; } try { lastLocation.readerId = (int)queryObj["READERID"]; } catch { lastLocation.readerId = 0; } listLocations.Add(lastLocation); } if (listLocations.Count > 0) { resultado = "OK"; salir = true; } if (intento == intentos && salir != true) { resultado = "No se presento un evento en la ventana de tiempo requerida"; salir = true; } else { System.Threading.Thread.Sleep(timeOut); intento++; } } while (salir == false); if (resultado == "OK") { success = true; } lastEvent = new ResLastLocationDC_DTO { locations = listLocations, result = resultado, success = success }; if (lastEvent.success) { eval.descripcionEvento = eval.descripcionEvento + "|" + evento.documentoRfId; } else { eval.descripcionEvento = eval.descripcionEvento + "|NA"; } } catch (Exception ex) { throw new Exception(ex.Message); } #endregion } } if (enviado) { return(eval); } else { throw new Exception("No se pudo enviar el evento"); } #endregion }
public async Task <object> AutorizacionIngreso(SendEvent_DTO evento, int gap, int intentos, int timeOut) { return(await _reader_REP.AutorizacionIngreso(evento, gap, intentos, gap, _path, _user, _pass)); }
public async Task <object> AutorizarSalida([FromBody] SendEvent_DTO evento) { try { //Obtiene la información de la persona que esta ingresando int badgekey = 0; string badgeID = ""; GetCardHolder_DTO persona = await _cardHolder_REP_LOCAL.ObtenerPersona(evento.documento, ""); //obtiene un badgekey de la persona foreach (GetBadge_DTO badge in persona.Badges) { if (badge.estado == "1") { badgekey = badge.badgekey; badgeID = badge.badgeID; } } if (badgekey == 0) { throw new Exception("no se encontro un badge activo"); } EvaluacionEvento_DTO eval = new EvaluacionEvento_DTO(); SendEvent_DTO acceso = new SendEvent_DTO { source = evento.source, device = evento.device, subdevice = evento.subdevice }; ReaderPath_DTO lectora = new ReaderPath_DTO { panelID = evento.panelId, readerID = evento.readerId, }; if (evento.documento != null) { eval = GetDescripcion(tipoEvento.SB, evento); } else { eval = GetDescripcion(tipoEvento.SBNI, evento); } evento.description = eval.descripcionEvento; //ENVIO DE EVENTO A LA PGR bool enviado = await _reader_REP_LOCAL.EnviarEventoGenerico(evento); //EVENTO REGISTRO DE MARCACION Y ACCION acceso.isAccessGranted = true; acceso.isAccessDeny = false; acceso.badgeId = int.Parse(badgeID); await _reader_REP_LOCAL.EnviarEventoGenerico(acceso); await _reader_REP_LOCAL.AbrirPuerta(lectora); if (enviado) { return(eval); } else { throw new Exception("No se pudo enviar el evento"); } } catch (Exception ex) { object result = new { sucess = false, status = 400, data = ex.Message }; return(BadRequest(result)); } }