public void procesoContingencia()
        {
            while (!_shouldStop)
            {
                //Thread.Sleep(60000); // Duerme 10 minutos
                Thread.Sleep(6000); // un minuto
                //Thread.Sleep(120000); // 20 minutos
                Console.WriteLine("ProcessContingencia thread: working...");

                Connect conn = new Connect();
                Log     log  = new Log();
                String  ping = conn.ping();

                String envunit     = String.Empty;
                String pdft        = String.Empty;
                String pdfc        = String.Empty;
                String jsonName    = String.Empty;
                String filecliente = String.Empty;
                String filefactura = String.Empty;

                if (ping == "{\"status\":\"Ok\"}")
                {
                    ReenvioSql reenv = new ReenvioSql();
                    // saco el nombres de los archivos  json, enviomasivo.xml pdfT y pdfC

                    List <String> listaReenvio = new List <string>();

                    listaReenvio = reenv.sgteReenvio();
                    // cargo clase Documento
                    Documento doc  = new Documento();
                    TxtReader json = new TxtReader();

                    int i = 0;
                    foreach (var reenvio in listaReenvio)
                    {
                        i++;
                        switch (i)
                        {
                        case 1:
                        {
                            doc      = json.lectura(reenvio, false, @"" + Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Iat", "unidadIat", null).ToString() + ":/IatFiles/fileprocess/");
                            jsonName = reenvio;
                        }
                        break;

                        case 2: envunit = reenvio;
                            break;

                        case 3: pdft = reenvio;
                            break;

                        case 4: pdfc = reenvio;
                            break;

                        case 5: filecliente = reenvio;
                            break;

                        case 6: filefactura = reenvio;
                            break;
                        }
                    }
                    // llamo clase connect para reenviar
                    if (listaReenvio.Count() > 0)
                    {
                        conn.sendInvoice(doc, pdft, pdfc, envunit, filecliente, filefactura, "S");

                        // Cambio estado del registro de reenvio
                        reenv.cambioEstadoReenvio("PROCESADO", jsonName);
                    }
                }
                else
                {
                    log.addLog("ERROR Proceso Contingencia Ping no responde Json:" + jsonName, "ERROR");
                }
            }
        }
Пример #2
0
        private void button18_Click(object sender, EventArgs e)
        {
            ReenvioSql reenv = new ReenvioSql();

            reenv.verReenv();
        }
Пример #3
0
        public string sendInvoice(Documento doc, String pdfTfileName, String pdfCfileName, String filename, String fileCliente, String fileFactura, String conEnv)
        {
            try
            {
                string HtmlResult = String.Empty;
                string postUri    = string.Format("{0}{1}/invoice.json",
                                                  //server,
                                                  cdb.GetUrl().ToString(),
                                                  version);

                MemoryStream stream           = new MemoryStream();
                DataContractJsonSerializer ds = new DataContractJsonSerializer(typeof(Documento));
                ds.WriteObject(stream, doc);
                string jsonString = Encoding.UTF8.GetString(stream.ToArray());
                stream.Close();

                String json = jsonString.Replace("null", "\"\"");
                json = json.Replace("\":", ":");
                json = json.Replace(",\"", ",");
                json = json.Replace("{\"", "{");
                json = json.Replace("detalle", "detalles_attributes");
                json = json.Replace("Referencia", "ref_detalles_attributes");
                json = json.Replace("comisiones", "comisions_attributes");
                json = json.Replace("dscRcgGlobal", "dsc_rcg_globals_attributes");
                json = json.Replace("imptoReten", "impuesto_retens_attributes");
                json = json.Replace("mntpagos", "monto_pagos_attributes");



                if (json.IndexOf("detalles_attributes:\"\"") != -1)
                {
                    json = json.Replace("detalles_attributes:\"\"", "detalles_attributes:[]");
                }
                if (json.IndexOf("ref_detalles_attributes:\"\"") != -1)
                {
                    json = json.Replace("ref_detalles_attributes:\"\"", "ref_detalles_attributes:[]");
                }
                if (json.IndexOf("comisions_attributes:\"\"") != -1)
                {
                    json = json.Replace("comisions_attributes:\"\"", "comisions_attributes:[{}]");
                }
                if (json.IndexOf("dsc_rcg_globals_attributes:\"\"") != -1)
                {
                    json = json.Replace("dsc_rcg_globals_attributes:\"\"", "dsc_rcg_globals_attributes:[]");
                }
                if (json.IndexOf("impuesto_retens_attributes:\"\"") != -1)
                {
                    json = json.Replace("impuesto_retens_attributes:\"\"", "impuesto_retens_attributes:[]");
                }
                if (json.IndexOf("monto_pagos_attributes:\"\"") != -1)
                {
                    json = json.Replace("monto_pagos_attributes:\"\"", "monto_pagos_attributes:[]");
                }


                return(sendToServer(doc.Folio, fileCliente, fileFactura, doc.fileName, filename, json, pdfTfileName, pdfCfileName, conEnv));
            }
            catch (Exception err)
            {
                Log        log  = new Log();
                ReenvioSql renv = new ReenvioSql();
                log.addLog("ERROR envio al Core TipoDTE :" + doc.TipoDTE + " Folio :" + doc.Folio, "ERROR");
                //si no existen las columnas de fileCliente y FileFactura las crea
                LocalDataBase ldb = new LocalDataBase();
                ldb.addCollumnToReenvio();

                renv.addReenvio(doc.fileName, filename, pdfTfileName, pdfCfileName, fileCliente, fileFactura);

                Console.WriteLine(err);
                return(err.Message);
            }
        }
Пример #4
0
 private void button18_Click(object sender, EventArgs e)
 {
     ReenvioSql reenv = new ReenvioSql();
     reenv.verReenv();
 }
        public void procesoContingencia()
        {
            while (!_shouldStop)
            {

             //   Thread.Sleep(60000); // Duerme 10 minutos
                Thread.Sleep(120000);
                Console.WriteLine("ProcessContingencia thread: working...");

                Connect conn = new Connect();
                Log log = new Log();
                String ping = String.Empty;

                String envunit = String.Empty;
                String pdft = String.Empty;
                String pdfc = String.Empty;
                String jsonName = String.Empty;
                String filecliente = String.Empty;
                String filefactura = String.Empty;

                if (ping == "{\"status\":\"Ok\"}")
                {

                    ReenvioSql reenv = new ReenvioSql();
                    // saco el nombres de los archivos  json, enviomasivo.xml pdfT y pdfC

                    List<String> listaReenvio = new List<string>();

                    listaReenvio = reenv.sgteReenvio();
                    // cargo clase Documento
                    Documento doc = new Documento();
                    TxtReader json = new TxtReader();

                    int i = 0;
                    foreach (var reenvio in listaReenvio)
                    {
                        i++;
                        switch (i)
                        {
                            case 1:
                                {
                                    doc = json.lectura(reenvio, false, @"c:\IatFiles\fileprocess\");
                                    jsonName = reenvio;
                                }
                                break;
                            case 2: envunit = reenvio;
                                break;
                            case 3: pdft = reenvio;
                                break;
                            case 4: pdfc = reenvio;
                                break;
                            case 5: filecliente = reenvio;
                                break;
                            case 6: filefactura = reenvio;
                                break;

                        }
                    }
                    // llamo clase connect para reenviar
                    if (listaReenvio.Count() > 0)
                    {

                       // conn.sendInvoice(doc, pdft, pdfc, envunit,filecliente,filefactura, "S");

                        // Cambio estado del registro de reenvio
                        reenv.cambioEstadoReenvio("PROCESADO", jsonName);
                    }
                }
                else
                {
                    log.addLog("ERROR Proceso Contingencia Ping no responde Json:" + jsonName , "ERROR");
                }
            }
        }