PrecedenceConstraints using Transformers
Introduction
I am currently working with one of our partners to convert their BimlExpress framework to BimlStudio and secure their IP using Transformers. I will post detailed instructions on that subject in the next week or two. One of the things that they do in the first task in every ControlFlow is to check a repository to determine whether the package should execute. I have seen similar approaches in various frameworks out there and provide the following code as a demonstration of how you can achieve this using a single transformer. The sample project is available as TransformerPrecedenceConstraint.zip. If you are new to Transformers please refer to the BimlScript Transformers Primer.
A Simple DataFlow
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Packages>
<Package Name="DummyPackage" ConstraintMode="Parallel">
<Tasks>
<Dataflow Name="DFT - Dummy">
<Annotations>
<Annotation AnnotationType="Tag" Tag="AddExecuteCheck">AddExecuteCheck</Annotation>
</Annotations>
</Dataflow>
</Tasks>
</Package>
</Packages>
</Biml>
Add Variables to Package
<#@ target type="Package" mergemode="LocalMerge" #>
<Package>
<Variables>
<Variable Name="IsExecutable" DataType="String" Namespace="User">"N"</Variable>
</Variables>
</Package>
Add Execute SQL Task to DataFlow
<#@ target type="DataflowTask" mergemode="LocalReplace" #>
<# if (TargetNode.Annotations["AddExecuteCheck"] != null) { #>
<Transformations>
<ExecuteSQL Name="SQL - Execute Check" ForcedExecutionValueDataType="Empty" ConnectionName="AW" ResultSet="SingleRow">
<Results>
<Result Name="0" VariableName="User.IsExecutable" />
</Results>
<DirectInput>SELECT 'Y'</DirectInput>
</ExecuteSQL>
<#=TargetNode.GetBiml()#>
</Transformations>
<# } #>
<#@ import namespace="System.Data"
Add PrecedenceConstraint to DataFlow
<#@ target type="DataflowTask" mergemode="LocalMerge" #>
<# if (TargetNode.Annotations["AddExecuteCheck"] != null) { #>
<DataFlow>
<PrecedenceConstraints LogicalType="And">
<Inputs>
<Input OutputPathName="SQL - Execute Check.Output" EvaluationOperation="ExpressionAndConstraint" Expression="@IsExecutable == "Y"" />
</Inputs>
</PrecedenceConstraints>
</DataFlow>
<# } #>
<#@ import namespace="System.Data" #>