/// <summary>
        /// Gather mapping informations in Pre execute phase
        /// </summary>
        private void CreateMapping()
        {
            _columnInfos = new List <ColumnInfo>(this.ComponentMetaData.InputCollection[0].InputColumnCollection.Count);
            IDTSInput100 input = this.ComponentMetaData.InputCollection[Constants.INPUT_NAME];

            foreach (IDTSInputColumn100 col in input.InputColumnCollection)
            {
                // Find the position in buffers that this column will take, and add it to the map.
                ColumnConfig config = _IsagCustomProperties.GetColumnConfigByInputColumnName(col.Name);
                _columnInfos.Add(new ColumnInfo(col.Name, col.DataType,
                                                this.BufferManager.FindColumnByLineageID(input.Buffer, col.LineageID),
                                                col.Length, col.Precision, col.Scale, col.CodePage, _IsagCustomProperties.IsColumnUsedForBulkCopy(config), config.OutputColumnName, config.Insert, config.IsGeometryDataType)
                                 );
            }

            if (_IsagCustomProperties.UseBulkInsert)
            {
                _columnMapping = new Dictionary <string, string>();
                foreach (ColumnConfig config in _IsagCustomProperties.ColumnConfigList)
                {
                    if (config.Insert)
                    {
                        _columnMapping.Add(config.OutputColumnName, config.InputColumnName);
                    }
                }
            }
        }
        /// <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>
        /// Creates, adds and returns a column configuration
        /// </summary>
        /// <param name="sqlColumns">Sql column list</param>
        /// <returns>column configuration</returns>
        public ColumnConfig AddColumnConfig(SqlColumnList sqlColumns)
        {
            ColumnConfig result = new ColumnConfig();

            result.SetSqlColumnDefinitions(sqlColumns);
            result.Default  = "";
            result.Function = "";
            this.ColumnConfigList.Add(result);

            return(result);
        }
        /// <summary>
        /// Is column written to temporary table?
        /// </summary>
        /// <param name="column">column configuration</param>
        /// <returns>Is column written to temporary table?</returns>
        public bool IsColumnUsedForBulkCopy(ColumnConfig column)
        {
            List <string> referencedByFunction = GetNeededColumnsReferenceByFunction();

            return(column.IsInputColumnUsed || referencedByFunction.Contains(column.InputColumnName));
        }
 /// <summary>
 /// Automap an input column to an output column
 /// </summary>
 /// <param name="config">column configuration
 /// </param>
 public void AutoMap(ColumnConfig config)
 {
     config.AutoMap(PrefixInput, PrefixOutput);
 }