Exemple #1
0
        private static Transformation CreateConditionalSplitFromXml(Vulcan.Packages.VulcanPackage vulcanPackage, IDTSComponentMetaData90 parentComponent, MainPipe dataFlowTask, XPathNavigator conditionalSplitNav)
        {
            if (conditionalSplitNav == null || conditionalSplitNav.Name.ToUpperInvariant() != "ConditionalSplit".ToUpperInvariant())
            {
                return null;
            }
            string conditionalSplitName = conditionalSplitNav.SelectSingleNode("@Name", vulcanPackage.VulcanConfig.NamespaceManager).Value;
            Message.Trace(Severity.Debug, "Begin: ConditionalSplit Transformation {0}", conditionalSplitName);
            ConditionalSplit cs = new ConditionalSplit(
                vulcanPackage,
                dataFlowTask,
                parentComponent,
                conditionalSplitName,
                conditionalSplitName
                );

            int intEvaluationOrder = 0;
            string expression = string.Empty;
            foreach (XPathNavigator nav in conditionalSplitNav.Select("//rc:Output|//rc:DefaultOutput", vulcanPackage.VulcanConfig.NamespaceManager))
            {
                if (nav.Name == "DefaultOutput")
                {
                    cs.Component.OutputCollection.SetIndex(cs.Component.OutputCollection.GetObjectIndexByID(cs.Component.OutputCollection["Conditional Split Default Output"].ID), 0);
                }
                else
                {
                    expression = nav.SelectSingleNode("rc:Expression", vulcanPackage.VulcanConfig.NamespaceManager).Value;
                    IDTSOutput90 newPath = cs.Component.OutputCollection.New();
                    newPath.Name = nav.SelectSingleNode("@Name", vulcanPackage.VulcanConfig.NamespaceManager).Value;
                    newPath.Description = nav.SelectSingleNode("@Name", vulcanPackage.VulcanConfig.NamespaceManager).Value;
                    newPath.ExclusionGroup = cs.Component.OutputCollection["Conditional Split Default Output"].ExclusionGroup;
                    newPath.SynchronousInputID = cs.Component.OutputCollection["Conditional Split Default Output"].SynchronousInputID;
                    newPath.ErrorOrTruncationOperation = "Computation";
                    newPath.ErrorRowDisposition = DTSRowDisposition.RD_IgnoreFailure;
                    newPath.TruncationRowDisposition = DTSRowDisposition.RD_FailComponent;

                    IDTSCustomProperty90 propEvaluationOrder = newPath.CustomPropertyCollection.New();
                    propEvaluationOrder.Name = "EvaluationOrder";
                    propEvaluationOrder.Value = intEvaluationOrder;

                    IDTSCustomProperty90 propFriendlyExpression = newPath.CustomPropertyCollection.New();
                    propFriendlyExpression.Name = "FriendlyExpression";
                    propFriendlyExpression.Value = expression;

                    IDTSCustomProperty90 propExpression = newPath.CustomPropertyCollection.New();
                    propExpression.Name = "Expression";
                    propExpression.Value = expression;

                    //A workaround to connect the path to Conditional Spit's output,
                    //because we always connect the current task to the previous task's first output
                    cs.Component.OutputCollection.SetIndex(cs.Component.OutputCollection.GetObjectIndexByID(newPath.ID), 0);
                    intEvaluationOrder++;
                }

                IDTSComponentMetaData90 startComponent = cs.Component;

                XPathNavigator transNav = nav.SelectSingleNode("rc:ConditionalSplitOutputPath/rc:Transformations", vulcanPackage.VulcanConfig.NamespaceManager);
                if (transNav != null)
                {
                    foreach (XPathNavigator etlNav in transNav.SelectChildren(XPathNodeType.Element))
                    {
                        // this is naughty but can be fixed later :)
                        Transformation t = TransformationFactory.ProcessTransformation(vulcanPackage, startComponent, dataFlowTask, etlNav);
                        if (t != null)
                        {
                            startComponent = t.Component;
                        }
                    }
                }

                XPathNavigator destNav = nav.SelectSingleNode("rc:ConditionalSplitOutputPath/rc:Destination", vulcanPackage.VulcanConfig.NamespaceManager);
                if (destNav != null)
                {
                    string name = destNav.SelectSingleNode("@Name").Value;
                    Connection destConnection = Connection.GetExistingConnection(vulcanPackage, destNav.SelectSingleNode("@ConnectionName").Value);
                    string tableName = String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", destNav.SelectSingleNode("@Table").Value.Trim());
                    OLEDBDestination oledbDestination = new OLEDBDestination(vulcanPackage, dataFlowTask, startComponent, name, name, destConnection, tableName);

                    string accessMode = destNav.SelectSingleNode("@AccessMode").Value;
                    bool tableLock = destNav.SelectSingleNode("@TableLock").ValueAsBoolean;
                    bool checkConstraints = destNav.SelectSingleNode("@CheckConstraints").ValueAsBoolean;
                    bool keepIdentity = destNav.SelectSingleNode("@KeepIdentity").ValueAsBoolean;
                    bool keepNulls = destNav.SelectSingleNode("@KeepNulls").ValueAsBoolean;

                    int rowsPerBatch = destNav.SelectSingleNode("@RowsPerBatch").ValueAsInt;
                    int maxInsertCommitSize = destNav.SelectSingleNode("@MaximumInsertCommitSize").ValueAsInt;

                    switch (accessMode.ToUpperInvariant())
                    {
                        case "TABLE":
                            oledbDestination.ComponentInstance.SetComponentProperty("AccessMode", 0);
                            oledbDestination.ComponentInstance.SetComponentProperty("OpenRowset", tableName);
                            break;
                        case "TABLEFASTLOAD":
                            oledbDestination.ComponentInstance.SetComponentProperty("AccessMode", 3);
                            oledbDestination.ComponentInstance.SetComponentProperty("OpenRowset", tableName);

                            oledbDestination.ComponentInstance.SetComponentProperty("FastLoadKeepIdentity", keepIdentity);
                            oledbDestination.ComponentInstance.SetComponentProperty("FastLoadKeepNulls", keepNulls);
                            oledbDestination.ComponentInstance.SetComponentProperty("FastLoadMaxInsertCommitSize", maxInsertCommitSize);

                            StringBuilder fastLoadOptions = new StringBuilder();
                            if (tableLock)
                            {
                                fastLoadOptions.AppendFormat("TABLOCK,");
                            }
                            if (checkConstraints)
                            {
                                fastLoadOptions.AppendFormat("CHECK_CONSTRAINTS,");
                            }
                            if (rowsPerBatch > 0)
                            {
                                fastLoadOptions.AppendFormat("ROWS_PER_BATCH = {0}", rowsPerBatch);
                            }
                            fastLoadOptions = fastLoadOptions.Replace(",", "", fastLoadOptions.Length - 5, 5);

                            oledbDestination.ComponentInstance.SetComponentProperty("FastLoadOptions", fastLoadOptions.ToString());
                            break;
                        default:
                            Message.Trace(Severity.Error, "Unknown Destination Load Type of {0}", accessMode);
                            break;
                    }

                    try
                    {
                        oledbDestination.InitializeAndMapDestination();
                    }
                    catch (Exception)
                    {
                    }

                    // Map any overrides
                    foreach (XPathNavigator navMap in destNav.Select("rc:Map", vulcanPackage.VulcanConfig.NamespaceManager))
                    {
                        string source = navMap.SelectSingleNode("@Source").Value;
                        string destination;
                        bool unMap = false;

                        if (navMap.SelectSingleNode("@Destination") == null)
                        {
                            unMap = true;
                            destination = source;
                        }
                        else
                        {
                            destination = nav.SelectSingleNode("@Destination").Value;
                        }

                        oledbDestination.Map(source, destination, unMap);
                    }
                } // end DestNav != null
                //this.FirstExecutableGeneratedByPattern = pipeHost;
                //this.LastExecutableGeneratedByPattern = pipeHost;

            }

            return cs;
        }
        private static Transformation CreateConditionalSplitFromXml(Vulcan.Packages.VulcanPackage vulcanPackage, IDTSComponentMetaData90 parentComponent, MainPipe dataFlowTask, XPathNavigator conditionalSplitNav)
        {
            if (conditionalSplitNav == null || conditionalSplitNav.Name.ToUpperInvariant() != "ConditionalSplit".ToUpperInvariant())
            {
                return(null);
            }
            string conditionalSplitName = conditionalSplitNav.SelectSingleNode("@Name", vulcanPackage.VulcanConfig.NamespaceManager).Value;

            Message.Trace(Severity.Debug, "Begin: ConditionalSplit Transformation {0}", conditionalSplitName);
            ConditionalSplit cs = new ConditionalSplit(
                vulcanPackage,
                dataFlowTask,
                parentComponent,
                conditionalSplitName,
                conditionalSplitName
                );

            int    intEvaluationOrder = 0;
            string expression         = string.Empty;

            foreach (XPathNavigator nav in conditionalSplitNav.Select("//rc:Output|//rc:DefaultOutput", vulcanPackage.VulcanConfig.NamespaceManager))
            {
                if (nav.Name == "DefaultOutput")
                {
                    cs.Component.OutputCollection.SetIndex(cs.Component.OutputCollection.GetObjectIndexByID(cs.Component.OutputCollection["Conditional Split Default Output"].ID), 0);
                }
                else
                {
                    expression = nav.SelectSingleNode("rc:Expression", vulcanPackage.VulcanConfig.NamespaceManager).Value;
                    IDTSOutput90 newPath = cs.Component.OutputCollection.New();
                    newPath.Name                       = nav.SelectSingleNode("@Name", vulcanPackage.VulcanConfig.NamespaceManager).Value;
                    newPath.Description                = nav.SelectSingleNode("@Name", vulcanPackage.VulcanConfig.NamespaceManager).Value;
                    newPath.ExclusionGroup             = cs.Component.OutputCollection["Conditional Split Default Output"].ExclusionGroup;
                    newPath.SynchronousInputID         = cs.Component.OutputCollection["Conditional Split Default Output"].SynchronousInputID;
                    newPath.ErrorOrTruncationOperation = "Computation";
                    newPath.ErrorRowDisposition        = DTSRowDisposition.RD_IgnoreFailure;
                    newPath.TruncationRowDisposition   = DTSRowDisposition.RD_FailComponent;

                    IDTSCustomProperty90 propEvaluationOrder = newPath.CustomPropertyCollection.New();
                    propEvaluationOrder.Name  = "EvaluationOrder";
                    propEvaluationOrder.Value = intEvaluationOrder;

                    IDTSCustomProperty90 propFriendlyExpression = newPath.CustomPropertyCollection.New();
                    propFriendlyExpression.Name  = "FriendlyExpression";
                    propFriendlyExpression.Value = expression;

                    IDTSCustomProperty90 propExpression = newPath.CustomPropertyCollection.New();
                    propExpression.Name  = "Expression";
                    propExpression.Value = expression;

                    //A workaround to connect the path to Conditional Spit's output,
                    //because we always connect the current task to the previous task's first output
                    cs.Component.OutputCollection.SetIndex(cs.Component.OutputCollection.GetObjectIndexByID(newPath.ID), 0);
                    intEvaluationOrder++;
                }

                IDTSComponentMetaData90 startComponent = cs.Component;

                XPathNavigator transNav = nav.SelectSingleNode("rc:ConditionalSplitOutputPath/rc:Transformations", vulcanPackage.VulcanConfig.NamespaceManager);
                if (transNav != null)
                {
                    foreach (XPathNavigator etlNav in transNav.SelectChildren(XPathNodeType.Element))
                    {
                        // this is naughty but can be fixed later :)
                        Transformation t = TransformationFactory.ProcessTransformation(vulcanPackage, startComponent, dataFlowTask, etlNav);
                        if (t != null)
                        {
                            startComponent = t.Component;
                        }
                    }
                }

                XPathNavigator destNav = nav.SelectSingleNode("rc:ConditionalSplitOutputPath/rc:Destination", vulcanPackage.VulcanConfig.NamespaceManager);
                if (destNav != null)
                {
                    string           name             = destNav.SelectSingleNode("@Name").Value;
                    Connection       destConnection   = Connection.GetExistingConnection(vulcanPackage, destNav.SelectSingleNode("@ConnectionName").Value);
                    string           tableName        = String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", destNav.SelectSingleNode("@Table").Value.Trim());
                    OLEDBDestination oledbDestination = new OLEDBDestination(vulcanPackage, dataFlowTask, startComponent, name, name, destConnection, tableName);

                    string accessMode       = destNav.SelectSingleNode("@AccessMode").Value;
                    bool   tableLock        = destNav.SelectSingleNode("@TableLock").ValueAsBoolean;
                    bool   checkConstraints = destNav.SelectSingleNode("@CheckConstraints").ValueAsBoolean;
                    bool   keepIdentity     = destNav.SelectSingleNode("@KeepIdentity").ValueAsBoolean;
                    bool   keepNulls        = destNav.SelectSingleNode("@KeepNulls").ValueAsBoolean;

                    int rowsPerBatch        = destNav.SelectSingleNode("@RowsPerBatch").ValueAsInt;
                    int maxInsertCommitSize = destNav.SelectSingleNode("@MaximumInsertCommitSize").ValueAsInt;

                    switch (accessMode.ToUpperInvariant())
                    {
                    case "TABLE":
                        oledbDestination.ComponentInstance.SetComponentProperty("AccessMode", 0);
                        oledbDestination.ComponentInstance.SetComponentProperty("OpenRowset", tableName);
                        break;

                    case "TABLEFASTLOAD":
                        oledbDestination.ComponentInstance.SetComponentProperty("AccessMode", 3);
                        oledbDestination.ComponentInstance.SetComponentProperty("OpenRowset", tableName);

                        oledbDestination.ComponentInstance.SetComponentProperty("FastLoadKeepIdentity", keepIdentity);
                        oledbDestination.ComponentInstance.SetComponentProperty("FastLoadKeepNulls", keepNulls);
                        oledbDestination.ComponentInstance.SetComponentProperty("FastLoadMaxInsertCommitSize", maxInsertCommitSize);

                        StringBuilder fastLoadOptions = new StringBuilder();
                        if (tableLock)
                        {
                            fastLoadOptions.AppendFormat("TABLOCK,");
                        }
                        if (checkConstraints)
                        {
                            fastLoadOptions.AppendFormat("CHECK_CONSTRAINTS,");
                        }
                        if (rowsPerBatch > 0)
                        {
                            fastLoadOptions.AppendFormat("ROWS_PER_BATCH = {0}", rowsPerBatch);
                        }
                        fastLoadOptions = fastLoadOptions.Replace(",", "", fastLoadOptions.Length - 5, 5);

                        oledbDestination.ComponentInstance.SetComponentProperty("FastLoadOptions", fastLoadOptions.ToString());
                        break;

                    default:
                        Message.Trace(Severity.Error, "Unknown Destination Load Type of {0}", accessMode);
                        break;
                    }

                    try
                    {
                        oledbDestination.InitializeAndMapDestination();
                    }
                    catch (Exception)
                    {
                    }

                    // Map any overrides
                    foreach (XPathNavigator navMap in destNav.Select("rc:Map", vulcanPackage.VulcanConfig.NamespaceManager))
                    {
                        string source = navMap.SelectSingleNode("@Source").Value;
                        string destination;
                        bool   unMap = false;

                        if (navMap.SelectSingleNode("@Destination") == null)
                        {
                            unMap       = true;
                            destination = source;
                        }
                        else
                        {
                            destination = nav.SelectSingleNode("@Destination").Value;
                        }

                        oledbDestination.Map(source, destination, unMap);
                    }
                } // end DestNav != null
                  //this.FirstExecutableGeneratedByPattern = pipeHost;
                  //this.LastExecutableGeneratedByPattern = pipeHost;
            }

            return(cs);
        }