Example #1
0
        /// <summary>
        /// Gets List of OutputColumns of Particular OuputID encapsulated in the FormOutputColumn class
        /// </summary>
        /// <param name="outputID">ID of the Output to get OutputColumns</param>
        /// <param name="creator">OutputColumnCreator to be used for creation of the FormInputColumn instances</param>
        /// <param name="changedHandler">PropertyChangedEventHanled to be associated with the newly created FormInputColumn objects</param>
        /// <returns>List of FomrInputColumn</returns>
        public virtual List <FormOutputColumn> GetFormOutputColumns(int outputID, OutputColumnCreator creator, PropertyChangedEventHandler changedHandler)
        {
            List <FormOutputColumn> outputCols = new List <FormOutputColumn>();
            IDTSOutput output = ComponentMetadata.OutputCollection.GetObjectByID(outputID);

            if (output != null && creator != null)
            {
                for (int i = 0; i < output.OutputColumnCollection.Count; i++)
                {
                    IDTSOutputColumn col = output.OutputColumnCollection[i];

                    FormOutputColumn oCol = creator(col);
                    oCol.UIHelper = this;
                    oCol.OutputID = outputID;

                    oCol.Index = i;

                    if (changedHandler != null)
                    {
                        oCol.PropertyChanged += changedHandler;
                    }

                    outputCols.Add(oCol);
                }
            }

            return(outputCols);
        }
        /// <summary>
        /// Provides SSIS Component Properties
        /// </summary>
        public override void ProvideComponentProperties()
        {
            this.ComponentMetaData.Version = PipelineUtils.GetPipelineComponentVersion(this);

            this.ComponentMetaData.Name        = Resources.ColumnsToXMLTransformationName;
            this.ComponentMetaData.Description = Resources.ColumnsToXMLTransformationDescription;
            this.ComponentMetaData.ContactInfo = Resources.TransformationContactInfo;

            // Reset the component.
            base.RemoveAllInputsOutputsAndCustomProperties();

            //call base method to insert input and output
            base.ProvideComponentProperties();

            //Set Input properties
            IDTSInput input = ComponentMetaData.InputCollection[0];

            input.Name = Resources.ColumnsToXmlInputName;

            // Set Output properties
            IDTSOutput output = ComponentMetaData.OutputCollection[0];

            output.Name = Resources.ColumnsToXmlOutputName;
            output.SynchronousInputID = input.ID;

            //Add Custom Properties for the component
            AddComponentCustomProperties();
        }
Example #3
0
        public override object Execute(Package package, DtsContainer container)
        {
            string remainingPath;
            var    taskHost = Helper.FindExecutable(package, Properties[PropOutput].Value, out remainingPath) as TaskHost;

            if (taskHost == null)
            {
                throw new ArgumentException("Output property did not match a valid component output.", "package");
            }
            var mainPipe = taskHost.InnerObject as MainPipe;

            if (mainPipe == null)
            {
                throw new ArgumentException("Output property did not match a valid component output.", "package");
            }

            IDTSOutput output = Helper.FindComponentOutput(mainPipe, remainingPath);

            if (output == null)
            {
                throw new ArgumentException("Output property did not match a valid component output.", "package");
            }

            throw new NotImplementedException();
            // return true;
        }
Example #4
0
 protected Pipe.IDTSOutput100 AddSSISOutput(string outputName)
 {
     Pipe.IDTSOutput100 output = ComponentWrapper.InsertOutput(Pipe.DTSInsertPlacement.IP_AFTER, SSISDefaultOutput.ID);
     output.Name        = outputName;
     output.Description = outputName;
     return(output);
 }
Example #5
0
 public OutputWrapper FindOutput(string outputName)
 {
     Pipe.IDTSOutput100 ssisOutput = FindSSISOutput(outputName);
     if (ssisOutput != null)
     {
         return(new OutputWrapper(ssisOutput));
     }
     else
     {
         throw new KeyNotFoundException("Can't find output with name " + outputName);
     }
 }
            /// <summary>
            /// Creates a new instance of the IDTSOutputColumn enccapsualted in the MetadataSolumn
            /// </summary>
            /// <param name="output">Output where the new OutputColumn should be created</param>
            /// <returns></returns>
            public static RowNumberColumn CreateNewInstance(IDTSOutput output)
            {
                IDTSOutputColumn col = output.OutputColumnCollection.New();

                col.Name = Resources.RowNumberDefaultColumnName + col.ID.ToString();

                RowNumberTransformation.SetRowNumberColumnProperties(col);

                RowNumberColumn c = new RowNumberColumn(col);

                return(c);
            }
            /// <summary>
            /// Creates a new instance of the IDTSOutputColumn enccapsualted in the MetadataSolumn
            /// </summary>
            /// <param name="output">Output where the new OutputColumn should be created</param>
            /// <returns></returns>
            public static MetadataColumn CreateNewInstance(IDTSOutput output)
            {
                IDTSOutputColumn col = output.OutputColumnCollection.New();

                col.Name = Resources.RegExExpressionDefaultOutputColumnName + col.ID.ToString();

                RegExExtractionTransformation.SetOutputColumnProperties(col, RegExExtractionTransformation.SetPropertyType.All, null, null);

                MetadataColumn c = new MetadataColumn(col);

                return(c);
            }
Example #8
0
            public static FormOutputColumn CreateNewInstance(IDTSOutput output)
            {
                IDTSOutputColumn col = output.OutputColumnCollection.New();

                col.Name        = Resources.XmlColumnDefaultName + col.ID;
                col.Description = Resources.XmlColumnDefaultDesccription;
                ColumnsToXmlTransformation.SetXmlColumnProperties(col);

                LookupErrorColumn c = new LookupErrorColumn(col);

                return(c);
            }
            /// <summary>
            /// Create a new instance of the HashOutputColumn
            /// </summary>
            /// <param name="output">output in which the instance should be created</param>
            /// <returns></returns>
            public static HashOutputColumn CreateNewInstance(IDTSOutput output)
            {
                IDTSOutputColumn col = output.OutputColumnCollection.New();

                col.Name        = Resources.HashColumnDefaultName + col.ID;
                col.Description = Resources.HashColumnDefaultDesccription;

                HashColumnsTransformationHelper.SetHashColumnProperties(HashColumnsTransformation.HashOuputColumnProperties.All, col);

                HashOutputColumn c = new HashOutputColumn(col);

                return(c);
            }
        /// <summary>
        /// Inserts new Output columns as specified position in specified output
        /// </summary>
        /// <param name="outputID">ID of the output to insert new output column</param>
        /// <param name="outputColumnIndex">Index of the inserted output column</param>
        /// <param name="name">Name of the inserted output column</param>
        /// <param name="description">Description of the inserted column</param>
        /// <returns>Inserted output column</returns>
        public override IDTSOutputColumn InsertOutputColumnAt(int outputID, int outputColumnIndex, string name, string description)
        {
            //Insert new column into specified output
            IDTSOutput       output    = ComponentMetaData.OutputCollection.FindObjectByID(outputID);
            IDTSOutputColumn xmlColumn = output.OutputColumnCollection.NewAt(outputColumnIndex);

            xmlColumn.Name        = name;
            xmlColumn.Description = description;

            SetXmlColumnProperties(xmlColumn);

            return(xmlColumn);
        }
Example #11
0
        /// <summary>
        /// Lodas the column data into the dts objects from the datasource for columns
        /// </summary>
        private void LoadDataSourceInformation(IDTSOutput output, Dictionary <string, string> existingColumnData)
        {
            object sharepointUrl      = ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTSITEURL].Value;
            object sharepointListName = ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTLISTNAME].Value;

            // Reset the values
            if ((sharepointUrl != null) && (sharepointListName != null))
            {
                CreateExternalMetaDataColumns(output,
                                              (string)ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTSITEURL].Value,
                                              (string)ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTLISTNAME].Value,
                                              (string)ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTLISTVIEWNAME].Value,
                                              existingColumnData);
            }
        }
Example #12
0
        /// <summary>
        /// Gets List of DataFlow component Outputs encapsulated in the FormOutputClass
        /// </summary>
        /// <param name="changeHandler">PropertyChangedEventHandler to be associated with the newly created FormOutput class</param>
        /// <returns>List of FormOutput</returns>
        public List <FormOutput> GetFormOutputs(PropertyChangedEventHandler changeHandler)
        {
            List <FormOutput> outputs = new List <FormOutput>();

            if (ComponentMetadata != null)
            {
                for (int i = 0; i < ComponentMetadata.OutputCollection.Count; i++)
                {
                    IDTSOutput o  = ComponentMetadata.OutputCollection[i];
                    FormOutput fo = new FormOutput(o);
                    fo.Index            = i;
                    fo.PropertyChanged += changeHandler;
                    outputs.Add(fo);
                }
            }
            return(outputs);
        }
        /// <summary>
        /// Sets value of the custom column property
        /// </summary>
        /// <param name="outputID">Output ID</param>
        /// <param name="outputColumnID">Output Column ID</param>
        /// <param name="propertyName">Name of the custom Property</param>
        /// <param name="propertyValue">Property value to be set</param>
        /// <returns>Custom property</returns>
        public override IDTSCustomProperty SetOutputColumnProperty(int outputID, int outputColumnID, string propertyName, object propertyValue)
        {
            //in case of HasshType property update, update output column data type
            if (propertyName == Resources.XmlSaveOptionPropertyName)
            {
                IDTSOutput       output       = ComponentMetaData.OutputCollection[0];
                IDTSOutputColumn outputColumn = output.OutputColumnCollection.FindObjectByID(outputColumnID);

                //outputColumn.SetDataTypeProperties(DataType.DT_NTEXT, 0, 0, 0, 0);

                return(base.SetOutputColumnProperty(outputID, outputColumnID, propertyName, propertyValue));
            }
            else if (propertyName == Resources.XmlSerializeLineageName || propertyName == Resources.XmlSerializeDataTypeName || propertyName == "DataType" || propertyName == "DataLength")
            {
                return(base.SetOutputColumnProperty(outputID, outputColumnID, propertyName, propertyValue));
            }

            throw new Exception(string.Format(Resources.ErrorOutputColumnPropertyCannotBeChanged, propertyName));
        }
Example #14
0
        private void form_DeleteOutputColumn(object sender, DeleteOutputColumnArgs args)
        {
            Debug.Assert(args.OutputColumnDetail.OutputColumn != null, "Invalid arguments passed from the UI");

            this.ClearErrors();
            try
            {
                // Grab the output collection
                IDTSOutput output = this.ComponentMetadata.OutputCollection[0];

                // Remove the column from the output collect.
                output.OutputColumnCollection.RemoveObjectByID(((IDTSOutputColumn)args.OutputColumnDetail.OutputColumn.Tag).ID);
            }
            catch (Exception ex)
            {
                this.ReportErrors(ex);
                args.CancelAction = true;
            }
        }
Example #15
0
        private void form_AddOutputColumn(object sender, AddOutputColumnNameArgs args)
        {
            Debug.Assert(args.OutputColumnDetail.OutputColumn != null, "Invalid arguments passed from the UI");

            this.ClearErrors();
            try
            {
                // Grab the output collection, and the number of output columns
                IDTSOutput output     = this.ComponentMetadata.OutputCollection[0];
                int        locationID = output.OutputColumnCollection.Count;

                // Create a new output column at the end of the set of output columns.
                IDTSOutputColumn outputColumn = this.DesigntimeComponent.InsertOutputColumnAt(output.ID, locationID, args.OutputColumnDetail.OutputColumn.Name, string.Empty);
                if (outputColumn == null)
                {
                    throw new ApplicationException(Properties.Resources.UIisInconsistentState);
                }

                // assign the output column details into the args.
                args.OutputColumnDetail.OutputColumn = new DataFlowElement(outputColumn.Name.ToString(), outputColumn);
                int j = 0;

                // assign the array to hold all the input columns
                args.OutputColumnDetail.InputColumns = new InputColumnElement[this.ComponentMetadata.InputCollection[0].InputColumnCollection.Count];

                // fill the array with unselected input columns.
                foreach (IDTSInputColumn inputColumn in this.ComponentMetadata.InputCollection[0].InputColumnCollection)
                {
                    args.OutputColumnDetail.InputColumns[j]              = new InputColumnElement();
                    args.OutputColumnDetail.InputColumns[j].InputColumn  = new DataFlowElement(inputColumn.Name, inputColumn);
                    args.OutputColumnDetail.InputColumns[j].LineageID    = inputColumn.LineageID;
                    args.OutputColumnDetail.InputColumns[j].Selected     = false;
                    args.OutputColumnDetail.InputColumns[j].SortPosition = 999999;
                    j++;
                }
            }
            catch (Exception ex)
            {
                this.ReportErrors(ex);
                args.CancelAction = true;
            }
        }
Example #16
0
        /// <summary>
        /// Allow the user to change a String to a NText, although this may affect performance.
        /// </summary>
        /// <param name="outputID"></param>
        /// <param name="outputColumnID"></param>
        /// <param name="dataType"></param>
        /// <param name="length"></param>
        /// <param name="precision"></param>
        /// <param name="scale"></param>
        /// <param name="codePage"></param>
        public override void SetOutputColumnDataTypeProperties(int outputID, int outputColumnID, Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType dataType, int length, int precision, int scale, int codePage)
        {
            var        outputColl = this.ComponentMetaData.OutputCollection;
            IDTSOutput output     = outputColl.GetObjectByID(outputID);

            var columnColl          = output.OutputColumnCollection;
            IDTSOutputColumn column = columnColl.GetObjectByID(outputColumnID);

            var sourceColl = output.ExternalMetadataColumnCollection;
            IDTSExternalMetadataColumn columnSource = sourceColl.GetObjectByID(column.ExternalMetadataColumnID);

            if (((column.DataType == DataType.DT_WSTR) || (column.DataType == DataType.DT_NTEXT)) &&
                ((dataType == DataType.DT_NTEXT) || (dataType == DataType.DT_WSTR)))
            {
                column.SetDataTypeProperties(dataType, length, precision, scale, codePage);
            }
            else
            {
                base.SetOutputColumnDataTypeProperties(outputID, outputColumnID, dataType, length, precision, scale, codePage);
            }
        }
Example #17
0
        /// <summary>
        /// Connects to SharePoint and gets any columns on the target
        /// </summary>
        /// <param name="output"></param>
        /// <param name="p"></param>
        private void CreateExternalMetaDataColumns(
            IDTSOutput output, string sharepointUrl, string listName, string viewName,
            Dictionary <string, string> existingColumnData)
        {
            // No need to load if the Url is bad.
            if ((sharepointUrl == null) || (sharepointUrl.Length == 0))
            {
                return;
            }

            // Need a list to continue
            if ((listName == null) || (listName.Length == 0))
            {
                return;
            }

            // If the list has changed, then we do not want any of the exisiting column data to
            // influence it (provides a way to actually reset the names if needed)
            if (output.Description != listName)
            {
                existingColumnData.Clear();
                output.Description = listName;
            }

            try
            {
                List <SharePointUtility.DataObject.ColumnData> accessibleColumns =
                    GetAccessibleSharePointColumns(sharepointUrl, listName, viewName);

                foreach (var column in accessibleColumns)
                {
                    // Setup the primary column details from the List
                    IDTSExternalMetadataColumn dtsColumnMeta = output.ExternalMetadataColumnCollection.New();
                    if (existingColumnData.ContainsKey(column.Name))
                    {
                        dtsColumnMeta.Name = existingColumnData[column.Name];
                    }
                    else
                    {
                        dtsColumnMeta.Name = column.FriendlyName;
                    }
                    dtsColumnMeta.Description = column.DisplayName;
                    dtsColumnMeta.Length      = 0;
                    dtsColumnMeta.Precision   = 0;
                    dtsColumnMeta.Scale       = 0;
                    if ("Boolean|AllDayEvent|Attachments|CrossProjectLink|Recurrence".Contains(column.SharePointType))
                    {
                        dtsColumnMeta.DataType = DataType.DT_BOOL;
                    }
                    else if (column.SharePointType == "DateTime")
                    {
                        dtsColumnMeta.DataType = DataType.DT_DBTIMESTAMP;
                    }
                    else if ("Number|Currency".Contains(column.SharePointType))
                    {
                        // Max = 100,000,000,000.00000
                        dtsColumnMeta.DataType = DataType.DT_R8;
                    }
                    else if ("Counter|Integer".Contains(column.SharePointType))
                    {
                        dtsColumnMeta.DataType = DataType.DT_I4;
                    }
                    else if ("Guid".Contains(column.SharePointType))
                    {
                        dtsColumnMeta.DataType = DataType.DT_GUID;
                    }
                    else
                    {
                        if (column.MaxLength == -1)
                        {
                            dtsColumnMeta.DataType = DataType.DT_NTEXT;
                            dtsColumnMeta.Length   = 0;
                        }
                        else
                        {
                            dtsColumnMeta.DataType = DataType.DT_WSTR;
                            dtsColumnMeta.Length   = column.MaxLength;
                        }
                    }

                    IDTSCustomProperty fieldNameMeta = dtsColumnMeta.CustomPropertyCollection.New();
                    fieldNameMeta.Name        = "Id";
                    fieldNameMeta.Description = "SharePoint ID";
                    fieldNameMeta.Value       = column.Name;

                    // Create default output columns for all of the fields returned and link to the original columns
                    IDTSOutputColumn dtsColumn = output.OutputColumnCollection.New();
                    dtsColumn.Name        = dtsColumnMeta.Name;
                    dtsColumn.Description = dtsColumnMeta.Description;
                    dtsColumn.ExternalMetadataColumnID = dtsColumnMeta.ID;

                    IDTSCustomProperty fieldName = dtsColumn.CustomPropertyCollection.New();
                    fieldName.Name        = fieldNameMeta.Name;
                    fieldName.Description = fieldNameMeta.Description;
                    fieldName.Value       = fieldNameMeta.Value;

                    dtsColumn.SetDataTypeProperties(
                        dtsColumnMeta.DataType, dtsColumnMeta.Length, dtsColumnMeta.Precision, dtsColumnMeta.Scale, 0);
                }
            }
            catch (ApplicationException)
            {
                // Exception happened, so clear the columns, which will invalidate this object.
                output.ExternalMetadataColumnCollection.RemoveAll();
            }
        }
        /// <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);
        }
        /// <summary>
        /// Connects to SharePoint and gets any columns on the target
        /// </summary>
        /// <param name="output"></param>
        /// <param name="p"></param>
        private void CreateExternalMetaDataColumns(
            IDTSOutput output, string sharepointUrl, string listName, string viewName,
            Dictionary<string, string> existingColumnData)
        {
            // No need to load if the Url is bad.
            if ((sharepointUrl == null) || (sharepointUrl.Length == 0))
                return;

            // Need a list to continue
            if ((listName == null) || (listName.Length == 0))
                return;

            // If the list has changed, then we do not want any of the exisiting column data to
            // influence it (provides a way to actually reset the names if needed)
            if (output.Description != listName)
            {
                existingColumnData.Clear();
                output.Description = listName;
            }

            try
            {
                List<SharePointUtility.DataObject.ColumnData> accessibleColumns =
                    GetAccessibleSharePointColumns(sharepointUrl, listName, viewName);

                // Group the friendly names which are duplicated
                var dupeNames = from n in accessibleColumns
                                group n by n.FriendlyName into g
                                where g.Count() > 1
                                select g.Key;

                foreach (var column in accessibleColumns)
                {
                    // Setup the primary column details from the List
                    IDTSExternalMetadataColumn dtsColumnMeta = output.ExternalMetadataColumnCollection.New();
                    if (existingColumnData.ContainsKey(column.Name))
                    {
                        dtsColumnMeta.Name = existingColumnData[column.Name];
                    }
                    else if (dupeNames.Contains(column.FriendlyName))
                    {
                        // Add the more descriptive name after the duplicate names
                        dtsColumnMeta.Name = column.FriendlyName + " (" + column.Name + ")";
                    }
                    else
                    {
                        dtsColumnMeta.Name = column.FriendlyName;
                    }
                    dtsColumnMeta.Description = column.DisplayName;
                    dtsColumnMeta.Length = 0;
                    dtsColumnMeta.Precision = 0;
                    dtsColumnMeta.Scale = 0;
                    if ("Boolean|AllDayEvent|Attachments|CrossProjectLink|Recurrence".Contains(column.SharePointType))
                    {
                        dtsColumnMeta.DataType = DataType.DT_BOOL;
                    }
                    else if (column.SharePointType == "DateTime")
                    {
                        dtsColumnMeta.DataType = DataType.DT_DBTIMESTAMP;
                    }
                    else if ("Number|Currency".Contains(column.SharePointType))
                    {
                        // Max = 100,000,000,000.00000
                        dtsColumnMeta.DataType = DataType.DT_R8;
                    }
                    else if ("Counter|Integer".Contains(column.SharePointType))
                    {
                        dtsColumnMeta.DataType = DataType.DT_I4;
                    }
                    else if ("Guid".Contains(column.SharePointType))
                    {
                        dtsColumnMeta.DataType = DataType.DT_GUID;
                    }
                    else
                    {
                        if (column.MaxLength == -1)
                        {
                            dtsColumnMeta.DataType = DataType.DT_NTEXT;
                            dtsColumnMeta.Length = 0;
                        }
                        else
                        {
                            dtsColumnMeta.DataType = DataType.DT_WSTR;
                            dtsColumnMeta.Length = column.MaxLength;
                        }
                    }

                    IDTSCustomProperty fieldNameMeta = dtsColumnMeta.CustomPropertyCollection.New();
                    fieldNameMeta.Name = "Id";
                    fieldNameMeta.Description = "SharePoint ID";
                    fieldNameMeta.Value = column.Name;

                    // Create default output columns for all of the fields returned and link to the original columns
                    IDTSOutputColumn dtsColumn = output.OutputColumnCollection.New();
                    dtsColumn.Name = dtsColumnMeta.Name;
                    dtsColumn.Description = dtsColumnMeta.Description;
                    dtsColumn.ExternalMetadataColumnID = dtsColumnMeta.ID;

                    IDTSCustomProperty fieldName = dtsColumn.CustomPropertyCollection.New();
                    fieldName.Name = fieldNameMeta.Name;
                    fieldName.Description = fieldNameMeta.Description;
                    fieldName.Value = fieldNameMeta.Value;

                    dtsColumn.SetDataTypeProperties(
                        dtsColumnMeta.DataType, dtsColumnMeta.Length, dtsColumnMeta.Precision, dtsColumnMeta.Scale, 0);
                }
            }
            catch (ApplicationException)
            {
                // Exception happened, so clear the columns, which will invalidate this object.
                output.ExternalMetadataColumnCollection.RemoveAll();
            }

        }
        /// <summary>
        /// Lodas the column data into the dts objects from the datasource for columns
        /// </summary>
        private void LoadDataSourceInformation(IDTSOutput output, Dictionary<string, string> existingColumnData)
        {
            object sharepointUrl = ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTSITEURL].Value;
            object sharepointListName = ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTLISTNAME].Value;

            // Reset the values
            if ((sharepointUrl != null) && (sharepointListName != null))
            {
                CreateExternalMetaDataColumns(output,
                    (string)ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTSITEURL].Value,
                    (string)ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTLISTNAME].Value,
                    (string)ComponentMetaData.CustomPropertyCollection[C_SHAREPOINTLISTVIEWNAME].Value,
                    existingColumnData);
            }
        }
        /// <summary>
        /// PreExecute Phase for initialization of internal runtime structures
        /// </summary>
        public override void PreExecute()
        {
            bool fireAgain = true;

            rowsProcessed = 0;
            ComponentMetaData.FireInformation(0, this.ComponentMetaData.Name, "Pre-Execute phase is beginning.", string.Empty, 0, ref fireAgain);

            IDTSInput input = ComponentMetaData.InputCollection[0];

            inputBufferColumns = new List <InputBufferColumnInfo>(input.InputColumnCollection.Count);

            for (int i = 0; i < input.InputColumnCollection.Count; i++)
            {
                IDTSInputColumn column = input.InputColumnCollection[i];

                inputBufferColumns.Add(new InputBufferColumnInfo(BufferManager.FindColumnByLineageID(input.Buffer, column.LineageID),
                                                                 column.Name, column.ID, column.LineageID, 0, column.DataType, column.Length, column.Precision, column.Scale));
            }

            outputColumns = new List <XmlColumn>();
            IDTSOutput output = ComponentMetaData.OutputCollection[0];

            foreach (IDTSOutputColumn col in output.OutputColumnCollection)
            {
                SaveOptions saveOptions       = SaveOptions.None;
                bool        serializeDataType = false;
                bool        serializeLineage  = false;
                string      sourceID          = string.Empty;
                string      sourceName        = string.Empty;
                List <int>  cols = null;

                foreach (IDTSCustomProperty prop in col.CustomPropertyCollection)
                {
                    if (prop.Name == Resources.XmlSaveOptionPropertyName)
                    {
                        saveOptions = (SaveOptions)prop.Value;
                    }
                    else if (prop.Name == Resources.XmlSerializeDataTypeName)
                    {
                        serializeDataType = (bool)prop.Value;
                    }
                    else if (prop.Name == Resources.XmlSerializeLineageName)
                    {
                        serializeLineage = (bool)prop.Value;
                    }
                    else if (prop.Name == Resources.XmlInputColumnsPropertyname)
                    {
                        string colsStr     = prop.Value.ToString();
                        var    colLineages = InputColumns.ParseInputLineages(colsStr);

                        cols = new List <int>(colLineages.Count);

                        foreach (int lineageID in colLineages)
                        {
                            int idx = inputBufferColumns.FindIndex(ibci => ibci.LineageID == lineageID);
                            cols.Add(idx);
                        }
                    }
                    else if (prop.Name == Resources.XmlSourceIdPropertyName)
                    {
                        sourceName = prop.Value.ToString();
                    }
                    else if (prop.Name == Resources.XmlSourceNamePropertyName)
                    {
                        sourceID = prop.Value.ToString();
                    }
                }

                int index = BufferManager.FindColumnByLineageID(input.Buffer, col.LineageID);
                outputColumns.Add(new XmlColumn(index, col.Name, col.DataType, saveOptions, serializeLineage, serializeDataType, cols, sourceID, sourceName, col.Length));
            }
        }
        /// <summary>
        /// PreExecute Phase for initialization of internal runtime structures
        /// </summary>
        public override void PreExecute()
        {
            base.PreExecute();
            IDTSInput input = ComponentMetaData.InputCollection[0];

            for (int i = 0; i < input.InputColumnCollection.Count; i++)
            {
                IDTSInputColumn column = input.InputColumnCollection[i];
            }

            IDTSOutput output = ComponentMetaData.OutputCollection[0];

            rowNumberColumns = new List <RowNumberColumn>();

            //Iterate thorough OutputColumns collection and generate and prepare RowNumberColumns
            foreach (IDTSOutputColumn col in output.OutputColumnCollection)
            {
                if (col.CustomPropertyCollection.Count == 2)
                {
                    RowNumberColumn numCol = new RowNumberColumn();
                    numCol.Index    = BufferManager.FindColumnByLineageID(input.Buffer, col.LineageID);
                    numCol.DataType = col.DataType;


                    foreach (IDTSCustomProperty prop in col.CustomPropertyCollection)
                    {
                        switch (prop.Name)
                        {
                        case "IncrementBy":
                            if (col.DataType == DataType.DT_DATE || col.DataType == DataType.DT_DBDATE)
                            {
                                string pv = prop.Value.ToString();
                                char   ch = pv[pv.Length - 1];
                                switch (ch)
                                {
                                case 'd':
                                    numCol.IncrementType = IncrementByType.Day;
                                    break;

                                case 'w':
                                    numCol.IncrementType = IncrementByType.Week;
                                    break;

                                case 'm':
                                    numCol.IncrementType = IncrementByType.Month;
                                    break;

                                case 'y':
                                    numCol.IncrementType = IncrementByType.Year;
                                    break;
                                }
                                numCol.IncrementBy = int.Parse(pv.Substring(0, pv.Length - 1));
                            }
                            else
                            {
                                numCol.IncrementBy   = prop.Value;
                                numCol.IncrementType = IncrementByType.Value;
                            }
                            break;

                        case "InitialValue":
                            numCol.InitialValue = prop.Value;
                            break;

                        default:
                            break;
                        }
                    }
                    rowNumberColumns.Add(numCol);
                }
            }
        }
        /// <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>
        /// Upgrades the component from earlier versions
        /// </summary>
        /// <param name="pipelineVersion"></param>
        public override void PerformUpgrade(int pipelineVersion)
        {
            DtsPipelineComponentAttribute componentAttribute = (DtsPipelineComponentAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(DtsPipelineComponentAttribute), false);
            int currentVersion = componentAttribute.CurrentVersion;

            // Get the attributes for the SSIS Package
            int metadataVersion = ComponentMetaData.Version;

            if (currentVersion < ComponentMetaData.Version)
            {
                throw new Exception(Properties.Resources.ErrorWrongRuntimeVersion);
            }
            else if (currentVersion > ComponentMetaData.Version)
            {
                IDTSInput  input         = ComponentMetaData.InputCollection[0];
                List <int> propsToRemove = new List <int>();
                List <KeyValuePair <int, int> > colLienagesSort = new List <KeyValuePair <int, int> >(input.InputColumnCollection.Count);

                string sourceID   = string.Empty;
                string sourceName = string.Empty;
                try
                {
                    IDTSCustomProperty prop = ComponentMetaData.CustomPropertyCollection[Resources.ColumnsToXmlSourceNameProperty];
                    if (prop != null)
                    {
                        sourceName = prop.Value.ToString();
                        ComponentMetaData.CustomPropertyCollection.RemoveObjectByID(prop.ID);
                    }
                }
                catch { }

                try
                {
                    IDTSCustomProperty prop = ComponentMetaData.CustomPropertyCollection[Resources.ColumnsToXmlSourceIDProperty];
                    if (prop != null)
                    {
                        sourceID = prop.Value.ToString();
                        ComponentMetaData.CustomPropertyCollection.RemoveObjectByID(prop.ID);
                    }
                }
                catch
                { }

                foreach (IDTSInputColumn col in input.InputColumnCollection)
                {
                    int sortOrder           = int.MaxValue;
                    IDTSCustomProperty prop = null;
                    propsToRemove = new List <int>();

                    foreach (IDTSCustomProperty p in col.CustomPropertyCollection)
                    {
                        if (p.Name == Resources.InputSortOrderPropertyName)
                        {
                            sortOrder = (int)p.Value;
                            propsToRemove.Add(p.ID);
                            break;
                        }
                    }

                    colLienagesSort.Add(new KeyValuePair <int, int>(col.LineageID, sortOrder));

                    foreach (int id in propsToRemove)
                    {
                        col.CustomPropertyCollection.RemoveObjectByID(id);
                    }
                }

                colLienagesSort.Sort((a, b) => a.Value.CompareTo(b.Value));


                IDTSOutput output = ComponentMetaData.OutputCollection[0];

                foreach (IDTSOutputColumn col in output.OutputColumnCollection)
                {
                    SetPropertyType setProp = SetPropertyType.All;
                    bool            additionalPropertyExists = false;

                    bool setDataType = !(col.DataType == DataType.DT_NTEXT || (col.DataType == DataType.DT_WSTR && col.Length <= 4000));

                    foreach (IDTSCustomProperty prop in col.CustomPropertyCollection)
                    {
                        if (prop.Name == Resources.XmlSaveOptionPropertyName)
                        {
                            setProp ^= SetPropertyType.XmlSaveOptions;
                        }
                        else if (prop.Name == Resources.XmlSerializeLineageName)
                        {
                            setProp ^= SetPropertyType.XmlSerializeLineage;
                        }
                        else if (prop.Name == Resources.XmlSerializeDataTypeName)
                        {
                            setProp ^= SetPropertyType.XmlSerializeDataType;
                        }
                        else if (prop.Name == Resources.XmlInputColumnsPropertyname)
                        {
                            setProp ^= SetPropertyType.XmlInputColumns;
                        }
                        else if (prop.Name == Resources.XmlSourceIdPropertyName)
                        {
                            setProp ^= SetPropertyType.XMlSourceID;
                        }
                        else if (prop.Name == Resources.XmlSourceNamePropertyName)
                        {
                            setProp ^= SetPropertyType.XmlSourceName;
                        }
                        else
                        {
                            additionalPropertyExists = true;
                        }
                    }

                    if (setProp != SetPropertyType.None || additionalPropertyExists || setDataType)
                    {
                        SetXmlColumnProperties(col, setProp, setDataType);
                    }

                    if ((setProp & SetPropertyType.XmlInputColumns) == SetPropertyType.XmlInputColumns && colLienagesSort.Count > 0)
                    {
                        string lineages = InputColumns.BuildInputLineagesString(colLienagesSort.ConvertAll <int>(kvp => kvp.Key));
                        col.CustomPropertyCollection[Resources.XmlInputColumnsPropertyname].Value = lineages;
                    }

                    if ((setProp & SetPropertyType.XMlSourceID) == SetPropertyType.XMlSourceID)
                    {
                        col.CustomPropertyCollection[Resources.XmlSourceIdPropertyName].Value = sourceID;
                    }

                    if ((setProp & SetPropertyType.XmlSourceName) == SetPropertyType.XmlSourceName)
                    {
                        col.CustomPropertyCollection[Resources.XmlSourceNamePropertyName].Value = sourceName;
                    }
                }

                ComponentMetaData.Version = currentVersion;
            }
        }
Example #25
0
 public ConditionalSplit AddConditionalSplitItem(string outputName, string expression)
 {
     Pipe.IDTSOutput100 newOutput = base.AddSSISOutput(outputName);
     ComponentWrapper.SetOutputProperty(newOutput.ID, "FriendlyExpression", expression);
     return(this);
 }
Example #26
0
 public FormOutput(IDTSOutput output)
 {
     DTSOutput = output;
 }
        private void HookupRawDestination(MainPipe pipeline, IDTSOutputXX output)
        {
            IDTSComponentMetaDataXX rawDestComponent = pipeline.ComponentMetaDataCollection.New();
            rawDestComponent.ComponentClassID = "DTSAdapter.RawDestination";
            CManagedComponentWrapper inst = rawDestComponent.Instantiate();
            inst.ProvideComponentProperties();
            inst.SetComponentProperty("FileName", GetRawFilePathForOutput(output));

            IDTSPathXX path = pipeline.PathCollection.New();
            path.AttachPathAndPropagateNotifications(output, rawDestComponent.InputCollection[0]);
            IDTSVirtualInputXX vInput = path.EndPoint.GetVirtualInput();
            foreach (IDTSVirtualInputColumnXX vColumn in vInput.VirtualInputColumnCollection)
            {
                inst.SetUsageType(path.EndPoint.ID, vInput, vColumn.LineageID, DTSUsageType.UT_READONLY);
            }
            rawDestComponent.Name = "BIDS_Helper_Raw_Dest_" + output.ID.ToString();
        }
        private static void HookupRowCountTransform(TaskHost dataFlowTask, MainPipe pipeline, IDTSOutputXX output)
        {
            Variable variable = dataFlowTask.Variables.Add("BIDS_HELPER_ROWCOUNT_" + output.ID, false, "User", (int)0);

            IDTSComponentMetaDataXX transform = pipeline.ComponentMetaDataCollection.New();
            transform.ComponentClassID = "DTSTransform.RowCount";
            CManagedComponentWrapper inst = transform.Instantiate();
            inst.ProvideComponentProperties();
            inst.SetComponentProperty("VariableName", variable.QualifiedName);

            string sOutputName = output.Name;
            int iComponentID = output.Component.ID;

            IDTSPathXX path = pipeline.PathCollection.New();
            path.AttachPathAndPropagateNotifications(output, transform.InputCollection[0]);

            transform.Name = "BIDS_Helper_RowCount_" + path.StartPoint.ID.ToString();
        }
 private string GetRawFilePathForOutput(IDTSOutputXX output)
 {
     return this._TempDirectory + "\\BIDS_Helper_Raw_Dest_" + output.ID.ToString() + ".raw";
 }