static int _refCount = 0; // Contador de referencias usadas por los translators. Si llega a cero se detiene el thread y se libera la referencia #region Singleton public static PoolGetConnStatus GetInstance() { if (_instance == null) { _instance = new PoolGetConnStatus(); } return(_instance); }
public void subRefCount() { _refCount--; Helpers.GetInstance().DoLog("Resto refCount de PoolGetConnStatus =" + _refCount); Thread.Sleep(100); if (_refCount == 0) { Stop(); // Detiene el thread de verificacion Thread.Sleep(500); _instance = null; // Hace null la referencia para que un nuevo GetInstance lance todo de nuevo Helpers.GetInstance().DoLog("Instance de PoolGetConnStatus es NULL"); } }
/// <summary> /// Mensaje para notificar la dada de baja de Panel. /// Solo se envia deletePanel si realmente se dio de baja y no existe en Lenel- /// Ademas usa DC para eliminar el usuario asociado al panel. /// </summary> public void deletePanel(int PanelID, string panelName) { PoolGetConnStatus.GetInstance().subRefCount(); // Para detener el thread y liberar memoria en caso de ser el ultimo panel que se da de baja. PoolGetAlarm.GetInstance().subRefCount(); PoolGetAcceso.GetInstance().subRefCount(); PoolSetAlarma.GetInstance().subRefCount(); PoolSetAcceso.GetInstance().subRefCount(); System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); string orgID = Helpers.GetInstance().MainOrgID.ToString(); // El configurado en el registro try { //Helpers.GetInstance().mutexTCP_ACCESS.WaitOne(); try { string errDesc = ""; int errCode = -1; if (!WebServiceAPI.GetInstance().ExistePanelEnOnGuard(PanelID.ToString(), out errDesc, out errCode)) { WebServiceAPI.GetInstance().DeleteDevice(PanelID.ToString(), orgID, out errDesc, out errCode); if (errCode == (int)StatusCode.OK) { Employee emp = WebServiceAPI.GetInstance().ObtenerEmpleadoAsociadoAHH(panelName, out errDesc, out errCode); if (emp != null) { Helpers.GetInstance().DoLog("Va a borrar el empleado " + emp.Nombre + " " + emp.Apellido + " con personid: " + emp.PersonID.ToString() + " asociado al panelID: " + PanelID.ToString() + " llamado:" + panelName); WebServiceAPI.GetInstance().EliminarEmpleado(emp.PersonID, out errDesc, out errCode); } else { Helpers.GetInstance().DoLog("emp es NULL en deletePanel. NO borró el empleado asociado al panel " + PanelID.ToString()); } } } } catch (Exception ex) { Helpers.GetInstance().DoLog("EXCEPCION en deletePanel: " + ex.Message); } } catch (Exception ex) { Helpers.GetInstance().DoLog("EXCEPCION en deletePanelMUTEX: " + ex.Message); } //finally //{ // Helpers.GetInstance().mutexTCP_ACCESS.ReleaseMutex(); //} }
public static List <string> ListaPanelNames = new List <string>(); // Lista de todos los PanelNames que levanta este CommServer.. //string m_Name; //int m_PanelID; // Constructor de la clase managed asociada al Translator. // Hay una instancia por cada Translator, y por lo tanto una por cada Panel. public ManagedAccessControl() { PoolGetConnStatus.GetInstance(); // Lanza el thread de actualizacion de connStatusgeneral PoolGetConnStatus.GetInstance().addRefCount(); // Agrega un conteo de referencia PoolGetAcceso.GetInstance(); // Idem get accesos PoolGetAcceso.GetInstance().addRefCount(); PoolGetAlarm.GetInstance(); // Idem get Alarmas PoolGetAlarm.GetInstance().addRefCount(); PoolSetAcceso.GetInstance(); PoolSetAcceso.GetInstance().addRefCount(); // Idem setAccesos PoolSetAlarma.GetInstance(); // Idem SetAlarmas PoolSetAlarma.GetInstance().addRefCount(); }
/// <summary> /// getConnStatus: obtener el estado de la conexion del Handheld asociado al v_panelID /// YES: Conectado /// NO: No conectado /// </summary> /// <param name="v_PanelID"></param> /// <returns></returns> public string getConnStatus(int v_PanelID, int m_IsDownloadInProgress) { if (PoolGetConnStatus.GetInstance().getConnStatusMobile(v_PanelID)) { return("YES"); } else { return("NO"); } //string res = ""; //string deviceID = v_PanelID.ToString(); //string orgID = Helpers.GetInstance().MainOrgID.ToString(); //Helpers.GetInstance().mutexTCP_ACCESS.WaitOne(); //try //{ // string errDesc = ""; // int errCode = -1; // res = WebServiceAPI.GetInstance().GetConnStatus(deviceID, orgID, out errDesc, out errCode); //} //catch (Exception ex) //{ // Helpers.GetInstance().DoLog("EXCEPCION en getConnStatus: " + ex.Message); // res = "FAIL"; //} //finally //{ // Helpers.GetInstance().mutexTCP_ACCESS.ReleaseMutex(); //} //Thread.Sleep(500); //return res.Trim(); }