protected void btnIngresar_Click(object sender, EventArgs e) { LectorXML objLectorXML = new LectorXML(); objLectorXML.RutaXML = Server.MapPath("~") + "\\Modulos\\XML\\Configuracion.xml"; CamposXML objCamposXML = new CamposXML(); objCamposXML.pTabla = "BD"; objCamposXML.pCampo = "G"; String usuario = objLectorXML.leerDatosXML(objCamposXML); objCamposXML.pCampo = "B"; String clave = objLectorXML.leerDatosXML(objCamposXML); if (usuario.Equals(txbUsuario.Text.Trim()) && clave.Equals(txbClave.Text.Trim())) { Response.Redirect("~/Modulos/Administracion/CadenaCX.aspx"); } else { UtilidadesWeb.ajustarMensaje(lbInforme, "Usuario o<br />contraseña no validos!", TipoMensaje.Error); mpeLogin.Show(); } }
static void Main(string[] args) { LectorXML lectorXML = new LectorXML(); List <NominaViewModel> lista = lectorXML.ObtenerInfo(); //InfoDAO infoDAO = new InfoDAO(); Console.WriteLine(lista.Count); Console.ReadLine(); lista.ForEach(x => { Info info = new Info() { rfc = x.RFC, uuid = x.UUID, fechafinalpago = x.FechaFinalPago, fechainicialpago = x.FechaInicialPago, fecha_timbrado = x.FechaTimbrado, fecha_pago = x.FechaPago, isr = Decimal.Parse(x.RetencionISR.ToString()), nombre = x.Nombre, path = x.path, reintegroISR = Decimal.Parse(x.ReintegroISR.ToString()) }; //if (infoDAO.existe(x.UUID)) //{ // Console.WriteLine("Ya esta registrado"); // return; //} //infoDAO.Agregar(info); Console.WriteLine("-----------------------------"); Console.WriteLine("Nombre {0}", x.Nombre); Console.WriteLine("RFC {0}", x.RFC); Console.WriteLine("UIID {0}", x.UUID); Console.WriteLine("FechaPago {0}", x.FechaPago); Console.WriteLine("FechaInicialPago {0}", x.FechaInicialPago); Console.WriteLine("FechaFinaPago {0}", x.FechaFinalPago); Console.WriteLine("FechaTimbrado {0}", x.FechaTimbrado); Console.WriteLine("Retension ISR {0}", x.RetencionISR); Console.WriteLine("Reintegro ISR {0}", x.ReintegroISR); Console.WriteLine("-----------------------------"); }); //string[] cancelados = lectorXML.obtenerCDFICancelados(); //Console.WriteLine(cancelados.Length); //cancelados.ToList().ForEach((c) => //{ // infoDAO.marcarComoCancelada(c); //}); Console.ReadLine(); }
private String leerXML(String Campo) { String respuesta = String.Empty; CamposXML objCampos = new CamposXML(); objCampos.pTabla = "BD"; objCampos.pCampo = Campo; LectorXML objLector = new LectorXML(); objLector.RutaXML = Server.MapPath("~") + "\\Modulos\\XML\\Configuracion.xml"; respuesta = objLector.leerDatosXML(objCampos); return(respuesta); }
private void escribirXML(String Campo, String Valor) { CamposXML objCampos = new CamposXML(); objCampos.pTabla = "BD"; objCampos.pCampo = Campo; objCampos.pValor = Valor; String valorOriginal = leerXML(Campo); if (!valorOriginal.Equals(Valor)) { LectorXML objLector = new LectorXML(); objLector.RutaXML = Server.MapPath("~") + "\\Modulos\\XML\\Configuracion.xml"; objLector.modificarXML(objCampos); } }
public string[] Proceso(string CertPath, string CertPass, string RequiereProxy, string ProxyServer, string ProxyUser, string ProxyPass, string DtePath, string DtePathProc, string maximoIntentos, string DtePathProcNOK, string VidaSemillaMil, string DteEstOK) { /* * string CertPath = Properties.Settings.Default["CertPath"].ToString(); * string CertPass = Properties.Settings.Default["CertPass"].ToString(); * string RequiereProxy = Properties.Settings.Default["RequiereProxy"].ToString(); * string ProxyServer = Properties.Settings.Default["ProxyServer"].ToString(); * string ProxyUser = Properties.Settings.Default["ProxyUser"].ToString(); * string ProxyPass = Properties.Settings.Default["ProxyPass"].ToString(); * string DtePath = Properties.Settings.Default["DtePath"].ToString(); * */ X509Certificate2 cert = new X509Certificate2(CertPath, CertPass); IWebProxy Proxya = System.Net.WebRequest.GetSystemWebProxy(); if (RequiereProxy == "S") { NetworkCredential nc = new NetworkCredential(ProxyUser, ProxyPass, ""); Proxya.Credentials = nc; } DirectoryInfo dir = new DirectoryInfo(DtePath); int numProcesados = 0; int numTotal = 0; Console.Clear(); //semilla XmlDocument xmlSemilla = new XmlDocument(); // Console.WriteLine("*****************************************************"); Console.WriteLine("CONSULTA DE ESTADO DE DTE"); Console.WriteLine("PROCESO INICIADO (" + DateTime.Now.ToString() + ")..."); Console.WriteLine("*****************************************************"); // //HORA SEMILLA DateTime horaSemilla = DateTime.Now; //Genera nuevos documentos foreach (FileInfo f in dir.GetFiles("*.xml")) { string name = f.Name; string fullName = f.FullName; XmlDocument xmlDTE = new XmlDocument(); xmlDTE.PreserveWhitespace = true; xmlDTE.Load(fullName); XmlNodeList elemDTE_Traspaso = xmlDTE.GetElementsByTagName("Documento"); //separa xml de paquetes de envio. for (int ctDte = 0; ctDte <= elemDTE_Traspaso.Count - 1; ctDte++) { XmlTextWriter aOuXML = new XmlTextWriter(Path.GetDirectoryName(fullName) + "\\" + Path.GetFileNameWithoutExtension(fullName) + "_" + ctDte + ".xml", System.Text.Encoding.GetEncoding("iso-8859-1")); XmlDocument xmlEnc_traspaso = new XmlDocument(); xmlEnc_traspaso.PreserveWhitespace = true; aOuXML.Formatting = Formatting.Indented; aOuXML.WriteStartDocument(); aOuXML.WriteRaw(elemDTE_Traspaso[ctDte].OuterXml); aOuXML.Flush(); aOuXML.Close(); } //mueve los dtes originales a esta carpeta string dias = System.DateTime.Now.ToString("yyyyMMdd"); string carpetaORI = Path.GetDirectoryName(fullName) + "\\Historico_Originales\\" + dias + "\\"; DirectoryInfo dir1 = new DirectoryInfo(carpetaORI); if (dir1.Exists == false) { dir1.Create(); } File.Move(fullName, carpetaORI + Path.GetFileNameWithoutExtension(fullName) + DateTime.Now.Ticks.ToString() + ".xml"); } foreach (FileInfo f in dir.GetFiles("*.xml")) { int problemas = 0; #region LEO DTE string name = f.Name; string fullName = f.FullName; XmlDocument xmlDTE = new XmlDocument(); xmlDTE.Load(fullName); XmlNodeList elemDTE = xmlDTE.GetElementsByTagName("Encabezado"); XmlDocument xmlEnc = new XmlDocument(); xmlEnc.InnerXml = elemDTE[0].OuterXml; xmlEnc.Save("Paso.xml"); LectorXML lector = new LectorXML(); Hashtable tbDTE = lector.lectorArchivo("Paso.xml"); //obtengo datos de consulta string[] arrayRutCons = tbDTE["RUTEmisor"].ToString().Split('-'); string RutConsultante = arrayRutCons[0]; string DvConsultante = arrayRutCons[1]; string[] arrayRutComp = tbDTE["RUTEmisor"].ToString().Split('-'); string RutCompania = arrayRutComp[0]; string DvCompania = arrayRutComp[1]; string[] arrayRutRece = tbDTE["RUTRecep"].ToString().Split('-'); string RutReceptor = arrayRutRece[0]; string DvReceptor = arrayRutRece[1]; string TipoDte = tbDTE["TipoDTE"].ToString(); string FolioDte = tbDTE["Folio"].ToString(); DateTime fecEmi = Convert.ToDateTime(tbDTE["FchEmis"]); string FechaEmisionDte = fecEmi.ToString("ddMMyyyy"); string MontoDte = tbDTE["MntTotal"].ToString(); #region SEMILLA //semilla string state = string.Empty; int intentos = 0; int resultMin = 0; int maxIntentos = int.Parse(maximoIntentos); while (intentos <= maxIntentos) { string estadoSemilla = string.Empty; try { TimeSpan ts = DateTime.Now.Subtract(horaSemilla); resultMin = ts.Milliseconds; if ((resultMin == int.Parse(VidaSemillaMil)) || (resultMin == 0) || (xmlSemilla.InnerText.Length == 0)) { cl.sii.semilla.CrSeedService mySemilla = new cl.sii.semilla.CrSeedService(); Console.WriteLine("Consultando SII-SEMILLA..." + DateTime.Now.ToString()); mySemilla.Timeout = 1000; if (RequiereProxy == "S") { mySemilla.Proxy = Proxya; } // state = mySemilla.getState(); //obtengo hora horaSemilla = DateTime.Now; resultMin = 0; // xmlSemilla.InnerXml = mySemilla.getSeed(); intentos++; Console.WriteLine("OK-SEMILLA..." + DateTime.Now.ToString()); break; } else { break; } } catch (Exception e2) { intentos++; } } if (xmlSemilla.InnerXml.Trim().Length > 0) { XmlNodeList elemList = xmlSemilla.GetElementsByTagName("SEMILLA"); string semilla = elemList[0].InnerText; XmlDocument reqTokenSinFirma = new XmlDocument(); reqTokenSinFirma.InnerXml = "<?xml version='1.0'?><getToken><item><Semilla>" + semilla + "</Semilla></item></getToken>"; XmlDocument reqTokenConFirma = new XmlDocument(); FirmaXML.Firmado firmador = new Firmado(); reqTokenConFirma.InnerXml = firmador.Genera(reqTokenSinFirma, "", cert); #endregion #region TOKEN //token XmlDocument xmlToken = new XmlDocument(); cl.sii.token.GetTokenFromSeedService myToken = new cl.sii.token.GetTokenFromSeedService(); Console.WriteLine("Consultando SII-TOKEN..."); if (RequiereProxy == "S") { myToken.Proxy = Proxya; } intentos = 0; while (intentos <= maxIntentos) { try { myToken.Timeout = 1000; xmlToken.InnerXml = myToken.getToken(reqTokenConFirma.InnerXml); XmlNodeList elemList2 = xmlToken.GetElementsByTagName("ESTADO"); string estadoToken = elemList2[0].InnerText; if (estadoToken != "00") { xmlToken.InnerText = ""; if (intentos <= maxIntentos) { state = string.Empty; } } else { Console.WriteLine("OK-TOKEN..." + DateTime.Now.ToString()); break; } intentos++; } catch (Exception e1) { intentos++; } } if (xmlToken.InnerXml.Trim().Length > 0) { XmlNodeList elemList3 = xmlToken.GetElementsByTagName("TOKEN"); string token = elemList3[0].InnerText; #endregion #region RESPUESTA //respuesta. XmlDocument respuestaSII = new XmlDocument(); intentos = 0; while (intentos <= maxIntentos) { try { Console.WriteLine("Consultando SII-ESTADO..."); cl.sii.queryEstDte.QueryEstDteService myqueryEstDte = new cl.sii.queryEstDte.QueryEstDteService(); myqueryEstDte.Timeout = 2000; if (RequiereProxy == "S") { myqueryEstDte.Proxy = Proxya; } respuestaSII.InnerXml = myqueryEstDte.getEstDte(RutConsultante, DvConsultante, RutCompania, DvCompania, RutReceptor, DvReceptor, TipoDte, FolioDte, FechaEmisionDte, MontoDte, token); Console.WriteLine("OK-ESTADO..." + DateTime.Now.ToString()); break; } catch { intentos++; } } if (respuestaSII.InnerXml.Trim().Length > 0) { XmlNodeList elemList2; string estadorespuestaSII = ""; try { elemList2 = respuestaSII.GetElementsByTagName("GLOSA_ESTADO"); estadorespuestaSII = elemList2[0].InnerText; } catch { elemList2 = respuestaSII.GetElementsByTagName("ESTADO"); estadorespuestaSII = elemList2[0].InnerText; } //valido si es una respuesta numerica. algo paso. Asi que lo dejo pendiente. bool retornoNumero = false; try { double.Parse(estadorespuestaSII); retornoNumero = true; } catch { retornoNumero = false; } if (!retornoNumero) { if (DteEstOK.Contains(estadorespuestaSII)) //estadorespuestaSII == "DOK" || estadorespuestaSII == "DNK") { //muevo archivos a procesados //string carpetaDias = DateTime.Now.ToString("yyyyMMdd"); string dirProcesado = DtePathProc; DirectoryInfo dir2 = new DirectoryInfo(dirProcesado); if (!dir2.Exists) { dir2.Create(); } if (!File.Exists(dirProcesado + @"\" + f.Name)) { f.MoveTo(dirProcesado + @"\" + f.Name); } else { f.MoveTo(dirProcesado + @"\" + "COPIA_" + DateTime.Now.Ticks.ToString() + "_" + f.Name); //f.MoveTo(dirProcesado + "COPIA_" + Path.GetFileNameWithoutExtension(fullName) + "_" + ctDte + DateTime.Now.Ticks.ToString() + ".xml"); } } else { //muevo archivos a procesados string carpetaDias = DateTime.Now.ToString("yyyyMMdd"); string dirProcesado = DtePathProcNOK + @"\" + carpetaDias; DirectoryInfo dir2 = new DirectoryInfo(dirProcesado); if (!dir2.Exists) { dir2.Create(); } f.MoveTo(dirProcesado + @"\" + f.Name); //guardo respuesta cuando es rechazado string newResp = f.Name.Substring(0, f.Name.Length - 4) + "_RES_" + DateTime.Now.Ticks + f.Extension; respuestaSII.Save(dirProcesado + @"\" + newResp); } numProcesados++; } else { problemas++; Console.WriteLine("RETORNO NO VALIDO, ESTADO NUMERO (RESPUESTA), ARCHIVO: " + name); } } else { problemas++; Console.WriteLine("CONEXION A SII NO FUE POSIBLE (RESPUESTA), ARCHIVO: " + name); } } else { problemas++; Console.WriteLine("CONEXION A SII NO FUE POSIBLE (TOKEN), ARCHIVO: " + name); } } else { problemas++; Console.WriteLine("CONEXION A SII NO FUE POSIBLE (SEMILLA), ARCHIVO: " + name); } #endregion numTotal++; #endregion } string[] myRetorno = new string[2]; myRetorno[0] = numTotal.ToString(); myRetorno[1] = numProcesados.ToString(); Console.WriteLine("*****************************************************"); Console.WriteLine("PROCESO FINALIZADO (" + DateTime.Now.ToString() + ")."); Console.WriteLine("*****************************************************"); return(myRetorno); }
public string[] Proceso(string CertPath, string CertPass, string RequiereProxy, string ProxyServer, string ProxyUser, string ProxyPass, string DtePath, string DtePathProc, string maximoIntentos, string DtePathProcNOK, string VidaSemillaMil, string[] DteEstOK, string OMITE_VAL_SII, string Valida_en_Sii, string Omitir_Guia, string Reintentos_Valida_Sii) { X509Certificate2 cert = new X509Certificate2(CertPath, CertPass); IWebProxy Proxya = System.Net.WebRequest.GetSystemWebProxy(); if (RequiereProxy == "S") { NetworkCredential nc = new NetworkCredential(ProxyUser, ProxyPass, ""); Proxya.Credentials = nc; } DirectoryInfo dir = new DirectoryInfo(DtePath); int numProcesados = 0; int numTotal = 0; Console.Clear(); //semilla XmlDocument xmlSemilla = new XmlDocument(); // Console.WriteLine("*****************************************************"); Console.WriteLine("*****************************************************"); Console.WriteLine("******* *******"); Console.WriteLine("***** Actualizado 01-08-2019 (SII) *****"); Console.WriteLine("******* *******"); Console.WriteLine("*****************************************************"); Console.WriteLine("*****************************************************"); Console.WriteLine("CONSULTA DE ESTADO DE DTE"); Console.WriteLine("PROCESO INICIADO (" + DateTime.Now.ToString() + ")..."); int cant_a_procesar = dir.GetFiles("*.xml").Length; Console.WriteLine("XML DISPONIBLES A PROCESAR: " + cant_a_procesar.ToString()); Console.WriteLine("*****************************************************"); /******************************** HISTORIAL DE ACTUALIZACIONES ************************************** * 01-08-2019 Se realiza actualizacion para omitir la verificacion de la guia de despacho en el SII * * ****************************** FIN HISTORIAL DE ACTUALIZACIONES ************************************/ // //HORA SEMILLA DateTime horaSemilla = DateTime.Now; //Crea nuevo directorio si no existe 27-11-2018 (mgarrido) if (!Directory.Exists(Valida_en_Sii)) { try{ Directory.CreateDirectory(Valida_en_Sii); } catch { } } //Genera nuevos documentos foreach (FileInfo f in dir.GetFiles("*.xml")) { string name = f.Name; string fullName = f.FullName; XmlDocument xmlDTE = new XmlDocument(); xmlDTE.PreserveWhitespace = true; xmlDTE.Load(fullName); XmlNodeList elemDTE_Traspaso = xmlDTE.GetElementsByTagName("Documento"); //separa xml de paquetes de envio. for (int ctDte = 0; ctDte <= elemDTE_Traspaso.Count - 1; ctDte++) { try { string newNombre = Path.GetFileNameWithoutExtension(fullName); try { if (newNombre.Length > 75) { newNombre = newNombre.Substring(0, 74); } } catch { } if (!newNombre.Contains("_JDN2018_")) { string azar = "_JDN2018_" + ramdonString(8) + "_" + DateTime.Now.ToString("yyyyMMddThhmmss"); newNombre += azar; } newNombre += ".xml"; // Se gurdan en un nuevo directorio desde el 27-11-2018 (mgarrido) XmlTextWriter aOuXML = new XmlTextWriter(Valida_en_Sii + "\\" + newNombre, System.Text.Encoding.GetEncoding("iso-8859-1")); XmlDocument xmlEnc_traspaso = new XmlDocument(); xmlEnc_traspaso.PreserveWhitespace = true; aOuXML.Formatting = Formatting.Indented; aOuXML.WriteStartDocument(); aOuXML.WriteRaw(elemDTE_Traspaso[ctDte].OuterXml); aOuXML.Flush(); aOuXML.Close(); System.Threading.Thread.Sleep(1000); } catch { } } try { //mueve los dtes originales a esta carpeta string dias = System.DateTime.Now.ToString("yyyyMMdd"); string carpetaORI = Path.GetDirectoryName(fullName) + "\\Historico_Originales\\" + dias + "\\"; DirectoryInfo dir1 = new DirectoryInfo(carpetaORI); if (dir1.Exists == false) { dir1.Create(); } File.Move(fullName, carpetaORI + Path.GetFileNameWithoutExtension(fullName) + DateTime.Now.Ticks.ToString() + ".xml"); } catch { } } // Se lee desde el nuevo directorio desde el 27-11-2018 (mgarrido) DirectoryInfo NewDirectory = new DirectoryInfo(Valida_en_Sii); foreach (FileInfo f in NewDirectory.GetFiles("*.xml")) { int problemas = 0; #region LEO DTE string name = f.Name; string fullName = f.FullName; XmlDocument xmlDTE = new XmlDocument(); xmlDTE.Load(fullName); XmlNodeList elemDTE = xmlDTE.GetElementsByTagName("Encabezado"); //XmlDocument xmlEnc = new XmlDocument(); //xmlEnc.InnerXml = elemDTE[0].OuterXml; //System.Threading.Thread.Sleep(2000); //xmlEnc.Save("Paso.xml"); // LectorXML lector = new LectorXML(); // Hashtable tbDTE = lector.lectorArchivo("Paso.xml"); XmlDocument xmlEnc = new XmlDocument(); xmlEnc.InnerXml = elemDTE[0].OuterXml; //System.Threading.Thread.Sleep(1500); //xmlEnc.Save("Paso.xml"); MemoryStream xmlStream = new MemoryStream(); xmlEnc.Save(xmlStream); xmlStream.Flush();//Adjust this if you want read your data xmlStream.Position = 0; LectorXML lector = new LectorXML(); //Hashtable tbDTE = lector.lectorArchivo("Paso.xml"); Hashtable tbDTE = new Hashtable(); try { tbDTE = lector.lectorArchivo2(xmlStream); } catch { System.Threading.Thread.Sleep(1500); xmlEnc.Save("Paso.xml"); tbDTE = lector.lectorArchivo("Paso.xml"); } //obtengo datos de consulta string[] arrayRutCons = tbDTE["RUTEmisor"].ToString().Split('-'); string RutConsultante = arrayRutCons[0]; string DvConsultante = arrayRutCons[1]; string[] arrayRutComp = tbDTE["RUTEmisor"].ToString().Split('-'); string RutCompania = arrayRutComp[0]; string DvCompania = arrayRutComp[1]; string[] arrayRutRece = tbDTE["RUTRecep"].ToString().Split('-'); string RutReceptor = arrayRutRece[0]; string DvReceptor = arrayRutRece[1]; string TipoDte = tbDTE["TipoDTE"].ToString(); string FolioDte = tbDTE["Folio"].ToString(); DateTime fecEmi = Convert.ToDateTime(tbDTE["FchEmis"]); string FechaEmisionDte = fecEmi.ToString("ddMMyyyy"); string MontoDte = tbDTE["MntTotal"].ToString(); #region SEMILLA string Si_Omite_Guia = "N"; if (Omitir_Guia == "S" && TipoDte == "52") { Si_Omite_Guia = Omitir_Guia; } //semilla string state = string.Empty; int intentos = 0; int resultMin = 0; int maxIntentos = int.Parse(maximoIntentos); while (intentos <= maxIntentos) { Console.WriteLine("Procesando XML : " + (numTotal + 1).ToString()); string estadoSemilla = string.Empty; try { TimeSpan ts = DateTime.Now.Subtract(horaSemilla); resultMin = ts.Milliseconds; if ((resultMin == int.Parse(VidaSemillaMil)) || (resultMin == 0) || (xmlSemilla.InnerText.Length == 0)) { cl.sii.semilla.CrSeedService mySemilla = new cl.sii.semilla.CrSeedService(); Console.WriteLine("Consultando SII-SEMILLA..." + DateTime.Now.ToString()); mySemilla.Timeout = 800; if (RequiereProxy == "S") { mySemilla.Proxy = Proxya; } // state = mySemilla.getState(); //obtengo hora horaSemilla = DateTime.Now; resultMin = 0; // xmlSemilla.InnerXml = mySemilla.getSeed(); intentos++; Console.WriteLine("OK-SEMILLA..." + DateTime.Now.ToString()); break; } else { break; } } catch (Exception e2) { intentos++; } } if (xmlSemilla.InnerXml.Trim().Length > 0) { XmlNodeList elemList = xmlSemilla.GetElementsByTagName("SEMILLA"); string semilla = elemList[0].InnerText; XmlDocument reqTokenSinFirma = new XmlDocument(); reqTokenSinFirma.InnerXml = "<?xml version='1.0'?><getToken><item><Semilla>" + semilla + "</Semilla></item></getToken>"; XmlDocument reqTokenConFirma = new XmlDocument(); FirmaXML.Firmado firmador = new Firmado(); reqTokenConFirma.InnerXml = firmador.Genera(reqTokenSinFirma, "", cert); #endregion #region TOKEN //token XmlDocument xmlToken = new XmlDocument(); cl.sii.token.GetTokenFromSeedService myToken = new cl.sii.token.GetTokenFromSeedService(); Console.WriteLine("Consultando SII-TOKEN..."); if (RequiereProxy == "S") { myToken.Proxy = Proxya; } intentos = 0; if (Si_Omite_Guia == "N") { while (intentos <= maxIntentos) { try { myToken.Timeout = 1000; xmlToken.InnerXml = myToken.getToken(reqTokenConFirma.InnerXml); XmlNodeList elemList2 = xmlToken.GetElementsByTagName("ESTADO"); string estadoToken = elemList2[0].InnerText; if (estadoToken != "00") { xmlToken.InnerText = ""; if (intentos <= maxIntentos) { state = string.Empty; } } else { Console.WriteLine("OK-TOKEN..." + DateTime.Now.ToString()); break; } intentos++; } catch (Exception e1) { intentos++; } } } else { xmlToken.InnerXml = "<TOKEN>TOKEN OMITIDO</TOKEN>"; Console.WriteLine("VALIDACIÓN SII DTE OMITIDO (GUIA)"); } if (xmlToken.InnerXml.Trim().Length > 0) { string token = string.Empty; try { Console.WriteLine(xmlToken.InnerXml); XmlNodeList elemList3 = xmlToken.GetElementsByTagName("TOKEN"); token = elemList3[0].InnerText; } catch (Exception ex) { Console.WriteLine(ex.Message); } #endregion #region RESPUESTA //respuesta. XmlDocument respuestaSII = new XmlDocument(); intentos = 0; if (Si_Omite_Guia == "N") { while (intentos <= maxIntentos) { try { Console.WriteLine("Consultando SII-ESTADO..."); cl.sii.queryEstDte.QueryEstDteService myqueryEstDte = new cl.sii.queryEstDte.QueryEstDteService(); myqueryEstDte.Timeout = 2000; if (RequiereProxy == "S") { myqueryEstDte.Proxy = Proxya; } respuestaSII.InnerXml = myqueryEstDte.getEstDte(RutConsultante, DvConsultante, RutCompania, DvCompania, RutReceptor, DvReceptor, TipoDte, FolioDte, FechaEmisionDte, MontoDte, token); Console.WriteLine("OK-ESTADO..." + DateTime.Now.ToString()); System.Threading.Thread.Sleep(1000); break; } catch { intentos++; } } } else { respuestaSII.InnerXml = "<TOKEN>RESPUESTA OMITIDO</TOKEN>"; Console.WriteLine("VALIDACIÓN SII DTE OMITIDO (GUIA)"); } if (respuestaSII.InnerXml.Trim().Length > 0) { XmlNodeList elemList2; string estadorespuestaSII = ""; if (Si_Omite_Guia == "N") { try { //elemList2 = respuestaSII.GetElementsByTagName("GLOSA_ESTADO"); elemList2 = respuestaSII.GetElementsByTagName("ESTADO"); estadorespuestaSII = elemList2[0].InnerText; } catch { //elemList2 = respuestaSII.GetElementsByTagName("ESTADO"); estadorespuestaSII = "0"; } } if (OMITE_VAL_SII == "S") { estadorespuestaSII = "DOK"; } if (Si_Omite_Guia == "S") { estadorespuestaSII = "DOK"; } //valido si es una respuesta numerica. algo paso. Asi que lo dejo pendiente. bool retornoNumero = false; try { double.Parse(estadorespuestaSII); retornoNumero = true; } catch { retornoNumero = false; } if (!retornoNumero) { int index = Array.IndexOf(DteEstOK, estadorespuestaSII); if (index > -1) //estadorespuestaSII == "DOK" || estadorespuestaSII == "DNK") { //muevo archivos a pendientes //string carpetaDias = DateTime.Now.ToString("yyyyMMdd"); string dirProcesado = DtePathProc; DirectoryInfo dir2 = new DirectoryInfo(dirProcesado); if (!dir2.Exists) { dir2.Create(); } if (!File.Exists(dirProcesado + @"\" + f.Name)) { f.MoveTo(dirProcesado + @"\" + f.Name); } else { f.MoveTo(dirProcesado + @"\" + "COPIA_" + DateTime.Now.Ticks.ToString("yyyMMddThhmmss") + "_" + f.Name); //f.MoveTo(dirProcesado + "COPIA_" + Path.GetFileNameWithoutExtension(fullName) + "_" + ctDte + DateTime.Now.Ticks.ToString() + ".xml"); } } else { /*//muevo archivos a rechazados * string carpetaDias = DateTime.Now.ToString("yyyyMMdd"); * string dirProcesado = DtePathProcNOK + @"\" + carpetaDias; * DirectoryInfo dir2 = new DirectoryInfo(dirProcesado); * if (!dir2.Exists) { dir2.Create(); } * f.MoveTo(dirProcesado + @"\" + f.Name); * //guardo respuesta cuando es rechazado * string newResp = f.Name.Substring(0, f.Name.Length - 4) + "_RES_" + DateTime.Now.Ticks + f.Extension; * respuestaSII.Save(dirProcesado + @"\" + newResp);*/ string carpetaDias = DateTime.Now.ToString("yyyyMMdd"); string dirProcesado = DtePathProcNOK + @"\" + carpetaDias; DirectoryInfo dir2 = new DirectoryInfo(dirProcesado); if (!dir2.Exists) { dir2.Create(); } string newResp = f.Name.Substring(0, f.Name.Length - 4) + "_RES_" + DateTime.Now.Ticks + f.Extension; var fechaRecepcion = f.LastWriteTime; DateTime Hoy = DateTime.Now; TimeSpan ts = Hoy - fechaRecepcion; int differenceInDays = ts.Days; if (estadorespuestaSII.Contains("FAU") && differenceInDays <= int.Parse(Reintentos_Valida_Sii)) { Console.WriteLine("DOCUMENTO NO EXISTENTE EN SII, HAN PASADO " + differenceInDays + " DIAS"); } else { Console.WriteLine("DOCUMENTO SE MUEVE A CARPETA DE RECHAZADOS"); //muevo archivos a rechazados f.MoveTo(dirProcesado + @"\" + f.Name); } //guardo respuesta cuando es rechazado respuestaSII.Save(dirProcesado + @"\" + newResp); } numProcesados++; } else { problemas++; Console.WriteLine("RETORNO NO VALIDO, ESTADO NUMERO (RESPUESTA), ARCHIVO: " + name); } } else { problemas++; Console.WriteLine("CONEXION A SII NO FUE POSIBLE (RESPUESTA), ARCHIVO: " + name); } } else { problemas++; Console.WriteLine("CONEXION A SII NO FUE POSIBLE (TOKEN), ARCHIVO: " + name); } } else { problemas++; Console.WriteLine("CONEXION A SII NO FUE POSIBLE (SEMILLA), ARCHIVO: " + name); } #endregion numTotal++; #endregion } string[] myRetorno = new string[2]; myRetorno[0] = numTotal.ToString(); myRetorno[1] = numProcesados.ToString(); Console.WriteLine("*****************************************************"); Console.WriteLine("PROCESO FINALIZADO (" + DateTime.Now.ToString() + ")."); Console.WriteLine("TOTAL: " + numTotal.ToString()); Console.WriteLine("PROCESADOS: " + numProcesados.ToString()); Console.WriteLine("*****************************************************"); return(myRetorno); }