c# - Create Script Component as Source Programmatically -
c# - Create Script Component as Source Programmatically -
i working on programmatically creating bundle info flow task containing script component source. have been able create package, info flow task, , add together script component. however, script component appears default transform.
does know how souce?
here class single method i'm working on:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using dynamicpackagecreator.models; using microsoft.sqlserver.dts.runtime; using system.io; using microsoft.sqlserver.dts.pipeline.wrapper; // alias prevent ambiguity using dtscolumndatatype = microsoft.sqlserver.dts.runtime.wrapper.datatype; namespace dynamicpackagecreator { public class dtsclient { public void createpackagewithdataflowandscriptsource(string filepath, string dataflowname, string sourcename, list<outputdefinition> outputdefinitions) { // create bundle bundle pkg = new package(); pkg.name = path.getfilenamewithoutextension(filepath); // create dataflow task executable e = pkg.executables.add("stock:pipelinetask"); taskhost thmainpipe = e taskhost; thmainpipe.name = dataflowname; mainpipe dataflowtask = thmainpipe.innerobject mainpipe; // create source component idtscomponentmetadata100 sourcecomponent = dataflowtask.componentmetadatacollection.new(); sourcecomponent.name = sourcename; sourcecomponent.componentclassid = ssiscomponenttype.scriptcomponent.getcomponentclassid(); // design time srcdesigntime of component cmanagedcomponentwrapper srcdesigntime = sourcecomponent.instantiate(); // initialize component srcdesigntime.providecomponentproperties(); int lastoutputid = 0; // add together metadata foreach (var outputdefinition in outputdefinitions) { var output = srcdesigntime.insertoutput(dtsinsertplacement.ip_after, lastoutputid); output.name = outputdefinition.outputname; lastoutputid = output.id; var outputcolumncollection = output.outputcolumncollection; foreach (var outputcolumndefinition in outputdefinition.outputcolumndefinitions) { var outputcolumn = outputcolumncollection.new(); outputcolumn.name = outputcolumndefinition.columnname; outputcolumn.setdatatypeproperties(dtscolumndatatype.dt_wstr, outputcolumndefinition.columnsize, 0, 0, 0); } } // reinitialise metadata srcdesigntime.reinitializemetadata(); // save bundle application app = new application(); app.savetoxml(filepath, pkg, null); } } }
the outputdefinition class custom class created holding definitions used when creating outputs.
so, solution issue remove inputs component. default component has "input 0" , "output 0" correlates beingness transform script component type. source type have no inputs, , destination have no outputs.
to remove inputs , outputs, add:
sourcecomponent.outputcollection.removeall(); sourcecomponent.inputcollection.removeall();
here:
// ... // initialize component srcdesigntime.providecomponentproperties(); // remove default inputs , outputs sourcecomponent.outputcollection.removeall(); sourcecomponent.inputcollection.removeall(); int lastoutputid = 0; // ...
c# ssis
Comments
Post a Comment