Ejemplo n.º 1
0
 private bool bMoveFile(ooFtpBO oFtpIn, string sOriginalPath, String sNewPath, string sFile, ooInfoDocumentoBE oInfoDoc)
 {
     bool bResp = false;
     try
     {
         ooFileBO oFiles = new ooFileBO(); //For combine and remove temporary files.
         if(oInfoDoc.bIsStandard){
             oFtpIn.upload(oFiles.sPathCombine(sNewPath, sFile), sFile); //copy file into new directory
             oFtpIn.delete(oFiles.sPathCombine(sOriginalPath, sFile)); //existing file in old directory is deleted
         }
         else
         {
             oFtpIn.renameShell(oInfoDoc,sFile, oFiles.sPathCombine(sNewPath, sFile));
         }
         oFiles.moveFile(oFiles.sPathCombineWin(System.AppDomain.CurrentDomain.BaseDirectory, sFile), oFiles.sPathCombineWin(System.AppDomain.CurrentDomain.BaseDirectory, System.Configuration.ConfigurationManager.AppSettings["sInternalTempDirectory"]));
         bResp = true;
     }
     catch (Exception ex)
     {
         this.oLog.LogError(ex.Message);
     }
     return bResp;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Funcion de uso general con la lógica para mover los archivos
        /// </summary>
        /// <param name="oInfoDoc"></param>
        /// <param name="lstFiles"></param>
        /// <returns></returns>
        public int moverDocumentos(ooInfoDocumentoBE oInfoDoc, List<string> lstFiles)
        {
            int lProcesados = 0;
            ooFileBO oFiles = new ooFileBO(); //For combine and remove temporary files.
            ooFtpBO oFtpIn;// = new ooFtpBO(oInfoDoc.sInPath, oInfoDoc.sInUsuarioFTP, oInfoDoc.sInPasswordFTP, oLog);//Reading server connection
            ooFtpBO oFtpOut;// = new ooFtpBO(oInfoDoc.sOutPath, oInfoDoc.sOutUsuarioFTP, oInfoDoc.sOutPasswordFTP, oLog); //Writting server connection
            this.oLog.LogInfo(String.Format("Inicio lectura de operaciones de tipo {0} en estado sin procesar.", lstFiles.Count));

            string sDocType = string.Empty; //to be used in foreach flow.
            string sDocNumber = string.Empty; //IDEM

            foreach (string item in lstFiles)
            {
                sDocType = string.Empty;
                sDocNumber = string.Empty;
                oFtpIn = new ooFtpBO(oInfoDoc.sInPath, oInfoDoc.sInUsuarioFTP, oInfoDoc.sInPasswordFTP, oLog);

                oFtpOut = new ooFtpBO(oInfoDoc.sOutPath, oInfoDoc.sOutUsuarioFTP, oInfoDoc.sOutPasswordFTP, oLog); //Writting server connection
                if (item.Length > 0)
                {
                    oLog.LogInfo("El archivo a trabajar es:"+item);

                    try
                    {
                        this.oLog.LogInfo("Se está accediendo al host: "+ oInfoDoc.sInPath);
                        this.oLog.LogInfo("Se esta leyendo el archivo " + oFiles.sPathCombine(oInfoDoc.sInPathWork, item));
                        //If source is standard, a regular download instruction will be used, else, the shell instruction is needed
                        bool bDownload = (oInfoDoc.bIsStandard ? oFtpIn.download(oFiles.sPathCombine(oInfoDoc.sInPathWork, item), item) : oFtpIn.downloadShell(oInfoDoc, item));

                        //If filename include document information, then we can continue, else need to be marked as error
                        if (bDownload && this.bDocumentInfo(out sDocType, out sDocNumber, item))
                        {
                            bool bStateUpload = false;
                            bool bStateDownload = oFtpIn.bCheckFileDownload(oFiles.sPathCombineWin(System.AppDomain.CurrentDomain.BaseDirectory, item));
                            if (bStateDownload)
                            {
                                bStateUpload = oFtpOut.upload(this.cNewName(item), oFiles.sPathCombineWin(System.AppDomain.CurrentDomain.BaseDirectory, item));
                            }
                            else
                            {
                                this.bMoveFile(oFtpIn, oInfoDoc.sInPathWork, oInfoDoc.sInPathError, item, oInfoDoc);
                                this.oConnectionBD.updateError(sDocType, sDocNumber, "Download failed.");
                                oLog.LogInfo("Downloading file error");
                            }

                            if (bStateUpload)
                            {
                                this.oLog.LogInfo("File will be moved");
                                this.bMoveFile(oFtpIn, oInfoDoc.sInPathWork, oInfoDoc.sInPathProcessed, item, oInfoDoc);
                                this.oConnectionBD.updateOK(sDocType, sDocNumber);
                                lProcesados++;
                            }
                            else
                            {
                                this.bMoveFile(oFtpIn, oInfoDoc.sInPathWork, oInfoDoc.sInPathError, item, oInfoDoc);
                                this.oConnectionBD.updateError(sDocType, sDocNumber, "Upload failed.");
                                oLog.LogInfo("Uploading file error");
                            }
                        }
                        else
                        {
                            this.oLog.LogInfo("File don't include document information");
                            this.bMoveFile(oFtpIn, oInfoDoc.sInPathWork, oInfoDoc.sInPathError, item, oInfoDoc);
                            //I can't mark in DB, because file doesn't have information to identify some register on DB.
                        }
                    }
                    catch (Exception ex)
                    {
                        this.bMoveFile(oFtpIn, oInfoDoc.sInPathWork, oInfoDoc.sInPathError, item, oInfoDoc);
                        this.oConnectionBD.updateError(sDocType, sDocNumber, ex.Message);
                        this.oLog.LogError(String.Format("Se ha producido un error al traspasar el archivo {0}, con la siguiente descripcion: {1}.", item, ex.Message));
                    }
                }
            }
            return lProcesados;
        }