I want to to avoid duplicate file listing while downloading files via rebex.
Actually I got a solution for memory exception to fetch large volume of files from rebex for a single file type. But while doing so for multiple Inward file types and extensions for each message type,We are looping the message type and Extensions as enumerators for each message type count is not coming fine with new Code.
public enum Extension
{
SHA =1,
DDR = 2,
PDF = 3,
ACK = 4,
NAK = 5,
}
public enum InwardMessageType
{
DDS210 = 210,
DDS300 = 300,
DDS310 = 310,
DDS400 = 400,
DDS501 = 501,
DDS503 = 503,
DDS598 = 598,
ACKNAK = 10,
REP =12,
}
Existing Method
private List<SFTPFile> ListInwardCBFiles()
{
_listSftp = new Sftp();
SFTPFile objSFTPFile;
List<SFTPFile> ListSFTPFile = new List<SFTPFile>();
try
{
if (ConnectSftp(_listSftp))
{
foreach (InwardMessageType t in Enum.GetValues(typeof(InwardMessageType)))
{
foreach (CBExtension r in Enum.GetValues(typeof(CBExtension)))
{
SftpItemCollection List = _listSftp.GetList(GetSFTPServerPath(Enum.GetName(typeof(InwardMessageType), t)) + "//" + "*." + Enum.GetName(typeof(CBExtension), r));
foreach (SftpItem item in List)
{
objSFTPFile = new SFTPFile();
objSFTPFile.FileType = Enum.GetName(typeof(InwardMessageType), t);
objSFTPFile.Extension = Enum.GetName(typeof(CBExtension), r);
objSFTPFile.Status = SFTPStatus.L.ToString();
objSFTPFile.FileName = item.Name.Trim();
objSFTPFile.FileSize = item.Size;
objSFTPFile.Mode = SFTPMode.D.ToString();
objSFTPFile.BankCode = Common.BANKCODE;
ListSFTPFile.Add(objSFTPFile);
Common.WriteLog(MethodInfo.GetCurrentMethod().Name + " FileType: " + objSFTPFile.FileType + " FileName: " + objSFTPFile.FileName, ServiceThread.Listing.ToString());
}
}
}
}
}
catch (Exception ex)
{
Common.WriteLog("Exception while listing files in the folder " + Environment.NewLine + ex.Message, ServiceThread.Listing.ToString());
}
finally
{
DisConnectSftp(_listSftp);
}
return ListSFTPFile;
}
Rebex Code
private List<SFTPFile> ListInwardCBFilesRebexCode()
{
_listSftp = new Sftp();
SFTPFile objSFTPFile;
List<SFTPFile> ListSFTPFile = new List<SFTPFile>();
try
{
if (ConnectSftp(_listSftp))
{
foreach (InwardMessageType t in Enum.GetValues(typeof(InwardMessageType)))
{
foreach (CBExtension r in Enum.GetValues(typeof(CBExtension)))
{
_listSftp.ListItemReceived += (s, e) =>
{
SftpItem item = e.Item;
objSFTPFile = new SFTPFile();
objSFTPFile.FileType = Enum.GetName(typeof(InwardMessageType), t);
objSFTPFile.Extension = Enum.GetName(typeof(CBExtension), r);
objSFTPFile.Status = SFTPStatus.L.ToString();
objSFTPFile.FileName = item.Name.Trim();
objSFTPFile.FileSize = item.Size;
objSFTPFile.Mode = SFTPMode.D.ToString();
objSFTPFile.BankCode = Common.BANKCODE;
ListSFTPFile.Add(objSFTPFile);
Common.WriteLog(MethodInfo.GetCurrentMethod().Name + " FileType: " + objSFTPFile.FileType + " FileName: " + objSFTPFile.FileName, ServiceThread.Listing.ToString());
// skip adding item to resulting collection
e.Ignore();
};
// clear resulting collection first
//ListSFTPFile.Clear();
// issue directory listing
SftpItemCollection List = _listSftp.GetList(GetSFTPServerPath(Enum.GetName(typeof(InwardMessageType), t)) + "//" + "*." + Enum.GetName(typeof(CBExtension), r));
//SftpItemCollection List = _listSftp.GetList(GetSFTPServerPath("DDS300"));
}
}
}
}
catch (Exception ex)
{
Common.WriteLog("Exception while listing files in the folder " + Environment.NewLine + ex.Message, ServiceThread.Listing.ToString());
}
finally
{
DisConnectSftp(_listSftp);
}
return ListSFTPFile;
}