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