Files
SIG/Sistemas/SessionesActivas.aspx.vb
2020-05-27 13:58:17 -07:00

241 lines
9.6 KiB
VB.net

Imports System.Data
Imports Extensiones
Partial Class SessionesActivas
Inherits System.Web.UI.Page
Private Property RCveUsuario As String
Get
Return ViewState("RCveUsuario").ToString
End Get
Set(value As String)
ViewState("RCveUsuario") = value
End Set
End Property
ReadOnly Property UsuarioActual() As Usuario
Get
Try
'UsuarioActual = DirectCast(Session("UsuarioSIG"), Usuario)
UsuarioActual = CType(Context.Session("UsuarioSIG"), Usuario)
Catch ex As Exception
Usuario.CerrarSession()
Return Nothing
End Try
End Get
End Property
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
If Not User.Identity.IsAuthenticated OrElse UsuarioActual Is Nothing Then
Dim AuthorizeRequest As Boolean = False
Dim HuboError = False
Dim statusCode = 401
AuthorizeRequest = False
Response.StatusCode = statusCode
If Not AuthorizeRequest Then
Usuario.CerrarSession()
Response.End()
End If
End If
If UsuarioActual.CveRol <> 1 Then
Dim AuthorizeRequest As Boolean = False
Dim HuboError = False
Dim statusCode = 401
AuthorizeRequest = False
Response.StatusCode = statusCode
If Not AuthorizeRequest Then
Usuario.CerrarSession()
Response.End()
End If
End If
' Dim listacve As New List(Of String)
' listacve.Add("1815")
' Notificaciones.AlertaVentana("notificacion", listacve, timeoutseconds:=0)
' RCveUsuario = "0"
'ClsSisNotificaciones.SendNotificacionERP(100, "Titulo", "Hola Mundo", 1)
CargaDatos("")
End If
End Sub
Private Sub CargaDatos(filtros As String)
Dim objUsuarios As New ClsSisUsuarios
objUsuarios.GetUsuarios(-1, -1, -1)
Dim dtU As DataTable = objUsuarios.DtResultados
dtU.Columns.Add("FechaSLogin", System.Type.GetType("System.DateTime"))
dtU.Columns.Add("RemoteIpAddres", System.Type.GetType("System.String"))
dtU.Columns.Add("LastPostback", System.Type.GetType("System.DateTime"))
dtU.Columns.Add("Modulo", System.Type.GetType("System.String"))
dtU.Columns.Add("SessionID", System.Type.GetType("System.String"))
Dim dtF As DataTable = dtU.Clone
Dim objlist As List(Of ADSSession.ADSSessionObj) = ADSSession.ADSSessionConfig.SessionManager(ADSSession.OpcionSession.getListasession)
For Each user As ADSSession.ADSSessionObj In objlist
Dim row As DataRow = dtU.FiltroPrimero($"CveUsuario={user.CveUsuario} AND CveEmpresa={user.CveEmpresa}")
If Not IsNothing(row) Then
row("FechaSLogin") = user.FechaLogin
row("RemoteIpAddres") = user.IpAddres
row("LastPostback") = user.LastPostback
row("Modulo") = user.Modulo
dtF.Rows.Add(row.ItemArray())
End If
Next
dtU.Dispose()
Dim GroupBy1 As String() = {"CveEmpresa", "Empresa"}
DdlEmpresa.DataSource = dtF.FiltraParametros("", "", {"CveEmpresa", "Empresa"})
DdlEmpresa.DataBind()
dtF = dtF.GroupByDT(filtros, "", {GroupBy1}, Nothing, Nothing,)
GVDatos.DataSource = dtF
GVDatos.DataBind()
objUsuarios.Dispose()
End Sub
Protected Sub GVDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim CveUsuario As Integer = e.Row.DataKey("CveUsuario").ToEntero()
If CveUsuario > 0 Then
Else
e.Row.Cells(0).Visible = False
e.Row.Cells(1).Visible = False
e.Row.Cells(3).Visible = False
e.Row.Cells(2).Attributes.Add("colspan", "4")
e.Row.CssClass = "Titulos"
e.Row.FCLinkButton("LnkEnviarMensaje").Visible = False
e.Row.FCLinkButton("LnkQuitar").Visible = False
End If
' Dim info As ADSSession.GlobalSessionInfo = ADSSession.MySessionInfo.GlobalSessions.FirstOrDefault(Function(M) M.CveUsuario = e.Row.DataKey("CveUsuario").ToEntero() AndAlso M.CveEmpresa = e.Row.DataKey("CveEmpresa").ToEntero())
' If IsNothing(info) Then
' e.Row.Visible = False
' End If
End If
End Sub
Protected Sub LnkFiltrar_Click(sender As Object, e As EventArgs)
Dim filtrosbuilder As New StringBuilder
Dim Prefix As String = ""
Dim idEmpresas As String = DdlEmpresa.GetSelectedValues("'", "'")
If idEmpresas.Length > 0 Then
filtrosbuilder.Append(String.Format("{1} CveEmpresa IN({0})", idEmpresas, Prefix))
Prefix = " AND "
End If
CargaDatos(filtrosbuilder.ToString())
End Sub
Protected Sub LnkQuitar_Click(sender As Object, e As EventArgs)
Dim gvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
'ADSSession.MySessionInfo.GlobalSessions.RemoveAll(Function(M) M.CveUsuario = gvRow.DataKey("CveUsuario").ToEntero())
Dim cveUsuario As Integer = gvRow.DataKey("CveUsuario").ToEntero()
Dim CveEmpresa As Integer = gvRow.DataKey("CveEmpresa").ToEntero()
ADSSession.ADSSessionConfig.SessionManager(ADSSession.OpcionSession.CerrarSession, CveEmpresa:=CveEmpresa, CveUsuario:=cveUsuario)
'For Each user As ADSSession.ADSSessionObj In objlist
' If cveUsuario = user.CveUsuario AndAlso CveEmpresa = user.CveEmpresa Then
' Dim aspsig As String = user.ASPSIG '"94C6AC57E8599390A4B7B8AB41FEABEF466D9B31120BE06D78110E66265F1ACC5616297BF3B88EDCEE71EBCFE35484308F62C8017EAC29FB3F0FB45CEC09E8F03DFBB4A4DD890D45755B7A30185C6D01F20AEFA74BE3A25FD12D536B20DCB8D9940A3D95"
' Dim sessionID As String = user.SessionID
' Dim url = ("http://localhost:85/Inicio.aspx?logout=1")
' Dim cookie As String = String.Format("ASP.NET_SessionId={0};.ASPXSIG={1}", sessionID, aspsig)
' sendURL(url, cookie)
' sendURL("http://caudillo:85/Inicio.aspx?logout=1", cookie)
' End If
'Next
CargaDatos("")
End Sub
Private Function sendURL(ByVal URL As String, ByVal Optional Cookie As String = "", ByVal Optional maxTimeMilliseconds As Integer = 120000) As String
Dim resultado As String = ""
Try
Dim request As Net.HttpWebRequest = CType(Net.HttpWebRequest.Create(URL), Net.HttpWebRequest)
request.Timeout = maxTimeMilliseconds
request.Method = "POST"
request.ContentType = "text/xml; charset=utf-8"
If Not String.IsNullOrEmpty(Cookie) Then
request.Headers.Add("Cookie", Cookie)
End If
Using stream As IO.Stream = request.GetRequestStream()
Using stmw As IO.StreamWriter = New IO.StreamWriter(stream)
stmw.Write("")
End Using
End Using
Dim response As Net.WebResponse = CType(request.GetResponse(), Net.WebResponse)
Dim sr As IO.StreamReader = New IO.StreamReader(response.GetResponseStream())
resultado = sr.ReadToEnd()
sr.Close()
Catch ex As Exception
'Extenciones.ApplicationParameter.GuardaLogEx(ex, $"SOAPAction : {SOAPAction} XML : {xml}")
End Try
Return resultado
End Function
Protected Sub LnkEnviarMensaje_Click(sender As Object, e As EventArgs)
Dim gvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
RCveUsuario = gvRow.DataKey("CveUsuario")
RegistraScript("$(""#DivMensaje"").modal();")
End Sub
Protected Sub LnkEnviar_Click(sender As Object, e As EventArgs)
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
Private Sub VerGC()
Dim myGCCol As MyGCCollectClass = New MyGCCollectClass()
Console.WriteLine("The highest generation is {0}", GC.MaxGeneration)
myGCCol.MakeSomeGarbage()
Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol))
Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(False))
GC.Collect(0)
Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol))
Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(False))
GC.Collect(2)
Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol))
Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(False))
Console.Read()
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
Private Sub LBGC_Click(sender As Object, e As EventArgs) Handles LBGC.Click
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
Class MyGCCollectClass
Public Sub MakeSomeGarbage()
Dim vt As Version
For i As Integer = 0 To 1000 - 1
vt = New Version()
Next
End Sub
End Class
End Class