/// <summary>
        /// load this properties from an xml string
        /// </summary>
        /// <param name="xml">xml string</param>
        /// <returns>this properties (IsagCustomProperties)</returns>
        public static IsagCustomProperties LoadFromXml(string xml)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(IsagCustomProperties));

            StringReader         reader = new StringReader(xml);
            IsagCustomProperties result = (IsagCustomProperties)serializer.Deserialize(reader);

            return(result);
        }
        /// <summary>
        /// loads the components custom properties
        /// </summary>
        private void LoadCustomProperties()
        {
            object configuration = _metadata.CustomPropertyCollection[Constants.PROP_CONFIG].Value;

            _isagCustomProperties = IsagCustomProperties.Load(configuration);

            if (_isagCustomProperties == null)
            {
                _isagCustomProperties = new IsagCustomProperties();
            }
        }
        /// <summary>
        /// Loads the custom properties
        /// </summary>
        private void InitializeProperties()
        {
            object configuration = this.ComponentMetaData.CustomPropertyCollection[Constants.PROP_CONFIG].Value;

            if (configuration != null)
            {
                _isagCustomProperties = IsagCustomProperties.Load(configuration);
            }
            else
            {
                _isagCustomProperties = new IsagCustomProperties();
            }
        }
        /// <summary>
        /// Erzeugt eine Instanz der Klasse IsagCustomProperties, sofern der Parameter configuration (sollte ein XML-String sein)
        /// dieses erlaubt.
        /// Creates an instance of this class IsagCustomProperties from an xml string
        /// </summary>
        /// <param name="configuration">XML String als object</param>
        /// <returns>this properties (IsagCustomProperties)</returns>
        public static IsagCustomProperties Load(object configuration)
        {
            IsagCustomProperties customProperties = null;

            if (configuration != null && configuration.ToString() != "")
            {
                customProperties = IsagCustomProperties.LoadFromXml(configuration.ToString());
            }

            if (customProperties.OutputColumnCount > 0)
            {
                Update(ref customProperties);
            }

            return(customProperties);
        }
        /// <summary>
        /// Provides the component properties
        /// </summary>
        public override void ProvideComponentProperties()
        {
            base.ProvideComponentProperties();

            _isagCustomProperties = new IsagCustomProperties();
            //set metadata version to DLL version
            ComponentMetaDataTools.UpdateVersion(this, ComponentMetaData);

            //Clear out base implmentation
            this.ComponentMetaData.RuntimeConnectionCollection.RemoveAll();
            this.ComponentMetaData.InputCollection.RemoveAll();
            this.ComponentMetaData.OutputCollection.RemoveAll();
            this.RemoveAllInputsOutputsAndCustomProperties();

            ComponentMetaData.UsesDispositions = false;

            //Input
            IDTSInput100 input = this.ComponentMetaData.InputCollection.New();

            input.Name = Constants.INPUT_NAME;
            input.ErrorRowDisposition = DTSRowDisposition.RD_NotUsed;

            //Output
            IDTSOutput100 output = this.ComponentMetaData.OutputCollection.New();

            output.Name = Constants.OUTPUT_NAME;
            output.SynchronousInputID = input.ID;

            //Custom Property: Configuration
            IDTSCustomProperty100 prop = ComponentMetaData.CustomPropertyCollection.New();

            prop.Name  = Constants.PROP_CONFIG;
            prop.Value = _isagCustomProperties.SaveToXml();

            //new connection manager
            IDTSRuntimeConnection100 conn = this.ComponentMetaData.RuntimeConnectionCollection.New();

            conn.Name        = Constants.CONNECTION_MANAGER_NAME;
            conn.Description = "Connection to SQL Server";
        }
        /// <summary>
        /// Updates properties (called after instance of this class has been created)
        /// </summary>
        /// <param name="properties">the IsagCustomProperties</param>
        private static void Update(ref IsagCustomProperties properties)
        {
            properties.LU_Matchparameter  = properties.CompareIdColumn;
            properties.LU2_Validparameter = properties.CompareFromToColumn;

            string sql = properties.SqlStatement.Replace("\n", " ");

            int pos = sql.ToUpper().IndexOf("SELECT");

            sql = sql.Substring(pos + 6);

            try
            {
                pos = sql.ToUpper().IndexOf("ORDER BY");
                sql = sql.Substring(0, sql.Length - (sql.Length - pos));
            }
            catch (Exception)
            {}

            pos = sql.ToUpper().LastIndexOf("FROM");
            properties.LU_Table = sql.Substring(pos + 5, sql.Length - pos - 5).Trim();
            sql = sql.Substring(0, sql.Length - (sql.Length - pos));

            string[] cols;

            cols = sql.Split(",".ToCharArray());

            for (int i = properties.OutputConfigList.Count - 1; i >= 0; i--)
            {
                if (string.IsNullOrEmpty(properties.OutputConfigList[i].DftColumn))
                {
                    properties.OutputConfigList.RemoveAt(i);
                }
            }


            foreach (string col in cols)
            {
                pos = col.ToUpper().IndexOf(" AS ");
                string colName  = col.Substring(0, pos).Trim();
                string colAlias = col.Substring(pos + 4).Trim();

                foreach (OutputConfig outConfig in properties.OutputConfigList)
                {
                    if (outConfig.SqlColumn == colAlias)
                    {
                        outConfig.SqlColumn = colName;
                    }
                }

                switch (colAlias.ToUpper())
                {
                case "LU2_VALIDPARAMETER":
                    properties.LU_TableMatchColumn = colName;
                    break;

                case "LU2_TABLEVALIDFROMCOLUMN":
                    properties.LU2_TableValidFromColumn = colName;
                    break;

                case "LU2_TABLEVALIDTOCOLUMN":
                    properties.LU2_TableValidToColumn = colName;
                    break;

                default:
                    break;
                }
            }

            properties.SqlStatement        = "";
            properties.CompareIdColumn     = "";
            properties.CompareFromToColumn = "";
            properties.OutputColumnCount   = 0;
        }