/// <summary>
        /// Rebuilds mapping of input and output columns
        /// (errors are corrected if possible)
        /// </summary>
        /// <param name="componentMetaData">SSIS components metadata</param>
        public void RebuildMappings(IDTSComponentMetaData100 componentMetaData, IsagEvents events)
        {
            IDTSInput100        input  = componentMetaData.InputCollection[Constants.INPUT_NAME];
            IDTSVirtualInput100 vInput = input.GetVirtualInput();

            Dictionary <int, ColumnConfig> mappingsInput         = new Dictionary <int, ColumnConfig>();
            List <ColumnConfig>            mappingsWithoutInputs = new List <ColumnConfig>();
            List <ColumnConfig>            newMappings           = new List <ColumnConfig>();

            if (this.ContainsWrongUsageType(vInput.VirtualInputColumnCollection, events))
            {
                ComponentMetaDataTools.SetUsageTypeReadOnly(vInput);
            }

            //Writre existing mappings in 2 lists (one with input columns, one without)
            foreach (ColumnConfig config in this.ColumnConfigList)
            {
                if (config.HasInput)
                {
                    mappingsInput.Add(config.InputColumnId, config);
                }
                else
                {
                    mappingsWithoutInputs.Add(config);
                }
            }

            //Generate new mapping using SSIS input columns
            foreach (IDTSInputColumn100 inputCol in input.InputColumnCollection)
            {
                ColumnConfig config;

                if (mappingsInput.ContainsKey(inputCol.ID))
                {
                    config = mappingsInput[inputCol.ID];
                    config.InputColumnName = inputCol.Name;
                    config.DataTypeInput   = SqlCreator.GetSQLServerDataTypeFromInput(inputCol, config.IsGeometryDataType);
                }
                else
                {
                    config = new ColumnConfig(inputCol.Name, SqlCreator.GetSQLServerDataTypeFromInput(inputCol, isGeometry: false), inputCol);
                }

                newMappings.Add(config);
            }

            //Add properties to the newly created mapping
            ColumnConfigList.Clear();

            foreach (ColumnConfig config in newMappings)
            {
                ColumnConfigList.Add(config);
            }
            foreach (ColumnConfig config in mappingsWithoutInputs)
            {
                ColumnConfigList.Add(config);
            }

            this.Save(componentMetaData);
        }
        /// <summary>
        /// Checks if column names and datatype are valid
        /// Does the mapping contain a row without a match (input column ids are compared) in the SSIS input column collection?
        /// If match is found: Are mappings input columm name and datatype equal to SSIS input column name and datatype?
        /// </summary>
        /// <param name="input">SSIS input</param>
        /// <param name="componentMetaData">SSIS component metadata</param>
        /// <returns>Are column names and datatypes valid?</returns>
        private bool AreColumnNamesAndDataTypesValid(IDTSInput100 input, IsagEvents events)
        {
            foreach (ColumnConfig config in this.ColumnConfigList)
            {
                if (config.HasInput)
                {
                    IDTSInputColumn100 inputColumn;

                    try
                    {
                        inputColumn = input.InputColumnCollection.GetObjectByID(config.InputColumnId);
                    }
                    catch (Exception)
                    {
                        events.Fire(IsagEvents.IsagEventType.Error, "The Mapping contains at least one column with a non existent, but assigned input column!");
                        return(false);
                    }

                    if (inputColumn.Name != config.InputColumnName || config.DataTypeInput != SqlCreator.GetSQLServerDataTypeFromInput(inputColumn, config.IsGeometryDataType))
                    {
                        events.Fire(IsagEvents.IsagEventType.Error, "The Mapping contains at least one column with a name or datatype differing from the assigned input column!");

                        return(false);
                    }
                }
            }

            return(true);
        }
        public void RebuildMappings(IDTSVirtualInputColumnCollection100 virtualInputColumns, IDTSInputColumnCollection100 inputColumns)
        {
            Hashtable       mappingsInput         = new Hashtable();
            List <object[]> mappingsWithoutInputs = new List <object[]>();
            List <object[]> newMappings           = new List <object[]>();

            //Speichern der bisherigen Mappings in 2 Listen (1x mit Input-Mapping, 1x ohne)
            for (int i = 0; i < this.MappingRowCount; i++)
            {
                object[] row = this.GetMappingRow(i);


                if (row[Constants.MAPPING_IDX_INPUT_COL_NAME] != null &&
                    row[Constants.MAPPING_IDX_INPUT_COL_NAME].ToString() != "")
                {
                    mappingsInput.Add(row[Constants.MAPPING_IDX_INPUT_COLUMN_ID], row);
                }
                else
                {
                    mappingsWithoutInputs.Add(row);
                }
            }


            //Generieren von neuen MappingRows anhand der InputColumns
            foreach (IDTSInputColumn100 inputCol in inputColumns)
            {
                object[] row;

                if (mappingsInput.Contains(inputCol.ID))
                {
                    row = (object[])mappingsInput[inputCol.ID];
                    row[Constants.MAPPING_IDX_INPUT_COL_NAME] = inputCol.Name;
                    row[Constants.MAPPING_IDX_DATATYPE_INPUT] = SqlCreator.GetSQLServerDataTypeFromInput(inputCol);//inputCol.DataType.ToString();
                }
                else
                {
                    row = new object[Constants.MAPPING_COUNT];

                    row[Constants.MAPPING_IDX_USE_INSERT]      = true;
                    row[Constants.MAPPING_IDX_USE_UPDATE]      = true;
                    row[Constants.MAPPING_IDX_KEY]             = false;
                    row[Constants.MAPPING_IDX_INPUT_COL_NAME]  = inputCol.Name;
                    row[Constants.MAPPING_IDX_OUTPUT_COL_NAME] = Constants.MAPPING_NOT_ASSIGNED;
                    row[Constants.MAPPING_IDX_DEFAULT]         = "";
                    row[Constants.MAPPING_IDX_DATATYPE_INPUT]  = SqlCreator.GetSQLServerDataTypeFromInput(inputCol);//inputCol.DataType.ToString();
                    row[Constants.MAPPING_IDX_INPUT_COLUMN_ID] = inputCol.ID;
                }

                newMappings.Add(row);
            }

            //Aufbauen der neuen Mapping Properties
            this.RemoveMappings();

            foreach (object[] row in newMappings)
            {
                this.AddMappingProperty(row);
            }
            foreach (object[] row in mappingsWithoutInputs)
            {
                this.AddMappingProperty(row);
            }
        }