Thursday, 24 April 2014

SSIS: PRE-PROCESS VALIDATION

SSIS: PRE-PROCESS VALIDATION
The preprocess validation is implemented for validating the presence of essential folders, files , for verifying the count of files in different folders, deleting the records in Error folders before proceeding with package execution. This is usually followed after the Common config reader package reads the configuration file and save its values to the package variables.


Variables used:
strSourcePath is having the Source folder path.
strFileCheckError is having ‘’ value and the package will gracefully end execution when it is having any value other than ‘’.
strTemplatePath is having the template file name to be verified along with the path.
strArchivePath holds the archive location path.
strErrorPath holds the error file location path.

Validation type
Source Code

Directory Validation

if(Directory.Exists(Dts.Variables["User::strSourcePath"].Value.ToString()))
  {
Dts.Variables["User::strFileCheckError"].Value = Dts.Variables["User::strFileCheckError"].Value;
  }

else
  {
Dts.Variables["User::strFileCheckError"].Value = Dts.Variables["User::strFileCheckError"].Value + "Source directory Not Found";
  }

File Validation

if(File.Exists(Dts.Variables["User::strTemplatePath"].Value.ToString()))
  {           Dts.Variables["User::strFileCheckError"].Value =Dts.Variables["User::strFileCheckError"].Value;
  }

else
  {                   Dts.Variables["User::strFileCheckError"].Value = Dts.Variables["User::strFileCheckError"].Value + "Template directory Not Found";
   }

0 KB Size Validation for Input file

FileInfo Files = new FileInfo(Dts.Variables["User::strTempFilename"].Value.ToString());

isValidFilename = true;

if (Files.Length == 0)
  {  Files.MoveTo(Dts.Variables["User::strArchivePath"].Value.ToString());
  }


Input File Name Validation

FileInfo Files = new FileInfo(Dts.Variables["User::strTempFilename"].Value.ToString());

string filename = Path.GetFileName(Dts.Variables["User::strTempFilename"].Value.ToString());

if(!filename.Contains("MPWR"))
 {
   Dts.Variables["User::blCorrectFileName"].Value = false;
   Files.MoveTo(Dts.Variables["User::strErrorPath"].Value.ToString());
 }

Deleting files from Error Location

if (Directory.Exists(Dts.Variables["User::strErrorPath"].Value.ToString()))
 {

   //Get the Directory Details
DirectoryInfo Dir = new   DirectoryInfo(Dts.Variables["User::strErrorPath"].Value.ToString());
   int counter = Dir.GetFiles().Length;

   if (counter >= 1)
    {  
                
      foreach (var file in Dir.GetFiles("*.*"))
         {

           file.Delete();                       
         }
     }
  }

Get the count of files in Source folder

DirectoryInfo SourceDir = new DirectoryInfo(Dts.Variables["User::strSourcePath"].Value.ToString());
int count = SourceDir.GetFiles().Length;
if(count == 0)
{
Dts.Variables["User::strFileCheckError"].Value = Dts.Variables["User::strFileCheckError"].Value + "Source directory is Empty";
}

 

No comments:

Post a Comment