public override void Emit(XPathNavigator patternNavigator) { if (patternNavigator != null) { string taskName = patternNavigator.SelectSingleNode("@Name").Value; string connectionName = patternNavigator.SelectSingleNode("@Connection").Value; string varPrefix = patternNavigator.SelectSingleNode("@PreviousLogEntryVariablePrefix").Value; string sourceColumn = patternNavigator.SelectSingleNode("@SourceColumn") == null ? null : patternNavigator.SelectSingleNode("@SourceColumn").Value; string destinationColumn = patternNavigator.SelectSingleNode("@DestinationColumn") == null ? null : patternNavigator.SelectSingleNode("@DestinationColumn").Value; string table = patternNavigator.SelectSingleNode("@Table") == null ? null : patternNavigator.SelectSingleNode("@Table").Value; string tableConnectionName = patternNavigator.SelectSingleNode("@TableConnection") == null ? null : patternNavigator.SelectSingleNode("@TableConnection").Value; if (varPrefix.ToUpperInvariant() == "varLog") { Message.Trace(Severity.Error, "Name: {0}: Error in PreviousLogEntryVariablePrefix: varLog is a reserved variable name.", taskName); return; } Connection connection = Connection.GetExistingConnection(VulcanPackage, connectionName); LogtainerLog ll = new LogtainerLog( VulcanPackage, Resources.LogVariablePrefix + VulcanPackage.Name + taskName, sourceColumn, destinationColumn, table, tableConnectionName ); string execSqlTaskName = Resources.Log + Resources.Seperator + VulcanPackage.Name + Resources.Seperator + taskName + Resources.Seperator; SQLTask logStartTask = new SQLTask(VulcanPackage, execSqlTaskName + Resources.Start, execSqlTaskName + Resources.Start, ParentContainer, connection); TemplateEmitter te = new TemplateEmitter(VulcanPackage.TemplateManager["LogStart"]); te.SetNamedParameter("ETLName", VulcanPackage.Name); te.SetNamedParameter("TaskName", taskName); if (_logStack.Count > 0) { te.SetNamedParameter("ParentLogID", "?"); // Yes you have to hard code the data type as there is no lookup or cross-reference source, and the intger is dependent on the connection you create... bugbug! logStartTask.BindParameter(CurrentLog.LogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Input, 3); } else { te.SetNamedParameter("ParentLogID", "NULL"); } logStartTask.BindParameter(ll.LogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, 3); logStartTask.BindParameter(ll.LastRecordLogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, 3); logStartTask.BindParameter(ll.IsAnotherInstanceCurrentlyRunningLogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, 3); string sqlExpression; te.Emit(out sqlExpression); logStartTask.TransmuteToExpressionTask(sqlExpression); te = new TemplateEmitter(VulcanPackage.TemplateManager["LogGetValue"]); te.SetNamedParameter("LogID", ll.LastRecordLogVariable.QualifiedName); this.FirstExecutableGeneratedByPattern = logStartTask.SQLTaskHost; // Push the current log variable onto the stack! _logStack.Push(ll); //Add a new SQL Task to read the previous log te = new TemplateEmitter("LogGetValue", VulcanPackage, ll.LastRecordLogVariable.QualifiedName); string readPreviousLogValuesQuery; te.Emit(out readPreviousLogValuesQuery); SQLTask readPreviousLogValues = new SQLTask(VulcanPackage, Resources.Log + Resources.LoadInto + varPrefix, Resources.Log + Resources.LoadInto + varPrefix, ParentContainer, connection); readPreviousLogValues.TransmuteToExpressionTask(readPreviousLogValuesQuery); VulcanPackage.AddPrecedenceConstraint(this.FirstExecutableGeneratedByPattern, readPreviousLogValues.SQLTaskHost, ParentContainer); //Bind and create variables for the SQL Task that reads the previous log. This is kinda hacky readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "StartTime", new DateTime(1980, 1, 1)), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.DBTimeStamp, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "EndTime", new DateTime(1980, 1, 1)), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.DBTimeStamp, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "FirstSourceRecord", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "FirstDestinationRecord", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "LastSourceRecord", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "LastDestinationRecord", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "Status", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "Notes", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); // Handle the sub-tasks just like the Container pattern DTS.Executable previousExec = readPreviousLogValues.SQLTaskHost; Pattern p = null; foreach (XPathNavigator nav in patternNavigator.SelectChildren(XPathNodeType.Element)) { p = PatternFactory.ProcessPattern(VulcanPackage, ParentContainer, nav, p); VulcanPackage.AddPrecedenceConstraint(previousExec, p.FirstExecutableGeneratedByPattern, ParentContainer); previousExec = p.LastExecutableGeneratedByPattern; } this.LastExecutableGeneratedByPattern = previousExec; // Pop the current log variable off of the stack and end the log. ll = _logStack.Pop(); te = new TemplateEmitter(VulcanPackage.TemplateManager["LogSetValue"]); te.SetNamedParameter("LogID", ll.LogVariable.QualifiedName); StringBuilder writeValuesToLogQuery = new StringBuilder(); foreach (string column in ll.LogColumnDictionary.Keys) { string temp; te.SetNamedParameter("Column", column); te.SetNamedParameter("Value", ll.LogColumnDictionary[column].QualifiedName); te.Emit(out temp); writeValuesToLogQuery.Append(temp); writeValuesToLogQuery.AppendFormat(" + \n"); } te = new TemplateEmitter(VulcanPackage.TemplateManager["LogEnd"]); te.Emit(out sqlExpression); writeValuesToLogQuery.Append(sqlExpression); SQLTask logEndTask = new SQLTask(VulcanPackage, execSqlTaskName + Resources.Stop, execSqlTaskName + Resources.Stop, ParentContainer, connection); logEndTask.TransmuteToExpressionTask(writeValuesToLogQuery.ToString()); logEndTask.BindParameter(ll.LogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Input, 3); if (previousExec != null) { VulcanPackage.AddPrecedenceConstraint(previousExec, logEndTask.SQLTaskHost, ParentContainer); } this.LastExecutableGeneratedByPattern = logEndTask.SQLTaskHost; } }
public override void Emit(XPathNavigator patternNavigator) { if (patternNavigator != null) { string taskName = patternNavigator.SelectSingleNode("@Name").Value; string connectionName = patternNavigator.SelectSingleNode("@Connection").Value; string varPrefix = patternNavigator.SelectSingleNode("@PreviousLogEntryVariablePrefix").Value; string sourceColumn = patternNavigator.SelectSingleNode("@SourceColumn") == null ? null : patternNavigator.SelectSingleNode("@SourceColumn").Value; string destinationColumn = patternNavigator.SelectSingleNode("@DestinationColumn") == null ? null : patternNavigator.SelectSingleNode("@DestinationColumn").Value; string table = patternNavigator.SelectSingleNode("@Table")== null ? null : patternNavigator.SelectSingleNode("@Table").Value; string tableConnectionName = patternNavigator.SelectSingleNode("@TableConnection") == null ? null : patternNavigator.SelectSingleNode("@TableConnection").Value; if (varPrefix.ToUpperInvariant() == "varLog") { Message.Trace(Severity.Error, "Name: {0}: Error in PreviousLogEntryVariablePrefix: varLog is a reserved variable name.", taskName); return; } Connection connection = Connection.GetExistingConnection(VulcanPackage, connectionName); LogtainerLog ll = new LogtainerLog( VulcanPackage, Resources.LogVariablePrefix + VulcanPackage.Name + taskName, sourceColumn, destinationColumn, table, tableConnectionName ); string execSqlTaskName = Resources.Log + Resources.Seperator + VulcanPackage.Name + Resources.Seperator + taskName + Resources.Seperator; SQLTask logStartTask = new SQLTask(VulcanPackage, execSqlTaskName + Resources.Start, execSqlTaskName + Resources.Start, ParentContainer, connection); TemplateEmitter te = new TemplateEmitter(VulcanPackage.TemplateManager["LogStart"]); te.SetNamedParameter("ETLName", VulcanPackage.Name); te.SetNamedParameter("TaskName", taskName); if (_logStack.Count > 0) { te.SetNamedParameter("ParentLogID", "?"); // Yes you have to hard code the data type as there is no lookup or cross-reference source, and the intger is dependent on the connection you create... bugbug! logStartTask.BindParameter(CurrentLog.LogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Input, 3); } else { te.SetNamedParameter("ParentLogID", "NULL"); } logStartTask.BindParameter(ll.LogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, 3); logStartTask.BindParameter(ll.LastRecordLogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, 3); logStartTask.BindParameter(ll.IsAnotherInstanceCurrentlyRunningLogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, 3); string sqlExpression; te.Emit(out sqlExpression); logStartTask.TransmuteToExpressionTask(sqlExpression); te = new TemplateEmitter(VulcanPackage.TemplateManager["LogGetValue"]); te.SetNamedParameter("LogID", ll.LastRecordLogVariable.QualifiedName); this.FirstExecutableGeneratedByPattern = logStartTask.SQLTaskHost; // Push the current log variable onto the stack! _logStack.Push(ll); //Add a new SQL Task to read the previous log te = new TemplateEmitter("LogGetValue", VulcanPackage, ll.LastRecordLogVariable.QualifiedName); string readPreviousLogValuesQuery; te.Emit(out readPreviousLogValuesQuery); SQLTask readPreviousLogValues = new SQLTask(VulcanPackage, Resources.Log + Resources.LoadInto + varPrefix, Resources.Log + Resources.LoadInto + varPrefix, ParentContainer,connection); readPreviousLogValues.TransmuteToExpressionTask(readPreviousLogValuesQuery); VulcanPackage.AddPrecedenceConstraint(this.FirstExecutableGeneratedByPattern, readPreviousLogValues.SQLTaskHost, ParentContainer); //Bind and create variables for the SQL Task that reads the previous log. This is kinda hacky readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "StartTime", new DateTime(1980,1,1)), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.DBTimeStamp, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "EndTime", new DateTime(1980,1,1)), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.DBTimeStamp, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "FirstSourceRecord", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "FirstDestinationRecord", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "LastSourceRecord", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "LastDestinationRecord", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "Status", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); readPreviousLogValues.BindParameter( VulcanPackage.AddVariable(varPrefix + "Notes", String.Empty), Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Output, (int)System.Data.OleDb.OleDbType.WChar, 255); // Handle the sub-tasks just like the Container pattern DTS.Executable previousExec = readPreviousLogValues.SQLTaskHost; Pattern p = null; foreach (XPathNavigator nav in patternNavigator.SelectChildren(XPathNodeType.Element)) { p = PatternFactory.ProcessPattern(VulcanPackage, ParentContainer, nav, p); VulcanPackage.AddPrecedenceConstraint(previousExec, p.FirstExecutableGeneratedByPattern, ParentContainer); previousExec = p.LastExecutableGeneratedByPattern; } this.LastExecutableGeneratedByPattern = previousExec; // Pop the current log variable off of the stack and end the log. ll = _logStack.Pop(); te = new TemplateEmitter(VulcanPackage.TemplateManager["LogSetValue"]); te.SetNamedParameter("LogID", ll.LogVariable.QualifiedName); StringBuilder writeValuesToLogQuery = new StringBuilder(); foreach (string column in ll.LogColumnDictionary.Keys) { string temp; te.SetNamedParameter("Column", column); te.SetNamedParameter("Value", ll.LogColumnDictionary[column].QualifiedName); te.Emit(out temp); writeValuesToLogQuery.Append(temp); writeValuesToLogQuery.AppendFormat(" + \n"); } te = new TemplateEmitter(VulcanPackage.TemplateManager["LogEnd"]); te.Emit(out sqlExpression); writeValuesToLogQuery.Append(sqlExpression); SQLTask logEndTask = new SQLTask(VulcanPackage, execSqlTaskName + Resources.Stop, execSqlTaskName + Resources.Stop, ParentContainer, connection); logEndTask.TransmuteToExpressionTask(writeValuesToLogQuery.ToString()); logEndTask.BindParameter(ll.LogVariable, Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ParameterDirections.Input, 3); if (previousExec != null) { VulcanPackage.AddPrecedenceConstraint(previousExec, logEndTask.SQLTaskHost, ParentContainer); } this.LastExecutableGeneratedByPattern = logEndTask.SQLTaskHost; } }