Beispiel #1
0
        public void Exportar(IEnumerable <DocumentoRepositorio> documentos, string ruta, bool zip, Func <DocumentoRepositorio, string> rutaInterna)
        {
            if (!ruta.EndsWith("\\"))
            {
                ruta += "\\";
            }

            foreach (DocumentoRepositorio documento in documentos)
            {
                LFDocument documentoLaserfiche = documento.DocumentoAsociado as LFDocument;

                string directorioInterno = rutaInterna.Invoke(documento);

                string[] subdirs    = directorioInterno.Split('\\');
                string   rutaActual = ruta;
                for (int i = 0; i < subdirs.Length; i++)
                {
                    rutaActual += subdirs[i];
                    DirectoryInfo directorio = new DirectoryInfo(rutaActual);
                    if (!directorio.Exists)
                    {
                        directorio.Create();
                    }
                }


                ExportarDocumento(ruta + directorioInterno, documentoLaserfiche);
            }

            Zippear(ruta, zip);
        }
Beispiel #2
0
        protected void ExportarDocumento(string ruta, LFDocument documentoLaserfiche, bool throwError = false)
        {
            if (documentoLaserfiche.Name.ToLowerInvariant().Contains("cove"))
            {
                return;
            }
            //Verificar el tipo de documento ya que los documentos escaneados se descargan como TIFF
            //documentoLaserfiche.
            try
            {
                if (documentoLaserfiche.ElectFile.IsEmpty)
                {
                    //Descargar documento escaneado TIFF
                    var exportadorPdf = new PdfExporter.PdfExporter();

                    exportadorPdf.ExportPagesToFile(documentoLaserfiche, ruta + documentoLaserfiche.Name + ".pdf");
                }
                else
                {
                    try
                    {
                        documentoLaserfiche.ElectFile.ReadStream.Open();
                        documentoLaserfiche.ElectFile.ReadStream.Export(ruta + documentoLaserfiche.Name + "." + documentoLaserfiche.ElectFile.Extension);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        documentoLaserfiche.ElectFile.ReadStream.Close();
                    }
                }
            }
            catch (Exception e)
            {
                //if (!throwError)
                //{
                //    conexionLF.Connect(documentoLaserfiche.Database);
                //    ExportarDocumento(ruta, documentoLaserfiche, true);
                //}
                //else
                //{
                //    throw e;
                //}
            }
        }
Beispiel #3
0
        public void Exportar(IEnumerable <DocumentoRepositorio> documentos, string ruta, bool zip)
        {
            if (!ruta.EndsWith("/"))
            {
                ruta += "/";
            }


            foreach (DocumentoRepositorio documento in documentos)
            {
                LFDocument documentoLaserfiche = documento.DocumentoAsociado as LFDocument;

                ExportarDocumento(ruta, documentoLaserfiche);
            }

            Zippear(ruta, zip);
        }
Beispiel #4
0
        private static void ExtraerDocumentos(List <DocumentoRepositorio> resultado, string referencia, LFFolder documentoLaserfiches)
        {
            //LFDocument documentoLaserfiche = searchHitLF.Entry as LFDocument;
            //LFDirectoryEntry documentoLaserfiches = searchHitLF.Entry as LFDirectoryEntry;
            //ILFEntry documentoLaserfichevs = searchHitLF.Entry as ILFEntry;
            //documentoLaserfichevs.EntryType == Entry_Type.ENTRY_TYPE_DOCUMENT;


            ILFCollection coleccionLaserfiche = documentoLaserfiches.GetChildren();

            foreach (ILFEntry entrada in coleccionLaserfiche)
            {
                if (entrada.EntryType == Entry_Type.ENTRY_TYPE_DOCUMENT)
                {
                    LFDocument documentoLaserfiche  = entrada as LFDocument;
                    var        documentoRepositorio = new DocumentoRepositorio();
                    documentoRepositorio.Referencia        = referencia;
                    documentoRepositorio.DocumentoAsociado = entrada;
                    documentoRepositorio.IdDocumento       = documentoLaserfiche.ID.ToString();
                    documentoRepositorio.Nombre            = documentoLaserfiche.Name;
                    documentoRepositorio.Ruta = documentoLaserfiche.FullPath;

                    if (documentoLaserfiche.ElectFile != null)
                    {
                        documentoRepositorio.TipoMime = documentoLaserfiche.ElectFile.MimeType;
                    }

                    if (documentoLaserfiche.Template != null)
                    {
                        documentoRepositorio.Plantilla = documentoLaserfiche.Template.Name;
                    }

                    resultado.Add(documentoRepositorio);
                }
                else if (entrada.EntryType == Entry_Type.ENTRY_TYPE_FOLDER)
                {
                    ExtraerDocumentos(resultado, referencia, entrada as LFFolder);
                }
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var t = new ExportadorDocumentosLaserfiche <Something>();

            t.ExportarAsync(new List <DocumentoRepositorio>(), "", true).ConfigureAwait(false);
            SqlConnection con = new SqlConnection();

            Trace.Listeners.Add(new ConsoleTraceListener());

            //Conectamos a Laserfiche
            LFConnection conexionLF = new LFConnection();

            conexionLF.UserName = "******";
            conexionLF.Password = "******";

            LFApplication aplicacionLF  = new LFApplication();
            LFServer      servidorLF    = aplicacionLF.GetServerByName("ServerWA");
            LFDatabase    baseDeDatosLF = servidorLF.GetDatabaseByName("DA-HINOJOSA");


            //Se obtienen las referencias que se encuentran en


            try
            {
                Trace.WriteLine("Conectando a laserfiche");
                conexionLF.Create(baseDeDatosLF);
                //conexionLF.Connect(baseDeDatosLF);
                Trace.WriteLine("Conectado");


                //LFSearch busquedaLF = baseDeDatosLF.CreateSearch();
                //busquedaLF.Command = "{LF:LOOKIN=\"DA-HINOJOSA\\MANZANILLO\\2018\\GALVAPRIME, S.A. DE C.V. ID2281\\IMPO\\Z1801770-0A\", Subfolders=0} & {LF:Name=\"PEDIMENTO FORMATO ANTERIOR\", TYPE=\"D\"}";

                Trace.WriteLine("Inicia búsqueda");
                //busquedaLF.BeginSearch(true);
                Trace.WriteLine("Busqueda finalizada");

                //ILFCollection coleccionLF = busquedaLF.GetSearchHits();
                //14694366
                //var doc2 = baseDeDatosLF.GetEntryByID(14658218);
                var        doc2  = baseDeDatosLF.GetEntryByID(14694366);
                LFDocument doc   = doc2 as LFDocument;
                ILFEntry   entry = doc2 as ILFEntry;

                var pe = new PdfExporter.PdfExporter();


                //doc.ElectFile.WriteStream.


                //long size = doc.ElectFileSize;
                //byte[] buffer = new byte[size];

                //doc.ElectFile.ReadStream.Open();


                //doc.ElectFile.ReadStream.ReadToBuffer(buffer);
                //doc.ElectFile.ReadStream.Close();

                //using (FileStream st = File.Create("something"))
                //{
                //    st.Write(buffer, 0, Convert.ToInt32(size));
                //    st.Flush();
                //}



                //doc.ElectFile.WriteStream.

                var exportador = new DocumentExporter();
                exportador.SourceDocument = entry;
                //exportador.SourceDocument = doc.;

                //                exportador.
                //exportador.

                if (doc.ElectFile.MimeType == "application/pdf")
                {
                    try
                    {
                        doc.ElectFile.ReadStream.Open();
                        doc.ElectFile.ReadStream.Export(@"c:\users\analista.programador\downloads\lf\" + doc.Name + ".pdf");
                    }catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        doc.ElectFile.ReadStream.Close();
                    }



                    var doc3 = (doc.ElectFile.Document as ILFDocument);
                    pe.ExportPagesToFile(doc3, @"c:\users\analista.programador\downloads\lf\" + doc.Name + ".pdf");
                }
                else
                {
                    //exportador.Format = Document_Format.DOCUMENT_FORMAT_EMBED_FAVOR_PDFA;
                    //exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" + doc.Name + ".pdf");

                    exportador.Format = Document_Format.DOCUMENT_FORMAT_TIFF;
                    exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" + doc.Name + "2");
                }


                //foreach (LFSearchHit laserficheHit in coleccionLF)
                //{

                //    LFDocument entradaLF = laserficheHit.Entry as LFDocument;
                //    //LFElectFile entradaLF2 = laserficheHit.Entry as LFElectFile;



                //    Console.WriteLine(entradaLF.ElectFile.Extension);

                //     //entradaLF.
                //     var exportador = new DocumentExporter();
                //    exportador.SourceDocument = entradaLF;

                //    Trace.WriteLine("Iniciando descarga de " + entradaLF.Name);
                //    exportador.Format = Document_Format.DOCUMENT_FORMAT_EMBED_FAVOR_PDFA;
                //    exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" +  entradaLF.Name + ".pdf" );

                //    exportador.Format = Document_Format.DOCUMENT_FORMAT_TIFF;
                //    exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" + entradaLF.Name + "2");

                //    exportador.Format = Document_Format.DOCUMENT_FORMAT_ELECTRONICFILE;
                //    exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" + entradaLF.Name + "3");
                //}
                //using(FileStream file = File.Create(""))
                //{
                //    StreamWriter sw = new StreamWriter(file);
                //    sw.WriteLine("");
                //    sw.Flush();


                //}
            }
            catch (Exception exc)
            {
                Trace.TraceError(exc.Message);
            }
            finally
            {
                if (!conexionLF.IsTerminated)
                {
                    conexionLF.Terminate();
                    Trace.WriteLine("Desconectado");
                }
            }


            Console.ReadKey();
        }