/// <summary>
        /// Reinitialize metadata in case input cvolumns are invalid
        /// </summary>
        public override void ReinitializeMetaData()
        {
            if (!inputColumnsValid)
            {
                IDTSInput           input  = ComponentMetaData.InputCollection[0];
                IDTSVirtualInput100 vInput = input.GetVirtualInput();

                foreach (IDTSInputColumn col in input.InputColumnCollection)
                {
                    input.InputColumnCollection.RemoveObjectByID(col.ID);
                }
                inputColumnsValid = true;
            }
        }
Example #2
0
        /// <summary>
        /// Gets VirtulaInput of the Input of the DataFlow Component at the Index position in the Inputs Collection.
        /// It ensures that the same IDTSVirtualInput object is retured during each call and ensures proper GUI functionality
        /// </summary>
        /// <param name="index">Index of the Input to retrive VistualInput</param>
        /// <returns>IDTSVirtualINput of Input at sprovided Index position</returns>
        public IDTSVirtualInput GetVirtualInput(int index)
        {
            while (virtualInputs.Count < ComponentMetadata.InputCollection.Count)
            {
                virtualInputs.Add(null);
            }

            IDTSInput input = GetInput(index);

            if (virtualInputs[index] == null && input != null)
            {
                virtualInputs[index] = input.GetVirtualInput();
            }
            return(virtualInputs[index]);
        }
        /// <summary>
        /// Called repeatedly when the component is edited in the designer, and once at the beginning of execution.
        /// Verifies the following:
        /// 1. Check that there are no outputs
        /// 2. Check that there is only one input
        /// 3. Check that all upstream columns are present.
        /// </summary>
        /// <returns>The status of the validation</returns>
        public override DTSValidationStatus Validate()
        {
            bool cancel = false;

            if (ComponentMetaData.InputCollection.Count != 1)
            {
                ComponentMetaData.FireError(0, ComponentMetaData.Name, "The input collection count is not 1.", String.Empty, 0, out cancel);
                return(DTSValidationStatus.VS_ISCORRUPT);
            }

            if (ComponentMetaData.OutputCollection.Count != 0)
            {
                ComponentMetaData.FireError(0, ComponentMetaData.Name, "The output collection count is not 0.", String.Empty, 0, out cancel);
                return(DTSValidationStatus.VS_ISCORRUPT);
            }

            IDTSInput        input  = ComponentMetaData.InputCollection[0];
            IDTSVirtualInput vInput = input.GetVirtualInput();

            if (input.HasSideEffects == false)
            {
                ComponentMetaData.FireError(0, ComponentMetaData.Name, "The input does not have HasSideEffects set.", String.Empty, 0, out cancel);
                return(DTSValidationStatus.VS_ISCORRUPT);
            }

            foreach (IDTSInputColumn inputColumn in input.InputColumnCollection)
            {
                try
                {
                    IDTSVirtualInputColumn vColumn = vInput.VirtualInputColumnCollection.GetVirtualInputColumnByLineageID(inputColumn.LineageID);
                }
                catch
                {
                    ComponentMetaData.FireError(0, ComponentMetaData.Name, "The input column " + inputColumn.IdentificationString + " does not match a column in the upstream output.", String.Empty, 0, out cancel);
                    areInputColumnsValid = false;
                    return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
                }
            }
            //return base.Validate();
            return(DTSValidationStatus.VS_ISVALID);
        }
        /// <summary>
        /// Validate HashColumnsTransform metadata
        /// </summary>
        /// <returns></returns>
        public override DTSValidationStatus Validate()
        {
            if (ComponentMetaData.InputCollection.Count != 1)
            {
                FireComponentMetadataError(0, Resources.ErrorIncorrectNumberOfInputs);
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }

            if (ComponentMetaData.OutputCollection.Count != 1)
            {
                FireComponentMetadataError(0, Resources.ErrorIncorrectNumberOfOutputs);
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }

            IDTSInput        input  = ComponentMetaData.InputCollection[0];
            IDTSVirtualInput vInput = input.GetVirtualInput();

            foreach (IDTSInputColumn column in input.InputColumnCollection)
            {
                try
                {
                    IDTSVirtualInputColumn100 vColumn = vInput.VirtualInputColumnCollection.GetVirtualInputColumnByLineageID(column.LineageID);
                }
                catch
                {
                    FireComponentMetadataError(0, string.Format(Resources.ErrorInputColumnNotInUpstreamComponent, column.IdentificationString));
                    inputColumnsValid = false;
                    return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
                }
            }

            IDTSOutput output = ComponentMetaData.OutputCollection[0];
            List <IDTSOutputColumn> redundantColumns = new List <IDTSOutputColumn>(output.OutputColumnCollection.Count);
            bool       xmlColumnExists      = false;
            List <int> missingLineages      = new List <int>();
            List <int> missingInputLineages = new List <int>();
            bool       missingError         = false;

            foreach (IDTSOutputColumn outputColumn in output.OutputColumnCollection)
            {
                bool isRendundant  = true;
                bool isInputColumn = false;
                foreach (IDTSInputColumn inputColumn in input.InputColumnCollection)
                {
                    if (inputColumn.Name == outputColumn.Name)
                    {
                        isRendundant  = false;
                        isInputColumn = true;
                        break;
                    }
                }


                //Check if XML Column;
                if (!isInputColumn)
                {
                    foreach (IDTSCustomProperty prop in outputColumn.CustomPropertyCollection)
                    {
                        if (prop.Name == Resources.XmlInputColumnsPropertyname)
                        {
                            isRendundant    = false;
                            xmlColumnExists = true;

                            var lineages = InputColumns.ParseInputLineages(prop.Value.ToString());

                            foreach (IDTSInputColumn icol in input.InputColumnCollection)
                            {
                                int l = icol.LineageID;
                                lineages.Remove(l);
                                if (lineages.Count == 0)
                                {
                                    break;
                                }
                            }

                            if (lineages.Count > 0)
                            {
                                foreach (int l in lineages)
                                {
                                    if (!missingInputLineages.Contains(l))
                                    {
                                        missingInputLineages.Add(l);
                                    }
                                }

                                foreach (IDTSVirtualInputColumn vcol in vInput.VirtualInputColumnCollection)
                                {
                                    int l = vcol.LineageID;
                                    lineages.Remove(l);
                                    if (lineages.Count == 0)
                                    {
                                        break;
                                    }
                                }

                                if (lineages.Count > 0)
                                {
                                    foreach (int l in lineages)
                                    {
                                        if (!missingLineages.Contains(l))
                                        {
                                            missingLineages.Add(l);
                                        }
                                    }
                                }
                            }
                        }
                        if (prop.Name == Resources.XmlSaveOptionPropertyName)
                        {
                            isRendundant    = false;
                            xmlColumnExists = true;

                            if (!Enum.IsDefined(typeof(SaveOptions), prop.Value))
                            {
                                FireComponentMetadataError(0, string.Format(Resources.ErrorInvalidSaveOption, outputColumn.Name));
                                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
                            }
                            else
                            {
                                if (outputColumn.DataType != DataType.DT_NTEXT && outputColumn.DataType != DataType.DT_WSTR)
                                {
                                    FireComponentMetadataError(0, string.Format(Resources.ErrorInvalidDataType, outputColumn.Name));
                                    return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
                                }
                            }
                        }
                    }
                }

                //add redundand column to redundand list
                if (isRendundant)
                {
                    redundantColumns.Add(outputColumn);
                }
            }


            if (missingLineages.Count > 0)
            {
                string ml = string.Join(", ", missingLineages.ConvertAll <string>(l => l.ToString()).ToArray());

                FireComponentMetadataError(0, string.Format("Output columns are referencing input column lineages which do not exists: {0}", ml));
                missingError = true;
            }

            if (missingInputLineages.Count > 0)
            {
                string ml = string.Join(", ", missingInputLineages.ConvertAll <string>(l => l.ToString()).ToArray());

                FireComponentMetadataError(0, string.Format("Output columns are referencing input column lineages which are not selected as Input columns: {0}", ml));
                missingError = true;
            }

            if (missingError)
            {
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }



            //remove redundand output columns
            foreach (IDTSOutputColumn col in redundantColumns)
            {
                output.OutputColumnCollection.RemoveObjectByID(col.ID);
            }

            //If XmlColumn does not exists, create a default one
            if (!xmlColumnExists)
            {
                IDTSOutputColumn xmlCol = output.OutputColumnCollection.New();
                xmlCol.Name        = Resources.XmlColumnDefaultName;
                xmlCol.Description = Resources.XmlColumnDefaultDesccription;

                SetXmlColumnProperties(xmlCol);
            }

            return(DTSValidationStatus.VS_ISVALID);
        }
        /// <summary>
        /// Validate HashColumnsTransform metadata
        /// </summary>
        /// <returns></returns>
        public override DTSValidationStatus Validate()
        {
            //Check that we have only one input
            if (ComponentMetaData.InputCollection.Count != 1)
            {
                FireComponentMetadataError(0, Resources.ErrorIncorrectNumberOfInputs);
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }
            //Check that we have only one output
            if (ComponentMetaData.OutputCollection.Count != 1)
            {
                FireComponentMetadataError(0, Resources.ErrorIncorrectNumberOfOutputs);
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }

            IDTSInput        input  = ComponentMetaData.InputCollection[0];
            IDTSVirtualInput vInput = input.GetVirtualInput();

            //Check Input columns that they exists
            foreach (IDTSInputColumn column in input.InputColumnCollection)
            {
                try
                {
                    IDTSVirtualInputColumn100 vColumn = vInput.VirtualInputColumnCollection.GetVirtualInputColumnByLineageID(column.LineageID);
                }
                catch
                {
                    inputColumnsValid = false;
                    FireComponentMetadataError(0, string.Format(Resources.ErrorInputColumnNotInUpstreamComponent, column.IdentificationString));
                    return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
                }
            }

            IDTSOutput output = ComponentMetaData.OutputCollection[0];
            List <IDTSOutputColumn> redundantColumns = new List <IDTSOutputColumn>(output.OutputColumnCollection.Count);
            bool rowNumberColumnExists = false;

            foreach (IDTSOutputColumn outputColumn in output.OutputColumnCollection)
            {
                bool isRendundant = true;

                foreach (IDTSCustomProperty prop in outputColumn.CustomPropertyCollection)
                {
                    if (prop.Name == Resources.RowNumberIncrementByPropertyName)
                    {
                        isRendundant          = false;
                        rowNumberColumnExists = true;
                    }

                    //TODO: Here will be checks for proper properties settings
                }
                //add redundand column to redundand list
                if (isRendundant)
                {
                    redundantColumns.Add(outputColumn);
                }
            }

            //remove redundand output columns
            foreach (IDTSOutputColumn100 col in redundantColumns)
            {
                output.OutputColumnCollection.RemoveObjectByID(col.ID);
            }

            if (!rowNumberColumnExists)
            {
                rowNumberColumnExists = true;
                output = ComponentMetaData.OutputCollection[0];
                IDTSOutputColumn rowNumberColumn = output.OutputColumnCollection.New();
                rowNumberColumn.Name        = Resources.RowNumberDefaultColumnName;
                rowNumberColumn.Description = Resources.RowNumberDefaultColumnDescription;

                SetRowNumberColumnProperties(rowNumberColumn);
            }

            return(DTSValidationStatus.VS_ISVALID);
        }