/// <summary> /// Download files from Ftp location /// </summary> /// <param name="folderSetting">FolderSetting from configuration to get the source ftp path & target folder</param> /// <param name="log">Thread specific logger</param> /// <param name="downloadedFileCount">To get the count of downloaded files from ftp</param> /// <returns>returns - Total files available in the ftp folder</returns> private int DownloadFilesFromSftp(Folder folderSetting, ILog log, out int downloadedFileCount) { string localFilePath = string.Empty; string localFileFolder = string.Empty; string message = string.Empty; int totalFileFound = 0; downloadedFileCount = 0; lock (sftplock) { try { log.Info("Inside Method"); SftpCallDataReader sftpReader = new SftpCallDataReader(folderSetting.ServerIP, folderSetting.ServerPort, folderSetting.SourcePath, folderSetting.FtpUserId, folderSetting.FtpPassword); sftpReader.FolderHierarchy = DirectoryHierarchy.None; FileCallDataImporter fileImporter = new FileCallDataImporter(folderSetting.TargetPath); fileImporter.FolderHierarchy = DirectoryHierarchy.DateHour; sftpReader.ReadCallData(); totalFileFound = sftpReader.CallDataList.Count; log.InfoFormat("{0} Files Found At {1}", totalFileFound, folderSetting.SourcePath); if (totalFileFound == 0) { return(0); } foreach (IvrCallData callData in sftpReader.CallDataList) { FtpCallData ftpCallData = callData as FtpCallData; Hashtable htParams = new Hashtable(); string fileName = System.IO.Path.GetFileNameWithoutExtension(ftpCallData.FtpFilePath); string fileExtn = System.IO.Path.GetExtension(ftpCallData.FtpFilePath).Replace(".", ""); htParams["FILE_NAME"] = fileName; htParams["FILE_EXTENSION"] = fileExtn; htParams["CALL_DATA"] = ftpCallData.CallData; fileImporter.ImportCallData(htParams); } log.InfoFormat("{0} Files Downloaded From {1}", downloadedFileCount, folderSetting.SourcePath); if (downloadedFileCount < totalFileFound) { message = string.Format("{0} Files Unable to Download From {1} ", totalFileFound - downloadedFileCount, folderSetting.SourcePath); log.InfoFormat(message); } } catch (Exception ex) { message = string.Format("Error Occured while downloading the files from ftp : {0}", folderSetting.SourcePath); log.Error(message, ex); } return(totalFileFound); } }
/// <summary> /// Download files from Shared Folder /// </summary> /// <param name="folderSetting">FolderSetting from configuration to get the source folder & target folder</param> /// <param name="log">Thread specific logger</param> /// <param name="downloadedFileCount">To get the count of retrieved files from shared path</param> /// <returns>returns - Total files available in the shared folder</returns> private int DownloadFilesFromSharedFolder(Folder folderSetting, ILog log, out int downloadedFileCount) { string localFilePath = string.Empty; string localFileFolder = string.Empty; string message = string.Empty; int totalFileFound = 0; downloadedFileCount = 0; try { log.Info("Inside Method"); FileCallDataReader fileCallDataReader = new FileCallDataReader(folderSetting.SourcePath); fileCallDataReader.FolderHierarchy = DirectoryHierarchy.None; FileCallDataImporter fileCallDataImporter = new FileCallDataImporter(folderSetting.TargetPath); fileCallDataImporter.FolderHierarchy = DirectoryHierarchy.DateHour; fileCallDataReader.ReadCallData(); totalFileFound = fileCallDataReader.CallDataList.Count; log.InfoFormat("{0} Files Found At {1}", totalFileFound, folderSetting.SourcePath); if (totalFileFound == 0) { return(0); } foreach (IvrCallData ivrCallData in fileCallDataReader.CallDataList) { FileCallData fileCallData = ivrCallData as FileCallData; Hashtable htParams = new Hashtable(); htParams["FILE_NAME"] = System.IO.Path.GetFileNameWithoutExtension(fileCallData.FilePath); htParams["FILE_EXTENSION"] = System.IO.Path.GetExtension(fileCallData.FilePath).Replace(".", ""); htParams["CALL_DATA"] = fileCallData.CallData; fileCallDataImporter.ImportCallData(htParams); File.Delete(fileCallData.FilePath); downloadedFileCount++; } log.InfoFormat("{0} Files Downloaded From {1}", downloadedFileCount, folderSetting.SourcePath); if (downloadedFileCount < totalFileFound) { message = string.Format("{0} Files Unable to Download From {1} ", totalFileFound - downloadedFileCount, folderSetting.SourcePath); log.InfoFormat(message); } } catch (Exception ex) { message = string.Format("Error Occured while downloading the files from shared path : {0}", folderSetting.SourcePath); log.Error(message, ex); } return(totalFileFound); }