Hi Experts.
I get error while deleting the file using system.io delete during batch job. however get no error & fiile get successfuly deleted when running same code as non btach.
Please suggest fix for following
1. How do i get to delete the file in batch & non batch mode
2. How do i get to move the file in batch & non batch mode.
3. Currently it does not capture the details of why the batch job failed, what can i do to improvise my catch block so that it capture the details of generic failures i.e. exception from info cllass's add exception .
Here is the complete code. Thanks in advance.
public void run()
{
str fileNameString,fileNamePath;
MyCustom msg;
System.IO.DirectoryInfo directory,processedDirectory;
System.IO.FileInfo[] files;
System.IO.FileInfo file;
//Set permissionSet;
InteropPermission permission;
counter filesCount;
FilePath processedFilePath,processedFileCompletePath;
Filename filename,filepath,fileType;
Filename tmpFilePath;
Filename tmpFileNameShort;
Filename tmpFileExt;
counter loop;
str fileNameOnly,fileNameTemp;
filetype type;
boolean skipZeroTrans;
boolean wrongFileFormat = false;
#FILE
try
{
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
select myCustomTable;
skipZeroTrans = myCustomTable.skipZeroTransVal;
directory = new System.IO.DirectoryInfo(@myCustomTable.FilePath);
filepath = @myCustomTable.myCustomTablelFilePath;
processedDirectory = new System.IO.DirectoryInfo(@myCustomTable.ProcessedFilePath);
processedFilePath = @myCustomTable.ProcessedFilePath;
files = directory.GetFiles("*.csv*");
filesCount = files.get_Length();
for (loop = 0; loop < filesCount; loop )
{
file = files.GetValue(loop);
fileNameTemp = file.get_FullName();
filename = fileNameTemp;
info(strFmt("filename: %1",filename));
if (strLen(fileNameTemp) > 0)
{
[tmpFilePath, tmpFileNameShort, tmpFileExt] = fileNameSplit(fileNameTemp);
fileNameString= tmpFileNameShort tmpFileExt;
info(strFmt('Import filename=%1', fileNameTemp));
if(tmpFilePath && tmpFileNameShort && tmpFileExt == #csv)
{
msg = this.processFile(fileNameTemp,skipZeroTrans);
}
else
{
if (strLen(tmpFilePath) == 0)
{
error("Filepath not specified");
}
wrongFileFormat = true;
Error (strFmt("%1 unsupported fileType", tmpFileExt));
}
if ( strScan(msg,"Error",0,strLen(msg)))
{
throw error("Error encountered while processing file");
}
this.myWriteMessage(tmpFilePath,tmpFileNameShort,msg);
info(msg);
System.IO.File::Delete(filename); //TODO 1 RUNS FINE IN NON BATCH MODE BUT ERRORS IN BATCH MODE ONCE FIXED USE either DELETE or MOVE
// CHECK FILE MOVE CODE
/* // processedFilePath = processedFilePath "\n\\" tmpFileNameShort;
//permissionSet = new Set(Types::Class);
//permissionSet.add(new FileIOPermission(filename, #io_write));
//permissionSet.add(new FileIOPermission(processedFilePath, #io_write));
//permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
//CodeAccessPermission::assertMultiple(permissionSet);
// CodeAccessPermission::revertAssert();
//processedFileCompletePath = processedFilePath "\n\\" tmpFileNameShort tmpFileExt;
//System.IO.File::Move(filename,processedFileCompletePath);
//System.IO.File::Move(fileName, newFileName); */ //TODO 2 ERRORS IN BOTH BATCH & NON BATCH MODE
}
}// for ends
} // Try ends
catch
{
if (wrongFileFormat == true)
{
this.myWriteMessage(tmpFilePath,tmpFileNameShort,msg);
throw Error (strFmt("%1 Unsupported file type", fileType));
}
else if (Exception::Error && Exception::CLRError)
{
this.myWriteMessage(tmpFilePath,tmpFileNameShort,msg);
throw Error (msg "Exception" ); //TODO 3 Explore how can you replace "Exception" with exception from info add exception so as to capture the details of geneic failures.
}
else if (Exception::DuplicateKeyException && Exception::DuplicateKeyExceptionNotRecovered)
{
this.myWriteMessage(tmpFilePath,tmpFileNameShort,msg);
throw error(strFmt("Error encountered while processng the file. \n Read log at %1 path for details",tmpFilePath));
}
}
}//Run method ends
Thanks
Mav