private void EmitPipelineUnion(SsisObject pipeline, string indent) { SourceWriter.WriteLine(); SourceWriter.WriteLine(@"{0}// {1}", indent, Attributes["name"]); // Create a new datatable SourceWriter.WriteLine(@"{0}DataTable component{1} = new DataTable();", indent, this.Attributes["id"]); // Add the columns we're generating int i = 0; List<SsisObject> transforms = this.GetChildByType("outputs").GetChildByTypeAndAttr("output", "isErrorOut", "false").GetChildByType("outputColumns").Children; List<string> colnames = new List<string>(); foreach (SsisObject outcol in transforms) { ColumnVariable cv = new ColumnVariable(outcol); LineageObject lo = new LineageObject(cv.LineageID, "component" + this.Attributes["id"], cv.Name); i++; pipeline._lineage_columns.Add(lo); // Print out this column SourceWriter.WriteLine(@"{0}component{1}.Columns.Add(new DataColumn(""{2}"", typeof({3})));", indent, this.Attributes["id"], cv.Name, cv.CsharpType()); DataTable dt = new DataTable(); colnames.Add(cv.Name); } // Loop through all the inputs and process them! SsisObject outputcolumns = this.GetChildByType("outputs").GetChildByType("output").GetChildByType("outputColumns"); foreach (SsisObject inputtable in this.GetChildByType("inputs").Children) { // Find the name of the table by looking at the first column SsisObject input_columns = inputtable.GetChildByType("inputColumns"); SsisObject metadata = inputtable.GetChildByType("externalMetadataColumns"); if (input_columns != null) { SsisObject first_col = input_columns.Children[0]; LineageObject first_input = pipeline.GetLineageObjectById(first_col.Attributes["lineageId"]); string component = first_input.DataTableName; // Read through all rows in the table SourceWriter.WriteLine(@"{0}for (int row = 0; row < {1}.Rows.Count; row++) {{", indent, component); SourceWriter.WriteLine(@"{0} DataRow dr = component{1}.NewRow();", indent, this.Attributes["id"]); // Loop through all the columns and insert them foreach (SsisObject col in inputtable.GetChildByType("inputColumns").Children) { LineageObject l = pipeline.GetLineageObjectById(col.Attributes["lineageId"]); // find the matching external metadata column string outcolname = ""; SsisObject mdcol = metadata.GetChildByTypeAndAttr("externalMetadataColumn", "id", col.Attributes["externalMetadataColumnId"]); if (mdcol == null) { SsisObject prop = col.GetChildByType("properties").GetChildByType("property"); SsisObject outcol = outputcolumns.GetChildByTypeAndAttr("outputColumn", "id", prop.ContentValue); outcolname = outcol.Attributes["name"]; } else { outcolname = mdcol.Attributes["name"]; } // Write out the expression SourceWriter.WriteLine(@"{0} dr[""{1}""] = {2};", indent, outcolname, l.ToString()); } // Write the end of this code block SourceWriter.WriteLine(@"{0} component{1}.Rows.Add(dr);", indent, this.Attributes["id"]); SourceWriter.WriteLine(@"{0}}}", indent); } } }
private void EmitPipelineTransform(SsisObject pipeline, string indent) { // Add the columns we're generating List<SsisObject> transforms = this.GetChildByType("outputs").GetChildByTypeAndAttr("output", "isErrorOut", "false").GetChildByType("outputColumns").Children; // Check the inputs to see what component we're using as the source string component = "component1"; SsisObject inputcolumns = this.GetChildByType("inputs").GetChildByType("input").GetChildByType("inputColumns"); if (inputcolumns != null) { foreach (SsisObject incol in inputcolumns.Children) { LineageObject input = pipeline.GetLineageObjectById(incol.Attributes["lineageId"]); if (component == null) { component = input.DataTableName; } else { if (component != input.DataTableName) { SourceWriter.Help(this, "This SSIS pipeline is merging different component tables!"); } } } } // Let's see if we can generate some code to do these conversions! foreach (SsisObject outcol in transforms) { ColumnVariable cv = new ColumnVariable(outcol); LineageObject source_lineage = null; string expression = null; // Find property "expression" if (outcol.Children.Count > 0) { foreach (SsisObject property in outcol.GetChildByType("properties").Children) { if (property.Attributes["name"] == "SourceInputColumnLineageID") { source_lineage = pipeline.GetLineageObjectById(property.ContentValue); expression = String.Format(@"Convert.ChangeType({1}.Rows[row][""{2}""], typeof({0}));", cv.CsharpType(), source_lineage.DataTableName, source_lineage.FieldName); } else if (property.Attributes["name"] == "FastParse") { // Don't need to do anything here } else if (property.Attributes["name"] == "Expression") { // Is this a lineage column? expression = FixExpression(cv.CsharpType(), pipeline._lineage_columns, property.ContentValue, true); } else if (property.Attributes["name"] == "FriendlyExpression") { // This comment is useless - SourceWriter.WriteLine(@"{0} // {1}", indent, property.ContentValue); } else { SourceWriter.Help(this, "I don't understand the output column property '" + property.Attributes["name"] + "'"); } } // If we haven't been given an explicit expression, just use this if (String.IsNullOrEmpty(expression)) { SourceWriter.Help(this, "I'm trying to do a transform, but I haven't found an expression to use."); } else { // Put this transformation back into the lineage table for later use! LineageObject lo = new LineageObject(outcol.Attributes["lineageId"], expression); pipeline._lineage_columns.Add(lo); } } else { SourceWriter.Help(this, "I'm trying to do a transform, but I don't have any properties to use."); } } }