SSIS Reverse Engineering Part II Revision I
After some thoughts on how to made the code simple and better I created new changes to the previous post, the class to traverse ssis packages; however, trying to get the best balance is hard work. So, I fired the changes and after arriving home I continue minor changes in the progress of other classes. As a short note my son's discover Japanese anime and I can't get him to help me as my personal assistant ( He is only 12 ) now he is watching Mysterious Girlfriend X and I just starting look like an angry martian. Parenting is almost like coding you make it, refined, love it, but at the end there are those little things that sometime drives us crazy.
Well here is the code change enjoy:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using System.IO;
namespace LPS.ETL.SSIS
{
public class ssisReverse
{
ssisPackage _package;
#region constructor
#endregion
#region public properties
public ssisReverse(String PackageDirectoryPath, String PackageName)
{
String FullFilePath = PackageDirectoryPath + "\\" + PackageName + ".dtsx";
if (File.Exists(FullFilePath))
{
_package = new ssisPackage(FullFilePath);
}
else
{
Console.WriteLine("Error: {0} Package Not found", FullFilePath);
}
}
#endregion
#region public sub modules
public void DisplayResults()
{
SearchPackage(_package.getExecutables);
}
#endregion
#region private sub modules
// Search Packge Module to find Components
private void SearchPackage (Executables CollExec)
{
int count = 0;
int count2 = (CollExec.Count);
while (count != (count2))
// foreach (Executable exc in CollExec)
{
Executable exc = CollExec[count++];
switch (exc.GetType().Name)
{
case "TaskHost":
TaskHost th = (TaskHost)exc;
GetTaskHost(th);
GetEventHandlers(th.EventHandlers);
//th = null;
continue;
case "Sequence":
Sequence seq = (Sequence) exc;
Console.WriteLine("Sequence Container - {0}", seq.Name);
SearchPackage(seq.Executables);
GetEventHandlers(seq.EventHandlers);
GetPrecedence(seq.PrecedenceConstraints);
// seq = null;
continue;
case "ForEachLoop":
ForEachLoop fel = (ForEachLoop)exc;
Console.WriteLine("ForEachLoop Container - {0}", fel.Name);
SearchPackage(fel.Executables);
GetEventHandlers(fel.EventHandlers);
GetPrecedence(fel.PrecedenceConstraints);
// fel = null;
continue;
case "ForLoop":
ForLoop fl = (ForLoop)exc;
Console.WriteLine("ForLoop Container - {0}", fl.Name);
SearchPackage(fl.Executables);
GetEventHandlers(fl.EventHandlers);
GetPrecedence(fl.PrecedenceConstraints);
// fl = null;
continue;
}
}
}
// Recursive to find evenths
private void GetEventHandlers(DtsEventHandlers colleventh)
{
foreach (DtsEventHandler eventh in colleventh)
{
SearchPackage(eventh.Executables);
}
}
// Find dataflows
private void GetTaskHost(TaskHost th)
{
if (th == null)
{
return;
}
Console.WriteLine("TaskHost : {0}", th.Name);
MainPipe pipeline = th.InnerObject as MainPipe;
if (pipeline != null)
{
GetPipeline(pipeline);
}
}
//SQL 2005
private void GetPipeline(MainPipe pipe)
{
foreach (IDTSComponentMetaData90 componentMetadata in pipe.ComponentMetaDataCollection)
{
Console.WriteLine("DataFlow Components - {0}", componentMetadata.Name);
}
}
private void GetPrecedence(PrecedenceConstraints precedenceconstraints)
{
foreach (PrecedenceConstraint pre in precedenceconstraints)
{
Console.WriteLine("PrecedenceConstrain: {0}", pre.PrecedenceExecutable.ToString());
}
}
#endregion
}
}
No comments:
Post a Comment