117 lines
5.2 KiB
VB.net
117 lines
5.2 KiB
VB.net
Imports System.Data
|
|
Imports Extensiones
|
|
Imports System.Data.SqlClient
|
|
Imports Microsoft.AspNet.SignalR
|
|
Imports System.IO
|
|
Imports System.Net.Http
|
|
Imports Newtonsoft.Json.Linq
|
|
|
|
Partial Class PortalGPS_Penske
|
|
Inherits System.Web.UI.Page
|
|
Private Sub PortalGPS_Penske_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
EnviarDatos()
|
|
End If
|
|
End Sub
|
|
Private Sub EnviarDatos()
|
|
Dim ObjTsoft As New ClsTSoft
|
|
Try
|
|
GuardaLog($"Empecé Task. Fecha: {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}")
|
|
If ObjTsoft.GetInfoWSPenske() AndAlso ObjTsoft.DtResultados.Rows.Count > 0 Then
|
|
Dim Direcciones As JArray = ConsultarDirecciones(ObjTsoft.DtResultados)
|
|
For Each Dir As JObject In Direcciones
|
|
IterarWS(ObjTsoft.DtResultados.Rows(Dir("Indice").ToEntero()), Dir("Direccion").ToString())
|
|
Next
|
|
End If
|
|
Catch ex As Exception
|
|
GuardaLog(ex.ToString())
|
|
Finally
|
|
GuardaLog($"Terminé Task, se reportaron: {ObjTsoft.DtResultados.Rows.Count} registros. Fecha: {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}")
|
|
ObjTsoft.Dispose()
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub IterarWS(row As DataRow, direccion As String)
|
|
Try
|
|
Dim ws As New WSPenske.ReceiveGPSInfo
|
|
Dim info As New WSPenske.GPSInfo
|
|
info.Proveedor = row("Proveedor").ToString
|
|
info.Latitud = row("Lat").ToString
|
|
info.Longitud = row("Lng").ToString
|
|
info.NumUnidad = row("NoEconomico").ToString
|
|
info.NumRemolque = row("NumeroRemolque").ToString
|
|
info.Velocidad = row("Velocidad").ToString
|
|
info.Placas = row("PlacasVehiculo").ToString
|
|
info.Trackingnumber = row("TrackingNumber").ToString
|
|
info.Ubicacion = direccion
|
|
info.FechaHoraEvento = row("FechaTrama").ToString
|
|
info.FechaRecepcion = DateTime.Now.AddMinutes(120)
|
|
info.Username = row("Usuario").ToString
|
|
info.Password = row("PWD").ToString
|
|
Dim Protocol As New WSPenske.Protocolo
|
|
Protocol = ws.ReceiveGPSInformation_Objeto(info)
|
|
GuardaLog($"Se envio informacion del vehículo: {row("NoEconomico").ToString}. Processed: {Protocol.Processed}. Message: {Protocol.Message}. Fecha Recepcion: {Protocol.ReceptionDate.ToString("dd/MM/yyyy HH:mm:ss")} ")
|
|
|
|
Catch ex As Exception
|
|
GuardaLog(ex.ToString())
|
|
End Try
|
|
End Sub
|
|
Protected Sub TimerNoti_Tick(sender As Object, e As EventArgs) Handles TimerNoti.Tick
|
|
EnviarDatos()
|
|
End Sub
|
|
Public Function ConsultarDirecciones(Dt As DataTable) As JArray
|
|
Dim retorno As JArray = Nothing
|
|
Dim posicionesArray = New JArray(From Row As DataRow In Dt
|
|
Let index = Dt.Rows().IndexOf(Row)
|
|
Select New JObject(
|
|
New JProperty("indice", index),
|
|
New JProperty("cveTrama", -1),
|
|
New JProperty("lat", Row("Lat").ToString.ToDouble),
|
|
New JProperty("lon", Row("Lng").ToString.ToDouble)
|
|
))
|
|
|
|
Dim Base64array = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(posicionesArray.ToString()))
|
|
|
|
Using wc As New HttpClient()
|
|
Try
|
|
Dim Url = New Uri($"{ClsPaginas.UrlDirecciones}nominatim/reverseMultiple.php")
|
|
Dim FormStuff = String.Format("formato=json&posiciones={0}", Base64array)
|
|
Dim content = New StringContent(FormStuff, Encoding.UTF8, "application/x-www-form-urlencoded")
|
|
Dim response = wc.PostAsync(Url, content).Result
|
|
Dim result = response.Content.ReadAsStringAsync().Result
|
|
retorno = JArray.Parse(result)
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al obtener las direcciones", ex)
|
|
End Try
|
|
End Using
|
|
Return retorno
|
|
End Function
|
|
|
|
|
|
Public Sub GuardaLog(Str As String)
|
|
Dim ArchivoW As StreamWriter
|
|
Dim strLineaTMP As String
|
|
|
|
' strLineaTMP = Chr(13) & Chr(10) & Day(Now) & "/" & Month(Now) & "/" & Year(Now) & " " & Hour(Now) & ":" & Minuto & ". " & Str & Chr(13) & Chr(10)
|
|
strLineaTMP = String.Format("{0}{1}Log: {2}{3}:{4}", Chr(13), Chr(10), Str, DateTime.Now.ToShortDateString, DateTime.Now.ToShortTimeString)
|
|
Try
|
|
ArchivoW = New StreamWriter(String.Format("{0}\log\LogPenske.txt", AppDomain.CurrentDomain.BaseDirectory), True, System.Text.Encoding.UTF8)
|
|
Catch ex As UnauthorizedAccessException
|
|
'Alert("No hay permisos para guardar en el Log.", Extensiones.TipoMensaje.MsgError)
|
|
Exit Sub
|
|
Catch ex As Exception
|
|
Exit Sub
|
|
End Try
|
|
|
|
Try
|
|
ArchivoW.WriteLine(strLineaTMP)
|
|
Catch
|
|
End Try
|
|
|
|
ArchivoW.Close()
|
|
ArchivoW.Dispose()
|
|
End Sub
|
|
|
|
|
|
End Class
|