158 lines
4.6 KiB
Plaintext
158 lines
4.6 KiB
Plaintext
<%@ WebHandler Language="C#" Class="SIGGPSRCService" %>
|
|
|
|
using System;
|
|
using System.Web;
|
|
using System.Web.SessionState;
|
|
using System.Data;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Extensiones;
|
|
using System.Collections.Specialized;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
|
|
public class SIGGPSRCService : IHttpHandler, IRequiresSessionState
|
|
{
|
|
public bool EsProduccion
|
|
{
|
|
get
|
|
{
|
|
if (System.Configuration.ConfigurationManager.AppSettings["EsProduccion"] == null)
|
|
return false;
|
|
else
|
|
return (System.Configuration.ConfigurationManager.AppSettings["EsProduccion"].ToString() == "1");
|
|
}
|
|
}
|
|
|
|
public bool IsReusable => false;
|
|
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
context.Response.ContentType = "text/plain";
|
|
bool retorno = false;
|
|
try
|
|
{
|
|
|
|
string Metodo = context.Request["Metodo"] == null ? "" : context.Request["Metodo"];
|
|
switch (Metodo)
|
|
{
|
|
case "EjecutaServicio":
|
|
ModExtensiones.GuardaLogAD("Servicio Ejecutado...........", "LogServicioConfiable");
|
|
retorno = IniciarTransmision();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if (retorno)
|
|
{
|
|
context.Response.Write("True");
|
|
}
|
|
else
|
|
{
|
|
context.Response.Write("False");
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.GuardaLog(ex.Message);
|
|
}
|
|
|
|
context.Response.End();
|
|
}
|
|
|
|
private bool IniciarTransmision()
|
|
{
|
|
var retorno = false;
|
|
var TieneError = false;
|
|
|
|
var WS = new RCGPSService.RCServiceClient();
|
|
|
|
RCGPSService.UserTokenResult Token = WS.GetUserToken(UserService, PasswordService);
|
|
List<RCGPSService.Event> ListaEventos = new List<RCGPSService.Event>();
|
|
|
|
DataTable DtTrackings = null;
|
|
var ObjGPS = new ClsGPS();
|
|
try
|
|
{
|
|
if (ObjGPS.GetRCTracking(-1, -1, 1, -1, -1))
|
|
{
|
|
DtTrackings = ObjGPS.DtResultados.Copy();
|
|
}
|
|
else
|
|
{
|
|
TieneError = true;
|
|
}
|
|
|
|
if (DtTrackings != null)
|
|
{
|
|
foreach (DataRow RowTrack in DtTrackings.Rows)
|
|
{
|
|
DataTable dtTracking = null;
|
|
if (ObjGPS.GetRCTrackingDatos(RowTrack["CveRCTracking"].ToString().ToEntero()))
|
|
{
|
|
dtTracking = ObjGPS.DtResultados.Copy();
|
|
}
|
|
else
|
|
{
|
|
TieneError = true;
|
|
}
|
|
if (dtTracking != null)
|
|
{
|
|
foreach (DataRow Row in dtTracking.Rows)
|
|
{
|
|
ListaEventos.Add(new RCGPSService.Event()
|
|
{
|
|
code = "STT",
|
|
date = Row["Fecha"].ToString().ToDateTime(),
|
|
latitude = Row["Latitud"].ToString(),
|
|
longitude = Row["Longitud"].ToString(),
|
|
asset = Row["PlacasVehiculo"].ToString(),
|
|
speed = Row["Velocidad"].ToString(),
|
|
shipment = Row["Shipment"].ToString()
|
|
});
|
|
}
|
|
}
|
|
dtTracking.Dispose();
|
|
dtTracking = null;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TieneError = true;
|
|
this.OnError("Ocurrió un error al enviar los datos", ex);
|
|
}
|
|
ObjGPS.Dispose();
|
|
|
|
DtTrackings.Dispose();
|
|
DtTrackings = null;
|
|
|
|
if (ListaEventos.Count > 0 && !TieneError)
|
|
{
|
|
var respuesta = WS.GPSAssetTracking(Token.token, ListaEventos.ToArray());
|
|
if (respuesta.Length > 0)
|
|
{
|
|
retorno = !TieneError;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
retorno = !TieneError;
|
|
}
|
|
|
|
WS.Close();
|
|
|
|
return retorno;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string UserService => EsProduccion ? "ws_avl_opsat" : "demo_cedis_corp";
|
|
private string PasswordService => EsProduccion ? "eiHv##889iWfz#&2" : "xxxxxxxx";
|
|
|
|
} |