Tengo un peculiar problema, tengo una app Windows Forms que desde que implemente el envio de pdf y xml a diferentes correos electrónicos a dejado de funcionar.
Pero desde el editor de código VS 2015 funciona con total normalidad sin problemas, hace un trabajo excelente.
El problema es cuando creo el instalor e instalo en las maquinas clientes no hace su trabajo se queda colgado en el progress bar esperando que termine su proceso.
Para tratar de descartar posibilidades comente el código del progress var y nunca termina el proceso de enviar a los correos los documentos adjuntados.
¿Como puedo depurar la app que esta instalada en las maquinas clientes?
Creo necesito una herramienta que me permita depurar la app instalada en la maquina cliente.
Me parece que el problema es que activo el progress bar en un evento pero lo desactivo en un método que llama, muestro el código.
Evento Click
private void dgvXml_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dgvXml.Columns[e.ColumnIndex].Name == "colBoton")
{
if (dgvXml.Rows.Count > 0 && dgvXml.CurrentRow != null)
_rutaXml = Convert.ToString(dgvXml.CurrentRow.Cells[0].Value);
string msg = string.Format("Se va a procesar el siguiente Comprobante Electrónico: {0} {1} {0} Nombre: {2}",
Environment.NewLine,
new string('-', 50),
dgvXml.CurrentRow.Cells[2].Value);
if (MessageBox.Show(msg, @"Aviso", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
var verificarConexion = Utilidades.CheckForInternetConnection();
if (!verificarConexion)
{
MessageBox.Show(@"No tiene conexión a Internet", @"Aviso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
//PROCESAR
if (_exist && _validarFechaVencimiento)
{
//ACTIVO CIRCULAR PROGRESS BAR
circularProgress1.Visible = true;
circularProgress1.IsRunning = true;
if (AmbienteType.Prueba == _ambiente)
{
try
{
if (string.IsNullOrEmpty(_rutaXml))
{
MessageBox.Show(@"Debe escoger una Factura de xml", @"Mensaje", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
if (!string.IsNullOrEmpty(_claveFirma)
&& !string.IsNullOrEmpty(_rutaXml))
{
var token = _hub.Subscribe<SelectedMensajeWsPrueba>(OnWsPruebaSelected);
_sdWebServicePrueba.ValidarComprobanteAsync(_byteFirma, _claveFirma, _rutaXml);
//_hub.Unsubscribe(token);
MessageBox.Show("Regresa o no");
}
}
catch (Exception ex)
{
MessageBox.Show($"{ex.Message}", @"Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
if (AmbienteType.Produccion == _ambiente)
{
try
{
if (string.IsNullOrEmpty(_rutaXml))
{
MessageBox.Show(@"Debe escoger una Factura de xml", @"Mensaje", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
if (!string.IsNullOrEmpty(_claveFirma)
&& !string.IsNullOrEmpty(_rutaXml))
{
var token = _hub.Subscribe<SelectedMensajeWsProduccion>(OnWsProduccionSelected);
_sdWebServiceProduccion.ValidarComprobanteAsync(_byteFirma, _claveFirma, _rutaXml);
//_hub.Unsubscribe(token);
MessageBox.Show("Regresa o no");
}
}
catch (Exception ex)
{
MessageBox.Show($"{ex.Message}", @"Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
}
Entrando en el evento que creo.
private void OnWsPruebaSelected(SelectedMensajeWsPrueba obj)
{
string path = string.Empty;
string nombreDocumento = string.Empty;
if (!string.IsNullOrEmpty(obj.EstadoRecepcionPrueba))
{
if (obj.EstadoRecepcionPrueba == "DEVUELTA")
{
MessageBox.Show($"Identificador: {obj.Identificador} Mensaje: {obj.Mensaje1} Tipo: {obj.Tipo}",
@"Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
if (!string.IsNullOrEmpty(obj.EstadoAutorizacionPrueba))
{
if (obj.EstadoAutorizacionPrueba == "AUTORIZADO")
{
XElement doc = XElement.Parse(obj.Comprobante);
var resultCodDoc = doc.Elements("infoTributaria")
.Elements("codDoc").ToArray();
if (string.IsNullOrEmpty(resultCodDoc[0].Value))
return;
var entity = _sdTipoComprobante.BuscarXCodigo(resultCodDoc[0].Value);
if (entity != null)
{
nombreDocumento = entity.Nombre;
var resultEstab = doc.Elements("infoTributaria")
.Elements("estab").ToArray();
var resultPtoEmi = doc.Elements("infoTributaria")
.Elements("ptoEmi").ToArray();
var resultSecuencial = doc.Elements("infoTributaria")
.Elements("secuencial").ToArray();
string numero = resultEstab[0].Value + "-" + resultPtoEmi[0].Value + "-" + resultSecuencial[0].Value;
switch (entity.Codigo)
{
case "01"://Factura
var resultComprador = doc.Elements("infoFactura")
.Elements("razonSocialComprador").ToArray();
var resultImporteTotal = doc.Elements("infoFactura")
.Elements("importeTotal").ToArray();
var nombreFactura = entity.Nombre + "_" + numero + "_" + resultComprador[0].Value + "_" + resultImporteTotal[0].Value;
var nombreFacturaXml = string.Concat(nombreFactura, ".xml");
path = Path.Combine(_rutaXmlAutorizado, nombreFacturaXml);
break;
case "04"://Nota de Credito
var resultCompradorNotaCredito = doc.Elements("infoNotaCredito")
.Elements("razonSocialComprador").ToArray();
var nombreNotaCredito = entity.Nombre + "_" + numero + "_" +
resultCompradorNotaCredito[0].Value;
var nombreNotaCreditoXml = string.Concat(nombreNotaCredito, ".xml");
path = Path.Combine(_rutaXmlAutorizado, nombreNotaCreditoXml);
break;
case "05"://Nota sw Debito
var resultCompradorNotaDebito = doc.Elements("infoNotaDebito")
.Elements("razonSocialComprador").ToArray();
var nombreNotaDebito = entity.Nombre + "_" + numero + "_" + resultCompradorNotaDebito[0].Value;
var nombreNotaDebitoXml = string.Concat(nombreNotaDebito, ".xml");
path = Path.Combine(_rutaXmlAutorizado, nombreNotaDebitoXml);
break;
case "06"://Guía de Remisión
var resultCompradorGuiaRemision = doc.Elements("destinatarios")
.Elements("destinatario")
.Elements("identificacionDestinatario").ToArray();
var nombreGuiaRemision = entity.Nombre + "_" + numero + "_" +
resultCompradorGuiaRemision[0].Value;
var nombreGuiaRemisionXml = string.Concat(nombreGuiaRemision, ".xml");
path = Path.Combine(_rutaXmlAutorizado, nombreGuiaRemisionXml);
break;
case "07"://Retención
var resultSujetoRetenido = doc.Elements("infoCompRetencion")
.Elements("razonSocialSujetoRetenido").ToArray();
var nombreRetencion = entity.Nombre + "_" + numero + "_" + resultSujetoRetenido[0].Value;
var nombreRetencionXml = string.Concat(nombreRetencion, ".xml");
path = Path.Combine(_rutaXmlAutorizado, nombreRetencionXml);
break;
}
//Escribe en disco
CrearXml(_rutaXmlAutorizado, obj.EstadoAutorizacionPrueba, obj.NumeroAutorizacion,
obj.FechaAutorizacion, obj.Ambiente, obj.Comprobante, obj.Mensajes, path);
MessageBox.Show(
$"Documento: {nombreDocumento} Estado: {obj.EstadoAutorizacionPrueba} Fecha: {obj.FechaAutorizacion} Ambiente: {obj.Ambiente}",
@"Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
//Eliminar el Xml que se aprobo
//Obtenre el nombre del Xml _rutaXml
var fileNameAprobado = Path.GetFileName(_rutaXml);
//Eliminar en lista de archivo Xml
if (_lista.Count > 0)
{
_lista.RemoveAll(x => x.Nombre == fileNameAprobado);
File.Delete(_rutaXml);
dgvXml.DataSource = null;
dgvXml.AutoGenerateColumns = false;
dgvXml.DataSource = _lista;
Utilidades.AutoGenerateRowNumber(dgvXml);
Utilidades.FormatoDgv(dgvXml);
ChangeWidthColumnXml();
}
}
else
{
MessageBox.Show(@"No se encontró Tipo de Comprobante.", @"Aviso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
//DESACTIVO CIRCULAR PRGRESS BAR
circularProgress1.IsRunning = false;
circularProgress1.Visible = false;
_hub.ClearSubscriptions();
}
Cuando estoy en el evento cllck de la grilla y creo el evento:
//Creo el evento
var token = _hub.Subscribe<SelectedMensajeWsPrueba>(OnWsPruebaSelected);
Va al web service a validarme el xml si tiene la estructura adecuada
_sdWebServicePrueba.ValidarComprobanteAsync(_byteFirma, _claveFirma, _rutaXml);
//Supuestamente regresando de _sdWebServicePrueba.ValidarComprobanteAsync debería ir al evento OnWsPruebaSelected
//Y regresndo de ahí elimiar el token cerrar el evento destruirlo, pero no sucede eso
//Si no que regresando de _sdWebServicePrueba.ValidarComprobanteAsync pasa a _hub.Unsubscribe(token); y lo cierra y ya no va al evento OnWsPruebaSelected es por eso que lo tengo comentado y destruyo al final del evento OnWsPruebaSelected.
//_hub.Unsubscribe(token);
MessageBox.Show("Regresa o no");
Cuando activo el progress bar en el evento click debo de cerrarlo en ese mismo evento es lo que se debería hacer si es que no estoy equivocado, ¿Hay alguna manera de trabajar asincronamente al método OnWsPruebaSelected
ya que en ese evento es donde creo los documentos pdf y xml para enviarlo a los correos, mejor dicho en ese evento se manda todo el proceso de crear los archivos pdf y xml que se van a enviar al correo claro que en ese evento se hacen varias consultas a la base de datos para poner datos en los documentos?
Encontrando el problema en producción
2019-03-18 19:01:28.0172 TecSoftware.EnviarFactura.Program error message
2019-03-18 19:01:28.0511 TecSoftware.EnviarFactura.Program fatal error message
2019-03-19 11:22:09.0250 TecSoftware.EnviarFactura.Program error message
2019-03-19 11:22:09.0411 TecSoftware.EnviarFactura.Program fatal error message
2019-03-19 11:24:04.1807 TecSoftware.EnviarFactura.DocumentosElectronicos Un errorSystem.Exception: IronBarCode must be licensed for barcode creation outside of the Visual Studio development environment. https://ironsoftware.com/csharp/barcode/license/
en IronBarCode.GeneratedBarcode..ctor(? )
en IronBarCode.BarcodeWriter.(String , Byte[] , BarcodeWriterEncoding , Int32 , Int32 )
en IronBarCode.BarcodeWriter.CreateBarcode(String Value, BarcodeWriterEncoding BarcodeType)
en TecSoftware.EnviarFactura.Utilidades.GenerarBarcode(String code) en D:\EnviarFactura\EnviarFactura\Clases\Utilidades.cs:línea 289
en TecSoftware.EnviarFactura.DocumentosElectronicos.CrearPdfEnvioCorreo(String documento, String rutaAutorizado, String rutaXml, String numeroAutorizacion, DateTime fechaAutorizacion, String email, String claveEmail, Boolean flag) en D:\EnviarFactura\EnviarFactura\Clases\DocumentosElectronicos.cs:línea 60
2019-03-19 11:24:06.0168 TecSoftware.EnviarFactura.DocumentosElectronicos Algo malo sucedioSystem.ArgumentException: Caracteres no válidos en la ruta de acceso.
en System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
en System.IO.Path.Combine(String path1, String path2)
en iTextSharp.text.html.simpleparser.ElementFactory.CreateImage(String src, IDictionary`2 attrs, ChainedProperties chain, IDocListener document, IImageProvider img_provider, Dictionary`2 img_store, String img_baseurl)
en iTextSharp.text.html.simpleparser.HTMLWorker.CreateImage(IDictionary`2 attrs)
en iTextSharp.text.html.simpleparser.HTMLTagProcessors.HTMLTagProcessor_IMG.StartElement(HTMLWorker worker, String tag, IDictionary`2 attrs)
en iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag, IDictionary`2 attrs)
en iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader)
en iTextSharp.text.html.simpleparser.HTMLWorker.Parse(TextReader reader)
en TecSoftware.EnviarFactura.DocumentosElectronicos.CrearPdfEnvioCorreo(String documento, String rutaAutorizado, String rutaXml, String numeroAutorizacion, DateTime fechaAutorizacion, String email, String claveEmail, Boolean flag) en D:\EnviarFactura\EnviarFactura\Clases\DocumentosElectronicos.cs:línea 183
Saludos!