public void Poll() { if (this.Connection.State != System.Data.ConnectionState.Open) this.Connection.Open(); qGen.Where WhereUsuario = new qGen.Where(qGen.AndOr.Or); WhereUsuario.AddWithValue("id_destinatario", Lbl.Sys.Config.Actual.UsuarioConectado.Id); WhereUsuario.AddWithValue("id_destinatario", null); if (Lbl.Sys.Config.Actual.UsuarioConectado.Persona.Grupo != null) WhereUsuario.AddWithValue("id_grupo", Lbl.Sys.Config.Actual.UsuarioConectado.Persona.Grupo.Id); if (Lbl.Sys.Config.Actual.UsuarioConectado.Persona.SubGrupo != null) WhereUsuario.AddWithValue("id_grupo", Lbl.Sys.Config.Actual.UsuarioConectado.Persona.SubGrupo.Id); qGen.Select SelMensajesSinLeer = new qGen.Select("sys_mensajes"); SelMensajesSinLeer.WhereClause = new qGen.Where(); //SelMensajesSinLeer.WhereClause.AddWithValue("estacion_recibe", Lfx.Environment.SystemInformation.MachineName); SelMensajesSinLeer.WhereClause.AddWithValue("id_mensaje", qGen.ComparisonOperators.GreaterThan, this.LastMessageId); SelMensajesSinLeer.WhereClause.AddWithValue(WhereUsuario); SelMensajesSinLeer.Order = "id_mensaje"; System.Data.DataTable TablaMensajes; try { TablaMensajes = this.Connection.Select(SelMensajesSinLeer); foreach (System.Data.DataRow Mensaje in TablaMensajes.Rows) { INotificacion Res = new NotificacionRegistro(this.Connection, (Lfx.Data.Row)(Mensaje)); this.LastMessageId = System.Convert.ToInt32(Mensaje["id_mensaje"]); string Destino = System.Convert.ToString(Mensaje["destino"]); if (Lfx.Components.Manager.ComponentesCargados.ContainsKey(Destino)) { // Lo notifico via IPC Lfx.Workspace.Master.RunTime.Notify(Destino, Res); // Se lo notifico directamente al componente if (Lfx.Components.Manager.ComponentesCargados[Destino].Funciones.ContainsKey("Notify")) { Lfx.Components.Manager.ComponentesCargados[Destino].Funciones["Notify"].Instancia.Arguments = new object[] { Res }; Lfx.Components.Manager.ComponentesCargados[Destino].Funciones["Notify"].Run(); } } else { Lfx.Workspace.Master.RunTime.Notify(Destino, Res); } } qGen.Insert ActualizarEstado = new qGen.Insert("sys_mensajeria"); ActualizarEstado.OnDuplicateKeyUpdate = true; ActualizarEstado.Fields.AddWithValue("id_usuario", Lbl.Sys.Config.Actual.UsuarioConectado.Id); ActualizarEstado.Fields.AddWithValue("estacion", Lfx.Environment.SystemInformation.MachineName); ActualizarEstado.Fields.AddWithValue("nombre", Lbl.Sys.Config.Actual.UsuarioConectado.Nombre); ActualizarEstado.Fields.AddWithValue("fecha", qGen.SqlFunctions.Now); if (this.LastMessageId > 0) ActualizarEstado.Fields.AddWithValue("id_ultimomensaje", this.LastMessageId); this.Connection.Execute(ActualizarEstado); } catch (Exception ex) { System.Console.WriteLine(ex.Message); if (Lfx.Environment.SystemInformation.DesignMode) throw; else return; } }
public void Poll() { if (this.Connection.State != System.Data.ConnectionState.Open) { this.Connection.Open(); } qGen.Where WhereUsuario = new qGen.Where(qGen.AndOr.Or); WhereUsuario.AddWithValue("id_destinatario", Lbl.Sys.Config.Actual.UsuarioConectado.Id); WhereUsuario.AddWithValue("id_destinatario", null); if (Lbl.Sys.Config.Actual.UsuarioConectado.Persona.Grupo != null) { WhereUsuario.AddWithValue("id_grupo", Lbl.Sys.Config.Actual.UsuarioConectado.Persona.Grupo.Id); } if (Lbl.Sys.Config.Actual.UsuarioConectado.Persona.SubGrupo != null) { WhereUsuario.AddWithValue("id_grupo", Lbl.Sys.Config.Actual.UsuarioConectado.Persona.SubGrupo.Id); } qGen.Select SelMensajesSinLeer = new qGen.Select("sys_mensajes"); SelMensajesSinLeer.WhereClause = new qGen.Where(); //SelMensajesSinLeer.WhereClause.AddWithValue("estacion_recibe", Lfx.Environment.SystemInformation.MachineName); SelMensajesSinLeer.WhereClause.AddWithValue("id_mensaje", qGen.ComparisonOperators.GreaterThan, this.LastMessageId); SelMensajesSinLeer.WhereClause.AddWithValue(WhereUsuario); SelMensajesSinLeer.Order = "id_mensaje"; System.Data.DataTable TablaMensajes; try { TablaMensajes = this.Connection.Select(SelMensajesSinLeer); foreach (System.Data.DataRow Mensaje in TablaMensajes.Rows) { INotificacion Res = new NotificacionRegistro(this.Connection, (Lfx.Data.Row)(Mensaje)); this.LastMessageId = System.Convert.ToInt32(Mensaje["id_mensaje"]); string Destino = System.Convert.ToString(Mensaje["destino"]); if (Lfx.Components.Manager.ComponentesCargados.ContainsKey(Destino)) { // Lo notifico via IPC Lfx.Workspace.Master.RunTime.Notify(Destino, Res); // Se lo notifico directamente al componente Lfx.Components.Manager.ComponentesCargados[Destino].ComponentInstance.Do("Notify", new object[] { Res }); } else { Lfx.Workspace.Master.RunTime.Notify(Destino, Res); } } qGen.Insert ActualizarEstado = new qGen.Insert("sys_mensajeria"); ActualizarEstado.OnDuplicateKeyUpdate = true; ActualizarEstado.ColumnValues.AddWithValue("id_usuario", Lbl.Sys.Config.Actual.UsuarioConectado.Id); ActualizarEstado.ColumnValues.AddWithValue("estacion", Lfx.Environment.SystemInformation.MachineName); ActualizarEstado.ColumnValues.AddWithValue("nombre", Lbl.Sys.Config.Actual.UsuarioConectado.Nombre); ActualizarEstado.ColumnValues.AddWithValue("fecha", new qGen.SqlExpression("NOW()")); if (this.LastMessageId > 0) { ActualizarEstado.ColumnValues.AddWithValue("id_ultimomensaje", this.LastMessageId); } this.Connection.ExecuteNonQuery(ActualizarEstado); } catch (Exception ex) { System.Console.WriteLine(ex.Message); if (Lfx.Environment.SystemInformation.DesignMode) { throw; } else { return; } } }