/////////////////////////////////////////////////////////// public bool SendMessage(string origin, string destiny, string message) { if (!current_config.Modules.ContainsKey(destiny)) { return(false); } UBSLib.ModuleInfo module_info = current_config.Modules[destiny]; if (module_info == null) { return(false); } if (module_info is UBSLib.ModuleInfoLocal) { // local message UBSLib.UBSModule module = local_modules[module_info.Id]; UBSLib.UBSMessage message_obj = new UBSLib.UBSMessage(destiny, message); message_obj.OriginId = origin; module.HandleMessages(message_obj); } else if (module_info is UBSLib.ModuleInfoRemote) { // do remote call (not implemented) // can be done through two bridge tcp/ip client/server modules new NotImplementedException("Servicio aun no disponible"); } return(true); }
////////////////////////////////////////////////////////////////////////////////// public override void HandleMessages(UBSLib.UBSMessage message) { string strMessage = message.ToString(); //Parametros del mensaje string[] strParams = strMessage.Split('#'); // if (strParams[0] == watchdogVar) { lastConection = DateTime.Now; } }
////////////////////////////////////////////////////////////////////////////////// public override void HandleMessages(UBSLib.UBSMessage message) { if (Status != UBSLib.UBSModuleStatus.Closing || Status != UBSLib.UBSModuleStatus.Closed) { m_alarmas.Communication = this.GetGlobalParameter("Communication").ToString(); string strMessage = message.ToString(); //Parametros del mensaje string[] strParams = strMessage.Split('#'); // //Si el primer valor del mensaje es una de los identificadores de las variables compartida se aplica ese valor if (m_alarmas.ContainsId(strParams[0])) { switch (m_alarmas.Communication) { case "message": break; case "twincat": m_alarmas.SetBlock(strParams[0], Convert.ToUInt32(strParams[1])); break; default: Notify("La comunicación configurada en el modulo Alarma no existe: " + m_alarmas.Communication, true, false); break; } } else { //Si solo se envia un codigo, significa que es la alarma a activar/desactivar //El segundo valor del mensaje debe ser el true o false por si se quiere activar o desactivar if (bool.Parse(strParams[1])) //Activar { m_alarmas.ActivarAlarma(strParams[0]); } else { //Desactivar if (m_alarmas.AlarmaActiva(strParams[0])) { m_alarmas.DesactivarAlarma(strParams[0]); } } } } }
////////////////////////////////////////////////////////////////////////////////// public override void HandleMessages(UBSLib.UBSMessage message) { string strMessage = message.ToString(); //Mensajes string[] strParams = strMessage.Split('#'); if (strMessage.StartsWith("insert#")) { try { string Tabla = strParams[1]; string vars = strParams[2]; string vals = strParams[3]; if (strParams.Length == 4) { if (!db.insert(Tabla, vars, vals)) { Error("No se ha podido llevar a cabo el proceso Insert en la base de datos.", true, false); } } else { string DB = strParams[4]; if (!db.insert(Tabla, vars, vals, DB)) { Error("No se ha podido llevar a cabo el proceso Insert en la base de datos.", true, false); } } } catch (Exception e) { Error("La estructura de la llamada para el proceso Insert está mal estructurada. " + e.Message, true, false); } } if (strMessage.StartsWith("update#")) { try { string Tabla = strParams[1]; string sets = strParams[2]; string cond = strParams[3]; if (!db.update(Tabla, sets, cond)) { Error("No se ha podido llevar a cabo el proceso Update en la base de datos.", true, false); } } catch (Exception e) { Error("La estructura de la llamada para el proceso Update está mal estructurada. " + e.Message, true, false); } } if (strMessage.StartsWith("delete#")) { try { string Tabla = strParams[1]; string cond = strParams[2]; if (strParams.Length == 3) { if (!db.delete(Tabla, cond)) { Error("No se ha podido llevar a cabo el proceso Delete en la base de datos.", true, false); } } else { string DB = strParams[3]; if (!db.delete(Tabla, cond, DB)) { Error("No se ha podido llevar a cabo el proceso Delete en la base de datos.", true, false); } } } catch (Exception e) { Error("La estructura de la llamada para el proceso Delete está mal estructurada. " + e.Message, true, false); } } if (strMessage.StartsWith("select#")) { try { string Variable = strMessage; string Tabla = strParams[1]; string vars = strParams[2]; string where = strParams[3]; List <string> listVal = new List <string>(); if (strParams.Length == 4) { if (!db.select(Tabla, vars, where, Variable)) { Error("No se ha podido llevar a cabo el proceso Select en la base de datos.", true, false); } } else { string DB = strParams[4]; if (!db.select(Tabla, vars, where, DB, Variable)) { Error("No se ha podido llevar a cabo el proceso Select en la base de datos.", true, false); } } } catch (Exception e) { Error("La estructura de la llamada para el proceso Select está mal estructurada. " + e.Message, true, false); } } if (strMessage.StartsWith("free#")) { try { List <string> listVal = new List <string>(); string Variable = strMessage; string text = strParams[1]; if (strParams.Length == 3) { string DB = strParams[2]; if (!db.free(text, DB, Variable)) { Error("No se ha podido llevar a cabo el texto libre en la base de datos.", true, false); } } else if (strParams.Length == 2) { if (!db.free(text, Variable)) { Error("No se ha podido llevar a cabo el texto libre en la base de datos.", true, false); } } else { Error("Los parametros de la llamada a la base de datos no concuerdan.", true, false); } } catch (Exception e) { Error("La estructura de la llamada a la base de datos de forma libre está mal estructurada. " + e.Message, true, false); } } }