Exemplo n.º 1
0
        /**
         *
         *
         */
        private static void ConvertFiles(Registro registro, Corte corte, string FileName)
        {
            bool     procesar    = false;
            string   fileNameTxt = string.Empty;
            string   path        = Settings.Default.PDFPath;
            FileInfo file        = new FileInfo(Settings.Default.PDFPath + "\\" + FileName);

            try
            {
                //Intentamos convertirlo en pdf
                FirstTestCase.regLog("Convirtiendo archivo:" + FileName);

                System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
                pProcess.StartInfo.FileName               = @Settings.Default.PathToPdfToText;
                pProcess.StartInfo.Arguments              = file.FullName;
                pProcess.StartInfo.UseShellExecute        = false;
                pProcess.StartInfo.RedirectStandardOutput = true;
                pProcess.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                pProcess.StartInfo.CreateNoWindow         = true;       //not diplay a windows
                pProcess.Start();
                Console.WriteLine(pProcess.StandardOutput.ReadToEnd()); //The output result
                pProcess.WaitForExit();

                fileNameTxt = file.FullName.Replace(file.Extension, "") + ".txt";
                procesar    = true;
                FirstTestCase.regLog(FileName + ", Tranformado a PDF");
            }catch (Exception ex) {
                try{
                    //Tratamos de convertirlo en doc
                    FirstTestCase.regLog("Convirtiendo archivo:" + file.Name);

                    System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
                    pProcess.StartInfo.FileName               = @Settings.Default.PathToLibreOffice;
                    pProcess.StartInfo.Arguments              = " --convert-to txt --outdir " + file.FullName;
                    pProcess.StartInfo.UseShellExecute        = false;
                    pProcess.StartInfo.RedirectStandardOutput = true;
                    pProcess.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                    pProcess.StartInfo.CreateNoWindow         = true;       //not diplay a windows
                    pProcess.Start();
                    Console.WriteLine(pProcess.StandardOutput.ReadToEnd()); //The output result
                    pProcess.WaitForExit();

                    fileNameTxt = file.FullName.Replace(file.Extension, "") + ".txt";
                    procesar    = true;
                    FirstTestCase.regLog(FileName + ", Tranformado a DOC");
                }catch (Exception exp) {
                    fileNameTxt = file.FullName.Replace(file.Extension, "") + ".txt";
                    file.CopyTo(fileNameTxt);
                    procesar = true;
                    FirstTestCase.regLog(FileName + ", Tranformado a txt");
                }
            }

            //Guardamos los datos en la base de datos
            if (File.Exists(fileNameTxt) && procesar == true)
            {
                try
                {
                    //creamos el Fallo
                    Fallo fallo = new Fallo();
                    fallo.tribunal = corte.loesid.ToString();
                    fallo.rol      = registro.rol.Trim();
                    fallo.fecha    = registro.fecha.Trim();
                    fallo.partes   = registro.partes.Trim();

                    string fileNameTxtClean = @Settings.Default.PathTxt + "\\" + corte.loesid.ToString() + "\\" + fallo.rol + ".txt";
                    File.Copy(fileNameTxt, fileNameTxtClean, true);
                    FirstTestCase.regLog("Limpiando archivo (" + file.Name + ")" + fileNameTxtClean);
                    FirstTestCase.cleanFile(fileNameTxtClean, ref fallo);
                    FirstTestCase.saveAndValidate(fallo, corte);
                }
                catch (Exception ex)
                {
                    FirstTestCase.regLog(ex.Message + "\r\n" + ex.InnerException);
                    FirstTestCase.regLog("[ERROR] Linea 380, posiblemente copy, delete, clean o save and validate");
                }
            }
            else
            {
                FirstTestCase.regLog("[ERROR] El archivo " + fileNameTxt + ", no existe.");
            }
        }