-- FIX. SIGNALR HUB NOTIFIFICACIONES
This commit is contained in:
@@ -150,6 +150,11 @@ Public Class ClsSisNotificaciones
|
||||
#End Region
|
||||
|
||||
#Region "N O T I F I C A C I O N E S"
|
||||
Public Shared Sub EnviarAlerta(Titulo As String, Mensaje As String, CveUsuario As String, Optional Tipo As TipoNotificacion = TipoNotificacion.AlertaVentanaNoOcultar, Optional TimeOut As Integer = 0)
|
||||
Dim hub = GlobalHost.ConnectionManager.GetHubContext(Of Notificaciones)()
|
||||
hub.Clients.Client(Notificaciones.UsuariosConexiones(CveUsuario)).alertaVentana(Titulo, Mensaje, DirectCast(Tipo, Integer), TimeOut)
|
||||
End Sub
|
||||
|
||||
|
||||
Public Sub DispararNotificacion(CveNotificacion As Integer, CvesFiltro As List(Of Object), CveEmpresa As Integer)
|
||||
_CveNotificacion = CveNotificacion
|
||||
@@ -1814,7 +1819,7 @@ Public Class ClsSisNotificaciones
|
||||
'Next
|
||||
Dim lista As New List(Of String)
|
||||
lista.Add(CveUsuario.ToString())
|
||||
Notificaciones.AlertaVentana(Mensaje, lista, Titulo, timeoutseconds)
|
||||
'Notificaciones.AlertaVentana(Mensaje, lista, Titulo, timeoutseconds)
|
||||
End Sub
|
||||
'Public Sub SendNotificacionGPS(context As IHubContext, CveUsuario As Integer, JsonParams As String)
|
||||
' context.Clients.All.DisparaNotificacionUsuario(CveUsuario,)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Option Strict Off
|
||||
Imports System.Collections.Concurrent
|
||||
Imports Extensiones
|
||||
Imports Microsoft.AspNet.SignalR
|
||||
|
||||
@@ -13,36 +14,55 @@ Public Enum TipoNotificacion As Integer
|
||||
AlertaVentanaNoOcultar = 1
|
||||
End Enum
|
||||
Public Class Notificaciones
|
||||
Inherits Hub
|
||||
Public Overrides Function OnConnected() As System.Threading.Tasks.Task
|
||||
Inherits Hub
|
||||
|
||||
Public Shared UsuariosConexiones As ConcurrentDictionary(Of String, String) = New ConcurrentDictionary(Of String, String)
|
||||
|
||||
Public Overrides Function OnConnected() As System.Threading.Tasks.Task
|
||||
NotificarConexion()
|
||||
Return MyBase.OnConnected()
|
||||
End Function
|
||||
|
||||
Public Overrides Function OnReconnected() As System.Threading.Tasks.Task
|
||||
Public Overrides Function OnReconnected() As System.Threading.Tasks.Task
|
||||
NotificarConexion()
|
||||
Return MyBase.OnReconnected()
|
||||
End Function
|
||||
Public Overrides Function OnDisconnected(stopCalled As Boolean) As Threading.Tasks.Task
|
||||
Return MyBase.OnDisconnected(stopCalled)
|
||||
End Function
|
||||
End Function
|
||||
|
||||
Public Sub NotificarConexion()
|
||||
If Context.User.Identity.IsAuthenticated Then
|
||||
Dim ConnectionId As String = Context.ConnectionId
|
||||
Dim CveUsuario As String = Context.User.Identity.Name
|
||||
If UsuariosConexiones.ContainsKey(CveUsuario) Then
|
||||
If UsuariosConexiones(CveUsuario) <> Context.ConnectionId Then
|
||||
UsuariosConexiones.TryUpdate(CveUsuario, Context.ConnectionId, UsuariosConexiones(CveUsuario))
|
||||
End If
|
||||
Else
|
||||
If CveUsuario.ToEntero > 0 Then
|
||||
UsuariosConexiones.TryAdd(CveUsuario, ConnectionId)
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub TestMessage(message As String)
|
||||
Clients.All.testMessage(message)
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
Public Shared Sub AlertaVentana(Message As String, Para As String, Optional Titulo As String = "", Optional timeoutseconds As Integer = 5, Optional Tipo As TipoNotificacion = TipoNotificacion.AlertaVentanaNoOcultar)
|
||||
Public Sub AlertaVentana(Message As String, Para As String, Optional Titulo As String = "", Optional timeoutseconds As Integer = 5, Optional Tipo As TipoNotificacion = TipoNotificacion.AlertaVentanaNoOcultar)
|
||||
Dim lPara As New List(Of String)
|
||||
lPara.Add(Para)
|
||||
AlertaVentana(Message, lPara, Titulo, timeoutseconds, Tipo)
|
||||
End Sub
|
||||
Public Shared Sub AlertaVentana(Message As String, Para As List(Of String), Optional Titulo As String = "", Optional timeoutseconds As Integer = 5, Optional Tipo As TipoNotificacion = TipoNotificacion.AlertaVentanaNoOcultar)
|
||||
Public Sub AlertaVentana(Message As String, Para As List(Of String), Optional Titulo As String = "", Optional timeoutseconds As Integer = 5, Optional Tipo As TipoNotificacion = TipoNotificacion.AlertaVentanaNoOcultar)
|
||||
If (Para IsNot Nothing) AndAlso Para.Count > 0 Then
|
||||
Dim Clients As Hubs.IHubConnectionContext(Of Object) = GlobalHost.ConnectionManager.GetHubContext(Of Notificaciones)().Clients
|
||||
Clients.Users(Para).AlertaVentana(Titulo, Message, DirectCast(Tipo, Integer), timeoutseconds)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Public Shared Sub AlertaVentana(Message As String, Para As List(Of String), Optional Titulo As String = "", Optional timeoutseconds As Integer = 5, Optional Tipo As TipoNotificacion = TipoNotificacion.AlertaVentanaNoOcultar)
|
||||
' Dim Clients As Hubs.IHubConnectionContext(Of Object) = GlobalHost.ConnectionManager.GetHubContext(Of Notificaciones)().Clients
|
||||
' Clients.Users(Para).AlertaVentana(Titulo, Message, DirectCast(Tipo, Integer), timeoutseconds)
|
||||
'End Sub
|
||||
End Class
|
||||
Public Class MyhubUserIdProvider
|
||||
Implements IUserIdProvider
|
||||
|
||||
@@ -14,16 +14,16 @@ var NotificacionesADS = function () {
|
||||
if (Notification.permission !== 'denied') {
|
||||
Notification.requestPermission(function (permission) {
|
||||
// If the user accepts, let's create a notification
|
||||
//if (permission === "granted") {
|
||||
//}
|
||||
if (permission === "granted") {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------- Eventos ----------------------------------------------------------------------
|
||||
var AlertaVentana = function (Titulo, Mensaje, Tipo, timeoutseconds, Opciones) {
|
||||
var AlertaVentana = function (Titulo, Mensaje, Tipo, timeoutseconds) {
|
||||
console.log(Mensaje);
|
||||
let obj = { metodo: "AlertaVentana", titulo: Titulo, mensaje: Mensaje, timeout: timeoutseconds, tipo: Tipo, opciones: Opciones, tick: (new Date()).getTime() };
|
||||
let obj = { metodo: "AlertaVentana", titulo: Titulo, mensaje: Mensaje, timeout: timeoutseconds, tipo: Tipo, tick: (new Date()).getTime() };
|
||||
let myjson = JSON.stringify(obj);
|
||||
localStorage.setItem("ADSNotificaciones", myjson);
|
||||
execAlertaVentana(obj);
|
||||
@@ -117,11 +117,11 @@ var NotificacionesADS = function () {
|
||||
var proxy = $.connection.notificaciones;
|
||||
/*$.connection.hub.url = '/signalr';*/
|
||||
$.connection.hub.disconnected(function () {
|
||||
console.log(' (SignalR) diconnected');
|
||||
console.log(' (SignalR) disconnected');
|
||||
signalrconectionStar(1200);
|
||||
});
|
||||
|
||||
proxy.client.AlertaVentana = AlertaVentana;
|
||||
proxy.client.alertaVentana = AlertaVentana;
|
||||
|
||||
proxy.client.Execstring = Execstring;
|
||||
|
||||
@@ -139,7 +139,7 @@ var NotificacionesADS = function () {
|
||||
nointentos = nointentos + 1;
|
||||
if (nointentos < maxintentos) {
|
||||
$.connection.hub.start().done(function () { console.log('(SignalR)Bienvenido'); nointentos = 0; })
|
||||
.fail(function () { console.log(' (SignalR) no conectado (Intento:' + nointentos + ')'); signalrconectionStar(12000); });
|
||||
.fail(function () { console.log(' (SignalR) no conectado (Intento:' + nointentos + ')'); signalrconectionStar(1200); });
|
||||
}
|
||||
}, TimeOut);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
Imports System.Data
|
||||
Imports Extensiones
|
||||
Imports Microsoft.AspNet.SignalR
|
||||
|
||||
Partial Class SessionesActivas
|
||||
Inherits System.Web.UI.Page
|
||||
@@ -189,11 +190,8 @@ Partial Class SessionesActivas
|
||||
RegistraScript("$(""#DivMensaje"").modal();")
|
||||
End Sub
|
||||
Protected Sub LnkEnviar_Click(sender As Object, e As EventArgs)
|
||||
ClsSisNotificaciones.EnviarAlerta("Aviso", TxtMensaje.Text.Trim(), RCveUsuario, Tipo:=TipoNotificacion.ToastInformacionB)
|
||||
|
||||
Dim lista As New List(Of String)
|
||||
lista.Add(RCveUsuario)
|
||||
'Notificaciones.AlertaVentana(TxtMensaje.Text, lista)
|
||||
Notificaciones.AlertaVentana(TxtMensaje.Text, lista, timeoutseconds:=0)
|
||||
RegistraScript($"$(""#DivMensaje"").modal('hide');console.log('{Decripta(Context.User.Identity.Name)}')")
|
||||
End Sub
|
||||
|
||||
|
||||
Reference in New Issue
Block a user