/// <summary>
        /// React on input path attached
        /// </summary>
        /// <param name="inputID">ID of the SSIS input</param>
        public override void OnInputPathAttached(int inputID)
        {
            base.OnInputPathAttached(inputID);

            IDTSVirtualInput100 virtualInput = ComponentMetaData.InputCollection[Constants.INPUT_NAME].GetVirtualInput();

            //set all input column to readwrite
            for (int i = 0; i < virtualInput.VirtualInputColumnCollection.Count; i++)
            {
                virtualInput.SetUsageType(virtualInput.VirtualInputColumnCollection[i].LineageID, DTSUsageType.UT_READWRITE);
            }

            // load (will update custom input column properties) & save custom properties
            InitializeProperties();

            _isagCustomProperties.Save(ComponentMetaData);
        }
        public static void FixInvalidInputColumnMetaData(IDTSInput100 input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            IDTSVirtualInput100 vInput = input.GetVirtualInput();

            foreach (IDTSInputColumn100 inputColumn in input.InputColumnCollection)
            {
                IDTSVirtualInputColumn100 vColumn
                    = vInput.VirtualInputColumnCollection.GetVirtualInputColumnByLineageID(inputColumn.LineageID);

                if (!DoesColumnMetaDataMatch(inputColumn, vColumn))
                {
                    vInput.SetUsageType(vColumn.LineageID, inputColumn.UsageType);
                }
            }
        }
        /// <summary>
        /// Responds to the input path being attached; automatically selects all input columns by default.
        /// Version 2: Creates missing input column custom properties.
        /// </summary>
        /// <param name="inputID"></param>
        public override void OnInputPathAttached(int inputID)
        {
            base.OnInputPathAttached(inputID);

            for (Int32 n = 0; n < ComponentMetaData.InputCollection.Count; n++)
            {
                ComponentMetaData.InputCollection[n].InputColumnCollection.RemoveAll();

                IDTSVirtualInput100 input = ComponentMetaData.InputCollection[n].GetVirtualInput();

                foreach (IDTSVirtualInputColumn100 inputColumn in input.VirtualInputColumnCollection)
                {
                    Int32 inputColumnLineageID = inputColumn.LineageID;
                    input.SetUsageType(inputColumnLineageID, DTSUsageType.UT_READONLY);

                    this.CreateInputColumnCustomProperties(n, inputColumnLineageID);
                }
            }

            this.Validate();
        }
        private void AddConvertComponent(Hashtable colConvertTable, Hashtable colConnectTable)
        {
            convertComp = pipeline.ComponentMetaDataCollection.New();
            convertComp.ComponentClassID         = DATACONVERT_GUID;
            convertComp.Name                     = "Data Conversion";
            convertComp.ValidateExternalMetadata = true;
            convertDesignTimeComp                = convertComp.Instantiate();
            convertDesignTimeComp.ProvideComponentProperties();
            IDTSInput100  cvtInput  = convertComp.InputCollection[0];
            IDTSOutput100 cvtOutput = convertComp.OutputCollection[0];
            IDTSInputColumnCollection100 cvtInputCols = cvtInput.InputColumnCollection;
            IDTSOutput100 srcOutput = srcComp.OutputCollection[0];

            pipeline.PathCollection.New().AttachPathAndPropagateNotifications(srcOutput, cvtInput);
            IDTSVirtualInput100 cvtVirInput = cvtInput.GetVirtualInput();

            int i = 0;

            foreach (object key in colConvertTable.Keys)
            {
                int srcColID = (int)key;
                cvtVirInput.SetUsageType(srcColID, DTSUsageType.UT_READONLY);
                IDTSInputColumn100 cvtInputCol = cvtInputCols.GetInputColumnByLineageID(srcColID);
                if (cvtInputCol != null)
                {
                    IDTSOutputColumn100           cvtOutputCol = convertDesignTimeComp.InsertOutputColumnAt(cvtOutput.ID, i++, "Convert_" + cvtInputCol.Name, "");
                    IDTSExternalMetadataColumn100 destCol      = (IDTSExternalMetadataColumn100)colConvertTable[key];
                    convertDesignTimeComp.SetOutputColumnDataTypeProperties(cvtOutput.ID,
                                                                            cvtOutputCol.ID, destCol.DataType, destCol.Length, destCol.Precision, destCol.Scale, destCol.CodePage);
                    // map output column and input column
                    convertDesignTimeComp.SetOutputColumnProperty(cvtOutput.ID,
                                                                  cvtOutputCol.ID, "SourceInputColumnLineageID", srcColID);
                    // add match table entry.
                    colConnectTable.Add(cvtOutputCol.ID, destCol);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Called when the user finishes editing a cell.  We apply changes
        /// directly to the component input column here.
        /// </summary>
        private void mappingGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            // Ignore cell header changes!
            if (e.RowIndex < 0)
            {
                return;
            }

            // Get the currently selected input/virtual input, and virtual input column from
            // the changed row.
            IDTSInput100        input  = component_.InputCollection[inputComboBox.SelectedItem];
            IDTSVirtualInput100 vInput = input.GetVirtualInput();

            // Use the column name in column 1 of the grid to find the lineage id
            // of the column we're editing.
            IDTSVirtualInputColumn100 vColumn =
                vInput.VirtualInputColumnCollection.GetVirtualInputColumnByLineageID(mapColumnNameToLineageID_[(string)mappingGridView.Rows[e.RowIndex].Cells[1].Value]);

            // pull out the first column value to determine if the cell is mapped.
            bool mapped = (bool)mappingGridView.Rows[e.RowIndex].Cells[0].Value;

            // If the checkbox cell is the one that changed, we need to either set or clear the properties.
            if (e.ColumnIndex == 0)
            {
                if (mapped)
                {
                    // The checkbox was just set -- we need to map this column and set default values
                    // for the XML mapping properties.

                    // Map the column
                    vInput.SetUsageType(vColumn.LineageID, DTSUsageType.UT_READONLY);

                    // Fetch the IDTSInputColumn100 now that it is mapped.
                    IDTSInputColumn100 inputColumn = input.InputColumnCollection.GetInputColumnByLineageID(vColumn.LineageID);

                    // Create the custom mapping properties on this input column.
                    AddCustomInputColumnProps(inputColumn);

                    // Set default values for the new properties.
                    // Use XmlConvert.EncodeLocalName to create a default tag name from the column name.
                    mappingGridView.Rows[e.RowIndex].Cells[2].Value    = System.Xml.XmlConvert.EncodeLocalName((string)mappingGridView.Rows[e.RowIndex].Cells[1].Value);
                    mappingGridView.Rows[e.RowIndex].Cells[2].ReadOnly = false;
                    inputColumn.CustomPropertyCollection[Constants.AttributeOrElementNameProperty].Value =
                        mappingGridView.Rows[e.RowIndex].Cells[2].Value;

                    // Set the item to an element style.
                    mappingGridView.Rows[e.RowIndex].Cells[3].ReadOnly = false;
                    mappingGridView.Rows[e.RowIndex].Cells[3].Value    = Constants.ElementStyle;
                    inputColumn.CustomPropertyCollection[Constants.StyleProperty].Value =
                        mappingGridView.Rows[e.RowIndex].Cells[3].Value;
                }
                else
                {
                    // The mapping for this olumn is unchecked.
                    // Clear it all out.  Don't sweat clearing the custom properties.
                    mappingGridView.Rows[e.RowIndex].Cells[2].ReadOnly = true;
                    mappingGridView.Rows[e.RowIndex].Cells[3].ReadOnly = true;
                    mappingGridView.Rows[e.RowIndex].Cells[3].Value    = Constants.ElementStyle;
                    mappingGridView.Rows[e.RowIndex].Cells[2].Value    = "";
                    vInput.SetUsageType(vColumn.LineageID, DTSUsageType.UT_IGNORED);
                }
            }
            if (e.ColumnIndex == 2 && mapped)
            {
                // The tag/attribute name has changed and the column is mapped --
                // change the value of the property appropriately.
                input.InputColumnCollection.GetInputColumnByLineageID(vColumn.LineageID).CustomPropertyCollection[Constants.AttributeOrElementNameProperty].Value =
                    (string)mappingGridView.Rows[e.RowIndex].Cells[2].Value;
            }
            if (e.ColumnIndex == 3 && mapped)
            {
                // The style of this column has changed, update the property appropriately.
                input.InputColumnCollection.GetInputColumnByLineageID(vColumn.LineageID).CustomPropertyCollection[Constants.StyleProperty].Value =
                    (string)mappingGridView.Rows[e.RowIndex].Cells[3].Value;
            }
        }
        public void AddPathsAndConnectColumns(Hashtable colPairs)
        {
            IDTSOutput100 srcOutput = srcComp.OutputCollection[0];
            IDTSOutputColumnCollection100 srcOutputCols = srcOutput.OutputColumnCollection;
            IDTSInput100 destInput = destComp.InputCollection[0];
            IDTSInputColumnCollection100            destInputCols = destInput.InputColumnCollection;
            IDTSExternalMetadataColumnCollection100 destExtCols   = destInput.ExternalMetadataColumnCollection;

            Hashtable destColtable = new Hashtable(destExtCols.Count);

            foreach (IDTSExternalMetadataColumn100 extCol in destExtCols)
            {
                destColtable.Add(extCol.Name, extCol);
            }

            bool useMatch = (colPairs != null && colPairs.Count > 0);
            // colConvertTable stores a pair of columns which need a type conversion
            // colConnectTable stores a pair of columns which dont need a type conversion and can be connected directly.
            Hashtable colConvertTable = new Hashtable(srcOutputCols.Count);
            Hashtable colConnectTable = new Hashtable(srcOutputCols.Count);

            foreach (IDTSOutputColumn100 outputCol in srcOutputCols)
            {
                // Get the column name to look for in the destination.
                // Match column by name if match table is not used.
                String colNameToLookfor = String.Empty;
                if (useMatch)
                {
                    colNameToLookfor = (String)colPairs[outputCol.Name];
                }
                else
                {
                    colNameToLookfor = outputCol.Name;
                }

                IDTSExternalMetadataColumn100 extCol = (String.IsNullOrEmpty(colNameToLookfor)) ? null : (IDTSExternalMetadataColumn100)destColtable[colNameToLookfor];
                // Does the destination column exist?
                if (extCol != null)
                {
                    // Found destination column, but is data type conversion needed?
                    if (NeedConvert(outputCol.DataType, extCol.DataType))
                    {
                        colConvertTable.Add(outputCol.ID, extCol);
                    }
                    else
                    {
                        colConnectTable.Add(outputCol.ID, extCol);
                    }
                }
            }
            if (colConvertTable.Count > 0)
            {
                // add convert component
                AddConvertComponent(colConvertTable, colConnectTable);
                pipeline.PathCollection.New().AttachPathAndPropagateNotifications(convertComp.OutputCollection[0], destInput);
            }
            else
            {
                // Convert transform not needed. Connect src and destination directly.
                pipeline.PathCollection.New().AttachPathAndPropagateNotifications(srcOutput, destInput);
            }

            IDTSVirtualInput100 destVirInput = destInput.GetVirtualInput();

            foreach (object key in colConnectTable.Keys)
            {
                int colID = (int)key;
                IDTSExternalMetadataColumn100 extCol = (IDTSExternalMetadataColumn100)colConnectTable[key];
                // Create an input column from an output col of previous component.
                destVirInput.SetUsageType(colID, DTSUsageType.UT_READONLY);
                IDTSInputColumn100 inputCol = destInputCols.GetInputColumnByLineageID(colID);
                if (inputCol != null)
                {
                    // map the input column with an external metadata column
                    destDesignTimeComp.MapInputColumn(destInput.ID, inputCol.ID, extCol.ID);
                }
            }
        }
        private void mappingGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            // Ignore cell header changes!
            if (e.RowIndex < 0)
            {
                return;
            }

            // Ignore any clicks on the source column name
            if (e.ColumnIndex == 1)
            {
                return;
            }

            // Get the currently selected input/virtual input, and virtual input column from
            // the changed row.
            IDTSInput100        input  = component_.InputCollection[0];
            IDTSVirtualInput100 vInput = input.GetVirtualInput();

            // Use the column name in column 1 of the grid to find the lineage id
            // of the column we're editing.
            IDTSVirtualInputColumn100 vColumn =
                vInput.VirtualInputColumnCollection.GetVirtualInputColumnByLineageID(mapColumnNameToLineageID_[(string)mappingGridView.Rows[e.RowIndex].Cells[1].Value]);

            // pull out the first column value to determine if the cell is mapped.
            bool mapped = (bool)mappingGridView.Rows[e.RowIndex].Cells[0].Value;

            // If the checkbox cell is the one that changed, we need to either set or clear the properties.
            if (e.ColumnIndex == 0)
            {
                if (mapped)
                {   // Map the column
                    vInput.SetUsageType(vColumn.LineageID, DTSUsageType.UT_READONLY);

                    // Fetch the IDTSInputColumn100 now that it is mapped.
                    IDTSInputColumn100 inputColumn = input.InputColumnCollection.GetInputColumnByLineageID(vColumn.LineageID);

                    // Enable editing the other columns
                    mappingGridView.Rows[e.RowIndex].Cells[2].ReadOnly = false;
                    mappingGridView.Rows[e.RowIndex].Cells[3].ReadOnly = false;
                }
                else
                {
                    // The mapping for this column is unchecked.
                    // Declare this virtual input column as unused
                    mappingGridView.Rows[e.RowIndex].Cells[2].ReadOnly = true;
                    mappingGridView.Rows[e.RowIndex].Cells[3].ReadOnly = true;
                    vInput.SetUsageType(vColumn.LineageID, DTSUsageType.UT_IGNORED);
                }
            }

            if (e.ColumnIndex == 2 && mapped)
            {
                // The destination column for this input column has been specified
                // Map this column to the appropriate external metadata column

                input.InputColumnCollection.GetInputColumnByLineageID(vColumn.LineageID).ExternalMetadataColumnID =
                    mapExternalColumnNameToID_[(string)mappingGridView.Rows[e.RowIndex].Cells[2].Value];
            }


            if (!manualEditMode_)
            {
                refreshMergeStatement();
                mergeStatementRichTextBox.Text = mergeStatement_;
            }
        }