Exemplo n.º 1
0
        //checks if output metadata matches external output metadata
        public override bool isExternalMetadataValid()
        {
            //get default output
            IDTSOutput100 output = null;

            for (int i = 0; i < ComponentMetaData.OutputCollection.Count; i++)
            {
                if (!ComponentMetaData.OutputCollection[i].IsErrorOut)
                {
                    output = ComponentMetaData.OutputCollection[i];
                }
            }

            //get default output external metadata
            IDTSExternalMetadataColumnCollection100 externalMetaData = output.ExternalMetadataColumnCollection;

            //return false if output column metadata does not match external column metadata
            foreach (IDTSOutputColumn100 col in output.OutputColumnCollection)
            {
                IDTSExternalMetadataColumn100 ecol = externalMetaData.GetObjectByID(col.ExternalMetadataColumnID);

                if (col.DataType != ecol.DataType ||
                    col.Precision != ecol.Precision ||
                    col.Length != ecol.Length ||
                    col.Scale != ecol.Scale)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        protected virtual void SafeMapInputToExternalMetadataColumn(string inputColumnName, string externalMetadataColumnName, bool unMap)
        {
            try
            {
                IDTSVirtualInput100           cvi  = _component.InputCollection[0].GetVirtualInput();
                IDTSExternalMetadataColumn100 eCol = _component.InputCollection[0].ExternalMetadataColumnCollection[externalMetadataColumnName];

                foreach (IDTSInputColumn100 inCol in _component.InputCollection[0].InputColumnCollection)
                {
                    //Unmap anything else that maps to this external metadata column)
                    if (inCol.ExternalMetadataColumnID == eCol.ID)
                    {
                        MessageEngine.Global.Trace(Severity.Debug, "{0}: {1} Unmapping Input {2}", GetType(), _component.Name, inCol.Name);
                        SetInputUsageType(cvi, cvi.VirtualInputColumnCollection[inCol.Name], DTSUsageType.UT_IGNORED, true);
                        break;
                    }
                }
                if (!unMap)
                {
                    SetInputUsageType(cvi, cvi.VirtualInputColumnCollection[inputColumnName], DTSUsageType.UT_READONLY);
                    _component.InputCollection[0].InputColumnCollection[inputColumnName].ExternalMetadataColumnID = eCol.ID;
                }
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                MessageEngine.Global.Trace(Severity.Warning, "WarningMapColumnsDoNotExist {0} {1} {2} {3}", inputColumnName, externalMetadataColumnName, _component.Name, ce.Message);
            }
        }
        public static bool DoesOutputColumnMetaDataMatchExternalColumnMetaData(IDTSOutput100 output)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            bool areAllOutputColumnsValid = true;

            if (output.ExternalMetadataColumnCollection.Count == 0)
            {
                return(false);
            }

            foreach (IDTSOutputColumn100 column in output.OutputColumnCollection)
            {
                bool Cancel = false;
                IDTSExternalMetadataColumn100 exColumn
                    = output.ExternalMetadataColumnCollection.GetObjectByID(
                          column.ExternalMetadataColumnID);

                if (!DoesColumnMetaDataMatch(column, exColumn))
                {
                    output.Component.FireError(
                        0,
                        output.Component.Name,
                        @"The output column " + column.IdentificationString + @" does not match the external metadata.",
                        @"",
                        0,
                        out Cancel);
                    areAllOutputColumnsValid = false;
                }
            }
            return(areAllOutputColumnsValid);
        }
        public static void FixOutputColumnMetaData(IDTSOutput100 output)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            if (output.ExternalMetadataColumnCollection.Count == 0)
            {
                return;
            }

            foreach (IDTSOutputColumn100 column in output.OutputColumnCollection)
            {
                IDTSExternalMetadataColumn100 exColumn
                    = output.ExternalMetadataColumnCollection.GetObjectByID(
                          column.ExternalMetadataColumnID);

                if (!DoesColumnMetaDataMatch(column, exColumn))
                {
                    column.SetDataTypeProperties(
                        exColumn.DataType,
                        exColumn.Length,
                        exColumn.Precision,
                        exColumn.Scale,
                        exColumn.CodePage);
                }
            }
        }
Exemplo n.º 5
0
        public override void PreExecute()
        {
            IDTSInput100 input = ComponentMetaData.InputCollection[0];

            foreach (IDTSInputColumn100 col in input.InputColumnCollection)
            {
                IDTSExternalMetadataColumn100 ecol = input.ExternalMetadataColumnCollection.GetObjectByID(col.ExternalMetadataColumnID);

                columnInfo ci = new columnInfo();
                ci.bufferColumnIndex     = BufferManager.FindColumnByLineageID(input.Buffer, col.LineageID);
                ci.columnName            = ecol.Name;
                ci.lineageID             = col.LineageID;
                ci.errorDisposition      = col.ErrorRowDisposition;
                ci.truncationDisposition = col.TruncationRowDisposition;
                if (ecol.Name == (string)ComponentMetaData.CustomPropertyCollection["Geometry Column"].Value)
                {
                    ci.geom = true;
                }
                else
                {
                    ci.geom = false;
                }
                this.columnInformation.Add(ci);
            }

            //set batchSize
            this.batchSize = (int)ComponentMetaData.CustomPropertyCollection["Batch Size"].Value;
        }
Exemplo n.º 6
0
        public static void CreatePath(MainPipe dataFlowTask, IDTSOutput100 fromOutput, IDTSComponentMetaData100 toComponent, CManagedComponentWrapper toInstance)
        {
            // Create the path from source to destination.
            IDTSPath100 path = dataFlowTask.PathCollection.New();

            path.AttachPathAndPropagateNotifications(fromOutput, toComponent.InputCollection[0]);

            // Get the destination's default input and virtual input.
            IDTSInput100        input  = toComponent.InputCollection[0];
            IDTSVirtualInput100 vInput = input.GetVirtualInput();

            // Iterate through the virtual input column collection.
            foreach (IDTSVirtualInputColumn100 vColumn in vInput.VirtualInputColumnCollection)
            {
                // Find external column by name
                IDTSExternalMetadataColumn100 externalColumn = null;
                foreach (IDTSExternalMetadataColumn100 column in input.ExternalMetadataColumnCollection)
                {
                    if (String.Compare(column.Name, vColumn.Name, true) == 0)
                    {
                        externalColumn = column;
                        break;
                    }
                }
                if (externalColumn != null)
                {
                    // Select column, and retain new input column
                    IDTSInputColumn100 inputColumn = toInstance.SetUsageType(input.ID, vInput, vColumn.LineageID, DTSUsageType.UT_READONLY);
                    // Map input column to external column
                    toInstance.MapInputColumn(input.ID, inputColumn.ID, externalColumn.ID);
                }
            }
        }
Exemplo n.º 7
0
        public override bool  isExternalMetadataValid()
        {
            IDTSExternalMetadataColumnCollection100 exColumns = ComponentMetaData.InputCollection[0].ExternalMetadataColumnCollection;
            Layer       OGRLayer      = this.getLayer();
            FeatureDefn OGRFeatureDef = OGRLayer.GetLayerDefn();

            // Get Geometry column name
            string geomtryColumn = (OGRLayer.GetGeometryColumn() != "") ? OGRLayer.GetGeometryColumn() : "GEOMETRY";

            //check for correct number of external metadata columns
            if (OGRFeatureDef.GetFieldCount() + 1 != exColumns.Count)
            {
                return(false);
            }

            //validate each external metadata column
            for (int i = 0; i < exColumns.Count; i++)
            {
                IDTSExternalMetadataColumn100 col = exColumns[i];

                if (col.Name == geomtryColumn)
                {
                    if (col.DataType != DataType.DT_IMAGE)
                    {
                        return(false);
                    }
                    // Check geometry column custom property against source
                    if ((string)ComponentMetaData.CustomPropertyCollection["Geometry Column"].Value != geomtryColumn)
                    {
                        return(false);
                    }
                }
                else
                {
                    //check if ogr field exists by name
                    int OGRFieldIndex = OGRFeatureDef.GetFieldIndex(col.Name);
                    if (OGRFieldIndex == -1)
                    {
                        return(false);
                    }

                    //check if ogr column matches output column type
                    FieldDefn OGRFieldDef  = OGRFeatureDef.GetFieldDefn(OGRFieldIndex);
                    FieldType OGRFieldType = OGRFieldDef.GetFieldType();
                    if (this.OGRTypeToBufferType(OGRFieldType) != col.DataType)
                    {
                        //check for case where OFTString -> DT_NTEXT
                        if (!(OGRFieldType == FieldType.OFTString && col.DataType == DataType.DT_NTEXT))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Add external output columns for offline support
        /// </summary>
        /// <param name="output"></param>
        /// <param name="outputColumn"></param>
        private void CreateExternalMetaDataColumn(IDTSOutput100 output, IDTSOutputColumn100 outputColumn)
        {
            IDTSExternalMetadataColumn100 externalColumn = output.ExternalMetadataColumnCollection.New();

            externalColumn.Name      = outputColumn.Name;
            externalColumn.Precision = outputColumn.Precision;
            externalColumn.Length    = outputColumn.Length;
            externalColumn.DataType  = outputColumn.DataType;
            externalColumn.Scale     = outputColumn.Scale;
            outputColumn.ExternalMetadataColumnID = externalColumn.ID;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Constructs an external metadata column and adds it to the provided collection, using the column metadata from the provided output column.
        /// </summary>
        /// <param name="externalMetadataColumnCollection"></param>
        /// <param name="outputColumn"></param>
        /// <returns></returns>
        private IDTSExternalMetadataColumn100 BuildExternalMetadataColumn(IDTSExternalMetadataColumnCollection100 externalMetadataColumnCollection, IDTSOutputColumn100 outputColumn)
        {
            IDTSExternalMetadataColumn100 externalColumnToPopulate = externalMetadataColumnCollection.New();

            externalColumnToPopulate.Name      = outputColumn.Name;
            externalColumnToPopulate.Precision = outputColumn.Precision;
            externalColumnToPopulate.Length    = outputColumn.Length;
            externalColumnToPopulate.DataType  = outputColumn.DataType;
            externalColumnToPopulate.Scale     = outputColumn.Scale;
            externalColumnToPopulate.CodePage  = outputColumn.CodePage;
            return(externalColumnToPopulate);
        }
        private static bool DoesColumnMetaDataMatch(IDTSOutputColumn100 column, IDTSExternalMetadataColumn100 exCol)
        {
            if (column.DataType == exCol.DataType &&
                column.Precision == exCol.Precision &&
                column.Length == exCol.Length &&
                column.Scale == exCol.Scale)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create an external metadata column for each output. Map the two
        /// by setting the ExternalMetaDataColumnID property of the output to the external metadata column.
        /// </summary>
        /// <param name="output">The output the columns are added to.</param>
        private static void CreateExternalMetaDataColumn(IDTSExternalMetadataColumnCollection100 externalCollection, IDTSOutputColumn100 column)
        {
            // For each output column create an external meta data columns.
            IDTSExternalMetadataColumn100 eColumn = externalCollection.New();

            eColumn.Name      = column.Name;
            eColumn.DataType  = column.DataType;
            eColumn.Precision = column.Precision;
            eColumn.Length    = column.Length;
            eColumn.Scale     = column.Scale;

            column.ExternalMetadataColumnID = eColumn.ID;
        }
Exemplo n.º 12
0
        public static string GetTooltipString(object dataflowColumn)
        {
            if (dataflowColumn is IDTSVirtualInputColumn100)
            {
                IDTSVirtualInputColumn100 column = dataflowColumn as IDTSVirtualInputColumn100;
                return(FormatTooltipText(
                           column.Name,
                           column.DataType.ToString(),
                           column.Length.ToString(CultureInfo.CurrentCulture), // Changed from CurrentUICulture
                           column.Scale.ToString(CultureInfo.CurrentCulture),
                           column.Precision.ToString(CultureInfo.CurrentCulture),
                           column.CodePage.ToString(CultureInfo.CurrentCulture),
                           column.SourceComponent));
            }
            else if (dataflowColumn is IDTSInputColumn100)
            {
                IDTSInputColumn100 column = dataflowColumn as IDTSInputColumn100;
                return(FormatTooltipText(
                           column.Name,
                           column.DataType.ToString(),
                           column.Length.ToString(CultureInfo.CurrentCulture),
                           column.Scale.ToString(CultureInfo.CurrentCulture),
                           column.Precision.ToString(CultureInfo.CurrentCulture),
                           column.CodePage.ToString(CultureInfo.CurrentCulture)));
            }
            else if (dataflowColumn is IDTSOutputColumn100)
            {
                IDTSOutputColumn100 column = dataflowColumn as IDTSOutputColumn100;
                return(FormatTooltipText(
                           column.Name,
                           column.DataType.ToString(),
                           column.Length.ToString(CultureInfo.CurrentCulture),
                           column.Scale.ToString(CultureInfo.CurrentCulture),
                           column.Precision.ToString(CultureInfo.CurrentCulture),
                           column.CodePage.ToString(CultureInfo.CurrentCulture)));
            }
            else if (dataflowColumn is IDTSExternalMetadataColumn100)
            {
                IDTSExternalMetadataColumn100 column = dataflowColumn as IDTSExternalMetadataColumn100;
                return(FormatTooltipText(
                           column.Name,
                           column.DataType.ToString(),
                           column.Length.ToString(CultureInfo.CurrentCulture),
                           column.Scale.ToString(CultureInfo.CurrentCulture),
                           column.Precision.ToString(CultureInfo.CurrentCulture),
                           column.CodePage.ToString(CultureInfo.CurrentCulture)));
            }

            return(string.Empty);
        }
Exemplo n.º 13
0
        public override bool  isMetadataValid()
        {
            IDTSExternalMetadataColumnCollection100 externalMetaData = ComponentMetaData.InputCollection[0].ExternalMetadataColumnCollection;

            foreach (IDTSInputColumn100 col in ComponentMetaData.InputCollection[0].InputColumnCollection)
            {
                IDTSExternalMetadataColumn100 ecol = externalMetaData.GetObjectByID(col.ExternalMetadataColumnID);

                if (col.DataType != ecol.DataType ||
                    col.Precision > ecol.Precision ||
                    col.Length > ecol.Length ||
                    col.Scale > ecol.Scale)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 14
0
        private void createDataTable()
        {
            m_table        = new DataTable();
            m_table.Locale = CultureInfo.InvariantCulture;
            IDTSInput100 iDTSInput = ComponentMetaData.InputCollection[0];
            IDTSExternalMetadataColumnCollection100 iDTSExtCols =
                iDTSInput.ExternalMetadataColumnCollection;
            IDTSInputColumnCollection100 iDTSInpCols =
                iDTSInput.InputColumnCollection;
            int cInpCols = iDTSInpCols.Count;

            m_tableCols = new DataColumn[cInpCols];
            IDTSExternalMetadataColumn100[] mappedExtCols =
                new IDTSExternalMetadataColumn100[cInpCols];
            m_bufferIdxs = new int[cInpCols];
            for (int iCol = 0; iCol < cInpCols; iCol++)
            {
                IDTSInputColumn100 iDTSInpCol = iDTSInpCols[iCol];
                int      metaID   = iDTSInpCol.MappedColumnID;
                DataType dataType = iDTSInpCol.DataType;
                Type     type;
                bool     isLong = false;
                dataType = ConvertBufferDataTypeToFitManaged(dataType,
                                                             ref isLong);
                type = BufferTypeToDataRecordType(dataType);
                m_tableCols[iCol] = new DataColumn(iDTSInpCol.Name, type);
                int lineageID = iDTSInpCol.LineageID;
                try
                {
                    m_bufferIdxs[iCol] = BufferManager.FindColumnByLineageID(
                        iDTSInput.Buffer, lineageID);
                }
                catch (Exception)
                {
                    bool bCancel;
                    //ErrorSupport.FireErrorWithArgs(HResults.DTS_E_ADODESTNOLINEAGEID,
                    //    out bCancel, lineageID, iDTSInpCol.Name);
                    //throw new PipelineComponentHResultException(HResults.
                    //    DTS_E_ADODESTNOLINEAGEID);
                }
            }

            m_table.Columns.AddRange(m_tableCols);
        }
Exemplo n.º 15
0
        private void CreateColumns()
        {
            IDTSOutput100 output = ComponentMetaData.OutputCollection[0];

            output.OutputColumnCollection.RemoveAll();
            output.ExternalMetadataColumnCollection.RemoveAll();

            IDTSOutputColumn100           column1   = output.OutputColumnCollection.New();
            IDTSExternalMetadataColumn100 exColumn1 = output.ExternalMetadataColumnCollection.New();

            IDTSOutputColumn100           column2   = output.OutputColumnCollection.New();
            IDTSExternalMetadataColumn100 exColumn2 = output.ExternalMetadataColumnCollection.New();

            column1.Name = "MessageContents";
            column1.SetDataTypeProperties(DataType.DT_WSTR, 4000, 0, 0, 0);

            column2.Name = "RoutingKey";
            column2.SetDataTypeProperties(DataType.DT_WSTR, 100, 0, 0, 0);
        }
        /// <summary>
        /// Getting tooltip text to be displayed for the given data flow column.
        /// </summary>
        /// <param name="dataFlowColumn"></param>
        /// <returns></returns>
        static public string GetTooltipString(object dataFlowColumn)
        {
            Debug.Assert(dataFlowColumn != null, "Tag is NULL");

            if (dataFlowColumn is IDTSVirtualInputColumn100)
            {
                IDTSVirtualInputColumn100 column = dataFlowColumn as IDTSVirtualInputColumn100;
                return(FormatTooltipText(column.Name, column.DataType.ToString(),
                                         column.Length.ToString(CultureInfo.CurrentUICulture),
                                         column.Scale.ToString(CultureInfo.CurrentUICulture),
                                         column.Precision.ToString(CultureInfo.CurrentUICulture),
                                         column.CodePage.ToString(CultureInfo.CurrentUICulture),
                                         column.SourceComponent));
            }
            else if (dataFlowColumn is IDTSInputColumn100)
            {
                IDTSInputColumn100 column = dataFlowColumn as IDTSInputColumn100;
                return(FormatTooltipText(column.Name, column.DataType.ToString(),
                                         column.Length.ToString(CultureInfo.CurrentUICulture),
                                         column.Scale.ToString(CultureInfo.CurrentUICulture),
                                         column.Precision.ToString(CultureInfo.CurrentUICulture),
                                         column.CodePage.ToString(CultureInfo.CurrentUICulture)));
            }
            else if (dataFlowColumn is IDTSOutputColumn100)
            {
                IDTSOutputColumn100 column = dataFlowColumn as IDTSOutputColumn100;
                return(FormatTooltipText(column.Name, column.DataType.ToString(), column.Length.ToString(CultureInfo.CurrentUICulture),
                                         column.Scale.ToString(CultureInfo.CurrentUICulture),
                                         column.Precision.ToString(CultureInfo.CurrentUICulture),
                                         column.CodePage.ToString(CultureInfo.CurrentUICulture)));
            }
            else if (dataFlowColumn is IDTSExternalMetadataColumn100)
            {
                IDTSExternalMetadataColumn100 column = dataFlowColumn as IDTSExternalMetadataColumn100;
                return(FormatTooltipText(column.Name, column.DataType.ToString(),
                                         column.Length.ToString(CultureInfo.CurrentUICulture),
                                         column.Scale.ToString(CultureInfo.CurrentUICulture),
                                         column.Precision.ToString(CultureInfo.CurrentUICulture),
                                         column.CodePage.ToString(CultureInfo.CurrentUICulture)));
            }

            return(string.Empty);
        }
Exemplo n.º 17
0
        public void MapColumns(IDTSComponentMetaData100 DestinationTask
                               , CManagedComponentWrapper InstanceDestination
                               , DTSUsageType dtsUsageType, string ErrorDetail)
        {
            #region map the columns
            IDTSInput100        input  = DestinationTask.InputCollection[0];
            IDTSVirtualInput100 vInput = input.GetVirtualInput();
            IDTSInputColumn100  vCol   = null;
            string columnName          = string.Empty;
            try
            {
                if (dtsUsageType == DTSUsageType.UT_READONLY)
                {
                    foreach (IDTSVirtualInputColumn100 vColumn in vInput.VirtualInputColumnCollection)
                    {
                        InstanceDestination.SetUsageType(input.ID, vInput, vColumn.LineageID, dtsUsageType);
                    }

                    foreach (IDTSInputColumn100 col in input.InputColumnCollection)
                    {
                        columnName = col.Name;
                        IDTSExternalMetadataColumn100 exCol = input.ExternalMetadataColumnCollection[col.Name];
                        InstanceDestination.MapInputColumn(input.ID, col.ID, exCol.ID);
                    }
                }
                else
                {
                    foreach (IDTSVirtualInputColumn100 vColumn in vInput.VirtualInputColumnCollection)
                    {
                        vCol       = InstanceDestination.SetUsageType(input.ID, vInput, vColumn.LineageID, dtsUsageType);
                        columnName = vCol.Name;
                        IDTSExternalMetadataColumn100 exCol = input.ExternalMetadataColumnCollection[vColumn.Name];
                        InstanceDestination.MapInputColumn(input.ID, vCol.ID, exCol.ID);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Table Mapping failed for source to destination for the column '" + columnName + "'. " + ErrorDetail);
            }
            #endregion
        }
        private void AddConvertComponent(Hashtable colConvertTable, Hashtable colConnectTable)
        {
            convertComp = pipeline.ComponentMetaDataCollection.New();
            convertComp.ComponentClassID         = DATACONVERT_GUID;
            convertComp.Name                     = "Data Conversion";
            convertComp.ValidateExternalMetadata = true;
            convertDesignTimeComp                = convertComp.Instantiate();
            convertDesignTimeComp.ProvideComponentProperties();
            IDTSInput100  cvtInput  = convertComp.InputCollection[0];
            IDTSOutput100 cvtOutput = convertComp.OutputCollection[0];
            IDTSInputColumnCollection100 cvtInputCols = cvtInput.InputColumnCollection;
            IDTSOutput100 srcOutput = srcComp.OutputCollection[0];

            pipeline.PathCollection.New().AttachPathAndPropagateNotifications(srcOutput, cvtInput);
            IDTSVirtualInput100 cvtVirInput = cvtInput.GetVirtualInput();

            int i = 0;

            foreach (object key in colConvertTable.Keys)
            {
                int srcColID = (int)key;
                cvtVirInput.SetUsageType(srcColID, DTSUsageType.UT_READONLY);
                IDTSInputColumn100 cvtInputCol = cvtInputCols.GetInputColumnByLineageID(srcColID);
                if (cvtInputCol != null)
                {
                    IDTSOutputColumn100           cvtOutputCol = convertDesignTimeComp.InsertOutputColumnAt(cvtOutput.ID, i++, "Convert_" + cvtInputCol.Name, "");
                    IDTSExternalMetadataColumn100 destCol      = (IDTSExternalMetadataColumn100)colConvertTable[key];
                    convertDesignTimeComp.SetOutputColumnDataTypeProperties(cvtOutput.ID,
                                                                            cvtOutputCol.ID, destCol.DataType, destCol.Length, destCol.Precision, destCol.Scale, destCol.CodePage);
                    // map output column and input column
                    convertDesignTimeComp.SetOutputColumnProperty(cvtOutput.ID,
                                                                  cvtOutputCol.ID, "SourceInputColumnLineageID", srcColID);
                    // add match table entry.
                    colConnectTable.Add(cvtOutputCol.ID, destCol);
                }
            }
        }
Exemplo n.º 19
0
        public void BuildExternalMetadataColumnTest()
        {
            PrivateObject p = new PrivateObject(typeof(MongoDataSource.MongoDataSource));

            IDTSOutputColumn100 outputColumn = Mock.Create <IDTSOutputColumn100>(Constructor.Mocked);

            String   expectedName      = "name";
            int      expectedPrecision = 1;
            int      expectedLength    = 2;
            int      expectedScale     = 3;
            DataType expectedDataType  = DataType.DT_TEXT;
            int      expectedCodePage  = 4;

            Mock.Arrange(() => outputColumn.Name).Returns(expectedName);
            Mock.Arrange(() => outputColumn.Precision).Returns(expectedPrecision);
            Mock.Arrange(() => outputColumn.Length).Returns(expectedLength);
            Mock.Arrange(() => outputColumn.DataType).Returns(expectedDataType);
            Mock.Arrange(() => outputColumn.Scale).Returns(expectedScale);
            Mock.Arrange(() => outputColumn.CodePage).Returns(expectedCodePage);

            IDTSExternalMetadataColumnCollection100 outputCollection = Mock.Create <IDTSExternalMetadataColumnCollection100>(Constructor.Mocked);
            IDTSExternalMetadataColumn100           expected         = Mock.Create <IDTSExternalMetadataColumn100>(Constructor.Mocked);

            Mock.Arrange(() => outputCollection.New()).Returns(expected);

            Mock.ArrangeSet(() => expected.Name      = Arg.Matches <String>(x => x == expectedName)).OccursOnce();
            Mock.ArrangeSet(() => expected.Precision = Arg.Matches <int>(x => x == expectedPrecision)).OccursOnce();
            Mock.ArrangeSet(() => expected.Length    = Arg.Matches <int>(x => x == expectedLength)).OccursOnce();
            Mock.ArrangeSet(() => expected.DataType  = Arg.Matches <DataType>(x => x == expectedDataType)).OccursOnce();
            Mock.ArrangeSet(() => expected.Scale     = Arg.Matches <int>(x => x == expectedScale)).OccursOnce();
            Mock.ArrangeSet(() => expected.CodePage  = Arg.Matches <int>(x => x == expectedCodePage)).OccursOnce();

            IDTSExternalMetadataColumn100 actual = (IDTSExternalMetadataColumn100)p.Invoke("BuildExternalMetadataColumn", new object[] { outputCollection, outputColumn });

            Mock.Assert(expected);
        }
        public static void FixExternalMetaDataColumns(IDTSOutput100 output)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            IDTSExternalMetadataColumnCollection100 externalMetaData
                = output.ExternalMetadataColumnCollection;

            externalMetaData.RemoveAll();

            foreach (IDTSOutputColumn100 column in output.OutputColumnCollection)
            {
                IDTSExternalMetadataColumn100 exColumn = externalMetaData.New();
                exColumn.Name      = column.Name;
                exColumn.DataType  = column.DataType;
                exColumn.Precision = column.Precision;
                exColumn.Scale     = column.Scale;
                exColumn.Length    = column.Length;

                column.ExternalMetadataColumnID = exColumn.ID;
            }
        }
Exemplo n.º 21
0
 public InputColumnMapping(IDTSInputColumn100 inputColumn, IDTSExternalMetadataColumn100 outputColumn)
 {
     InputColumn = inputColumn;
     OutputColumn = outputColumn;
 }
Exemplo n.º 22
0
        protected void ProcessMappings()
        {
            IDTSVirtualInput100 cvi = Component.InputCollection[0].GetVirtualInput();

            var virtualInputDictionary = new Dictionary <string, IDTSVirtualInputColumn100>();

            foreach (IDTSVirtualInputColumn100 vc in cvi.VirtualInputColumnCollection)
            {
                virtualInputDictionary["@" + vc.Name.ToUpperInvariant()] = vc;
            }

            // Automatically map columns
            foreach (IDTSExternalMetadataColumn100 extCol in Component.InputCollection[0].ExternalMetadataColumnCollection)
            {
                if (virtualInputDictionary.ContainsKey(extCol.Name.ToUpperInvariant()))
                {
                    IDTSVirtualInputColumn100 vc = virtualInputDictionary[extCol.Name.ToUpperInvariant()];
                    Instance.SetUsageType(Component.InputCollection[0].ID, cvi, vc.LineageID, DTSUsageType.UT_READONLY);
                    Component.InputCollection[0].InputColumnCollection[vc.Name].ExternalMetadataColumnID = extCol.ID;
                }
            }

            // Map any overrides
            foreach (AstDataflowColumnMappingNode mapping in _astOleDBCommandNode.Query.Mappings)
            {
                if (String.IsNullOrEmpty(mapping.TargetName))
                {
                    SetInputColumnUsage(0, mapping.SourceName, DTSUsageType.UT_IGNORED, true);
                }
                else
                {
                    IDTSExternalMetadataColumn100 ecol = TransformationUtility.FindExternalColumnByName(mapping.TargetName, Component.InputCollection[0].ExternalMetadataColumnCollection, true);

                    // Unmap anything else that maps to this external metadata column)
                    foreach (IDTSInputColumn100 inputColumn in Component.InputCollection[0].InputColumnCollection)
                    {
                        if (inputColumn.ExternalMetadataColumnID == ecol.ID)
                        {
                            MessageEngine.Trace(_astOleDBCommandNode, Severity.Debug, "V0401", "{0}: {1} Unmapping Input {2}", GetType(), Component.Name, inputColumn.Name);
                            SetInputColumnUsage(0, inputColumn.Name, DTSUsageType.UT_IGNORED, true);
                            break;
                        }
                    }

                    IDTSInputColumn100 icol = SetInputColumnUsage(0, mapping.SourceName, DTSUsageType.UT_READONLY, false);
                    if (ecol != null)
                    {
                        if (icol != null)
                        {
                            icol.ExternalMetadataColumnID = ecol.ID;
                        }
                        else
                        {
                            MessageEngine.Trace(_astOleDBCommandNode, Severity.Error, "V0105", "Could not find source column {0}", mapping.SourceName);
                        }
                    }
                    else
                    {
                        MessageEngine.Trace(_astOleDBCommandNode, Severity.Error, "V0106", "Could not find destination column {0}", mapping.TargetName);
                    }
                }
            }
        }
        /// <summary>
        /// Creates an ADO.NET DataTable object for storing a batch of rows from the source, in memory,
        /// before it is staged in the database. The DataTable object is stored in m_table.
        /// </summary>
        private void createDataTable()
        {

            // compose DataTable column for each input column,
            // and find its DTS buffer column.
            m_table = new DataTable();
            m_table.Locale = CultureInfo.InvariantCulture;

            IDTSInput100 iDTSInput = ComponentMetaData.InputCollection[0];

            IDTSExternalMetadataColumnCollection100 iDTSExtCols =
                iDTSInput.ExternalMetadataColumnCollection;
            IDTSInputColumnCollection100 iDTSInpCols =
                iDTSInput.InputColumnCollection;
            int cInpCols = iDTSInpCols.Count;
            m_tableCols = new DataColumn[cInpCols];
            IDTSExternalMetadataColumn100[] mappedExtCols =
                new IDTSExternalMetadataColumn100[cInpCols];
            m_bufferIdxs = new int[cInpCols];
            for (int iCol = 0; iCol < cInpCols; iCol++)
            {
                IDTSInputColumn100 iDTSInpCol = iDTSInpCols[iCol];
                int metaID = iDTSInpCol.ExternalMetadataColumnID;

                // find the mapped destination column
                IDTSExternalMetadataColumn100 iDTSExtCol =
                    iDTSExtCols.FindObjectByID(metaID);
                mappedExtCols[iCol] = iDTSExtCol;

                DataType dataType = iDTSInpCol.DataType;
                Type type;


                bool isLong = false;
                dataType = ConvertBufferDataTypeToFitManaged(dataType,
                                                            ref isLong);
                type = BufferTypeToDataRecordType(dataType);


                m_tableCols[iCol] = new DataColumn(iDTSExtCol.Name, type);

                // find the corresponding buffer columnn index, this shouldnt fail
                int lineageID = iDTSInpCol.LineageID;
                try
                {
                    m_bufferIdxs[iCol] = BufferManager.FindColumnByLineageID(
                        iDTSInput.Buffer, lineageID);
                }
                catch (Exception)
                {
                    // failed to find column with lineageID
                    bool bCancel;
                    ErrorSupport.FireErrorWithArgs(HResults.DTS_E_ADODESTNOLINEAGEID,
                        out bCancel, lineageID, iDTSExtCol.Name);
                    throw new PipelineComponentHResultException(HResults.
                        DTS_E_ADODESTNOLINEAGEID);
                }

            }

            m_table.Columns.AddRange(m_tableCols);
        }
		// Users like implicit conversion, 
		// so it is allowed but some warnings can be thrown.
		private void checkTypes(IDTSInputColumn100 iDTSInpCol, 
								IDTSExternalMetadataColumn100 iDTSExtCol)
		{
			// implicit conversion allowed
			bool isLong = false;
			DataType dataTypeInp = 
				ConvertBufferDataTypeToFitManaged(iDTSInpCol.DataType, ref isLong);
			DataType dataTypeExt = iDTSExtCol.DataType;

			if ((dataTypeInp == dataTypeExt)&& (dataTypeInp == DataType.DT_WSTR 
											|| dataTypeInp == DataType.DT_BYTES))
			{
				if (iDTSInpCol.Length > iDTSExtCol.Length)
				{
					ErrorSupport.FireWarningWithArgs(
						HResults.DTS_W_POTENTIALTRUNCATIONFROMDATAINSERTION,
						iDTSInpCol.Name, iDTSInpCol.Length, iDTSExtCol.Name, 
						iDTSExtCol.Length);
				}
			}
			
			// check for numeric types including integers and floating numbers
			if (!IsCompatibleNumericTypes(dataTypeInp, dataTypeExt))
			{
				// The warning message would display mismatched SSIS numeric types
				// and inform user an alternative way 
				// to do conversion is by using our data conversion component which 
				// converts between SSIS types.
				ErrorSupport.FireWarningWithArgs(
					HResults.DTS_W_ADODESTPOTENTIALDATALOSS,
					iDTSInpCol.Name, Enum.GetName(typeof(DataType), dataTypeInp),
					iDTSExtCol.Name, Enum.GetName(typeof(DataType), dataTypeExt));
			}
		}
        private static bool DoesColumnMetaDataMatch(IDTSOutputColumn100 column, IDTSExternalMetadataColumn100 exCol)
        {
            if (column.DataType == exCol.DataType
                && column.Precision == exCol.Precision
                && column.Length == exCol.Length
                && column.Scale == exCol.Scale)
            {
                return true;
            }

            return false;
        }
        public void AddPathsAndConnectColumns(Hashtable colPairs)
        {
            IDTSOutput100 srcOutput = srcComp.OutputCollection[0];
            IDTSOutputColumnCollection100 srcOutputCols = srcOutput.OutputColumnCollection;
            IDTSInput100 destInput = destComp.InputCollection[0];
            IDTSInputColumnCollection100            destInputCols = destInput.InputColumnCollection;
            IDTSExternalMetadataColumnCollection100 destExtCols   = destInput.ExternalMetadataColumnCollection;

            Hashtable destColtable = new Hashtable(destExtCols.Count);

            foreach (IDTSExternalMetadataColumn100 extCol in destExtCols)
            {
                destColtable.Add(extCol.Name, extCol);
            }

            bool useMatch = (colPairs != null && colPairs.Count > 0);
            // colConvertTable stores a pair of columns which need a type conversion
            // colConnectTable stores a pair of columns which dont need a type conversion and can be connected directly.
            Hashtable colConvertTable = new Hashtable(srcOutputCols.Count);
            Hashtable colConnectTable = new Hashtable(srcOutputCols.Count);

            foreach (IDTSOutputColumn100 outputCol in srcOutputCols)
            {
                // Get the column name to look for in the destination.
                // Match column by name if match table is not used.
                String colNameToLookfor = String.Empty;
                if (useMatch)
                {
                    colNameToLookfor = (String)colPairs[outputCol.Name];
                }
                else
                {
                    colNameToLookfor = outputCol.Name;
                }

                IDTSExternalMetadataColumn100 extCol = (String.IsNullOrEmpty(colNameToLookfor)) ? null : (IDTSExternalMetadataColumn100)destColtable[colNameToLookfor];
                // Does the destination column exist?
                if (extCol != null)
                {
                    // Found destination column, but is data type conversion needed?
                    if (NeedConvert(outputCol.DataType, extCol.DataType))
                    {
                        colConvertTable.Add(outputCol.ID, extCol);
                    }
                    else
                    {
                        colConnectTable.Add(outputCol.ID, extCol);
                    }
                }
            }
            if (colConvertTable.Count > 0)
            {
                // add convert component
                AddConvertComponent(colConvertTable, colConnectTable);
                pipeline.PathCollection.New().AttachPathAndPropagateNotifications(convertComp.OutputCollection[0], destInput);
            }
            else
            {
                // Convert transform not needed. Connect src and destination directly.
                pipeline.PathCollection.New().AttachPathAndPropagateNotifications(srcOutput, destInput);
            }

            IDTSVirtualInput100 destVirInput = destInput.GetVirtualInput();

            foreach (object key in colConnectTable.Keys)
            {
                int colID = (int)key;
                IDTSExternalMetadataColumn100 extCol = (IDTSExternalMetadataColumn100)colConnectTable[key];
                // Create an input column from an output col of previous component.
                destVirInput.SetUsageType(colID, DTSUsageType.UT_READONLY);
                IDTSInputColumn100 inputCol = destInputCols.GetInputColumnByLineageID(colID);
                if (inputCol != null)
                {
                    // map the input column with an external metadata column
                    destDesignTimeComp.MapInputColumn(destInput.ID, inputCol.ID, extCol.ID);
                }
            }
        }
Exemplo n.º 27
0
        public override void ReinitializeMetaData()
        {
            base.ReinitializeMetaData();

            //get default output
            IDTSOutput100 defaultOutput = null;

            this.GetErrorOutputInfo(ref errorOutputID, ref errorOutputIndex);
            foreach (IDTSOutput100 output in ComponentMetaData.OutputCollection)
            {
                if (output.ID != errorOutputID)
                {
                    defaultOutput = output;
                }
            }

            if (this.isConnected)
            {
                defaultOutput.OutputColumnCollection.RemoveAll();
                defaultOutput.ExternalMetadataColumnCollection.RemoveAll();

                //get ogrlayer and layer definition
                Layer OGRLayer;
                bool  isSQLLayer = (!(ComponentMetaData.CustomPropertyCollection["SQL Statement"].Value == null || ComponentMetaData.CustomPropertyCollection["SQL Statement"].Value.ToString() == string.Empty));
                if (isSQLLayer)
                {
                    OGRLayer = getSQLLayer();
                }
                else
                {
                    OGRLayer = getLayer();
                }
                FeatureDefn OGRFeatureDef = OGRLayer.GetLayerDefn();

                //for each field in ogrlayer add output column and external metadata
                int i = 0;
                while (i < OGRFeatureDef.GetFieldCount())
                {
                    //map OGR field type to SSIS data type
                    FieldDefn OGRFieldDef    = OGRFeatureDef.GetFieldDefn(i);
                    DataType  BufferDataType = this.OGRTypeToBufferType(OGRFieldDef.GetFieldType());
                    int       length         = 0;
                    int       precision      = OGRFieldDef.GetWidth();
                    int       scale          = OGRFieldDef.GetPrecision();
                    int       codepage       = 1252;

                    switch (BufferDataType)
                    {
                    case DataType.DT_WSTR:
                        length    = precision;
                        codepage  = 0;
                        precision = 0;
                        scale     = 0;
                        //check for length == 0
                        if (length == 0)
                        {
                            //BufferDataType = DataType.DT_NTEXT;
                            length = 4000;
                        }
                        break;

                    default:
                        length    = 0;
                        precision = 0;
                        codepage  = 0;
                        scale     = 0;
                        break;
                    }

                    //create column metadata
                    IDTSOutputColumn100 col = defaultOutput.OutputColumnCollection.New();
                    col.Name = OGRFieldDef.GetName();
                    col.ErrorRowDisposition      = DTSRowDisposition.RD_FailComponent;
                    col.TruncationRowDisposition = DTSRowDisposition.RD_FailComponent;
                    col.SetDataTypeProperties(BufferDataType, length, precision, scale, codepage);

                    //create external metadata
                    IDTSExternalMetadataColumn100 ecol = defaultOutput.ExternalMetadataColumnCollection.New();
                    ecol.Name      = col.Name;
                    ecol.DataType  = col.DataType;
                    ecol.Precision = col.Precision;
                    ecol.Length    = col.Length;
                    ecol.Scale     = col.Scale;
                    ecol.CodePage  = col.CodePage;

                    col.ExternalMetadataColumnID = ecol.ID;

                    i++;
                }

                //get geometry column
                string geomtryColumn = (OGRLayer.GetGeometryColumn() != "") ? OGRLayer.GetGeometryColumn() : "GEOMETRY";

                //add geom output column
                IDTSOutputColumn100 geomCol = defaultOutput.OutputColumnCollection.New();
                geomCol.Name = geomtryColumn;
                geomCol.ErrorRowDisposition      = DTSRowDisposition.RD_FailComponent;
                geomCol.TruncationRowDisposition = DTSRowDisposition.RD_FailComponent;
                geomCol.SetDataTypeProperties(DataType.DT_IMAGE, 0, 0, 0, 0);

                //add geom external metadata
                IDTSExternalMetadataColumn100 egeomCol = defaultOutput.ExternalMetadataColumnCollection.New();
                egeomCol.Name      = geomCol.Name;
                egeomCol.DataType  = geomCol.DataType;
                egeomCol.Precision = geomCol.Precision;
                egeomCol.Length    = geomCol.Length;
                egeomCol.Scale     = geomCol.Scale;
                egeomCol.CodePage  = geomCol.CodePage;

                //map column metadata to external column metadata
                geomCol.ExternalMetadataColumnID = egeomCol.ID;

                //set geometry column custom property
                ComponentMetaData.CustomPropertyCollection["Geometry Column"].Value = geomtryColumn;

                if (isSQLLayer)
                {
                    this.OGRDataSource.ReleaseResultSet(OGRLayer);
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// For the provided collection, will attempt to determine the name and type of each column in the collection.
        /// Adds the columns to both the default and error outputs.
        /// </summary>
        /// <param name="collectionName">The name of the mongo db collection</param>
        private void CreateColumnsFromMongoDb(string collectionName)
        {
            if (database == null)
            {
                AcquireConnections(null);
            }

            MongoCollection <BsonDocument> collection = database.GetCollection(collectionName);

            if (collection.Count() == 0)
            {
                throw new Exception(collectionName + " collection has no records");
            }

            // Remove the existing columns from the output in order to prevent us from adding duplicate columns
            foreach (IDTSOutput100 output in ComponentMetaData.OutputCollection)
            {
                // We can't simply call RemoveAll on the error output column collection, as there
                //  are two columns (ErrorColumn and ErrorCode) that we cannot remove as it throws an exception if we try
                if (output.IsErrorOut)
                {
                    List <IDTSOutputColumn100> columns = new List <IDTSOutputColumn100>();
                    for (int i = 0; i < output.OutputColumnCollection.Count; i++)
                    {
                        columns.Add(output.OutputColumnCollection[i]);
                    }

                    string[]          errorColumns      = new string[] { "ErrorColumn", "ErrorCode" };
                    IEnumerable <int> columnIdsToRemove = columns.Where(column => !errorColumns.Contains(column.Name)).Select(column => column.ID);
                    foreach (int columnIdToRemove in columnIdsToRemove)
                    {
                        output.OutputColumnCollection.RemoveObjectByID(columnIdToRemove);
                    }
                }
                else
                {
                    output.OutputColumnCollection.RemoveAll();
                    output.ExternalMetadataColumnCollection.RemoveAll();
                }
            }

            int sampleSize   = ComponentMetaData.CustomPropertyCollection[SAMPLE_SIZE_PROP_NAME].Value;
            int sampleOffset = ComponentMetaData.CustomPropertyCollection[SAMPLE_OFFSET_PROP_NAME].Value;

            // Get a sample of documents to increase the likelihood that all possible columns are found.
            // Offsetting the sample allows the user to move the sample window.
            var documents = collection
                            .FindAll()
                            .SetSkip(sampleOffset)
                            .SetLimit(sampleSize);

            // Collect the distinct column names
            var elements = documents.SelectMany(document => document.Select(element => element.Name)).Distinct();

            // For each data column, create an output column and an external metadata column.
            foreach (var element in elements)
            {
                // Try to find a document that has a [non null] value for the particular column.
                BsonDocument documentWithNonNullElementValue = collection.FindOne(Query.NE(element, BsonNull.Value));

                // If the column is not populated in any document of the collection, don't output the column.
                // Without a value, we can't determine the data type of the column.
                if (documentWithNonNullElementValue == null)
                {
                    continue;
                }

                BsonElement bsonElement = documentWithNonNullElementValue.GetElement(element);

                foreach (IDTSOutput100 output in ComponentMetaData.OutputCollection)
                {
                    IDTSOutputColumn100           outColumn      = BuildOutputColumn(output, bsonElement);
                    IDTSExternalMetadataColumn100 externalColumn = BuildExternalMetadataColumn(output.ExternalMetadataColumnCollection, outColumn);

                    // Map the external column to the output column.
                    outColumn.ExternalMetadataColumnID = externalColumn.ID;
                }
            }
        }
Exemplo n.º 29
0
 internal BipsProxyIDTSExternalMetadataColumn100(IDTSExternalMetadataColumn100 innerObject)
 {
     _innerObject = innerObject;
 }
 public DataFlowMetadataColumnNodeFactory(IDTSExternalMetadataColumn100 input)
 {
     _input = input;
 }
        public IDTSComponentMetaData100 AddComp_OleDBCommand(string componentName,
                                                             string conManName,
                                                             IDTSOutput100 outCols,
                                                             string sqlCmd,
                                                             Dictionary <string, string> paramMapping
                                                             )
        {
            //
            //  --------------------------------------------------------------------------------------------------------

            //  Create

            IDTSComponentMetaData100 Comp = dmp.ComponentMetaDataCollection.New();

            Comp.ComponentClassID = "Microsoft.OLEDBCommand";

            //  Instantiate

            CManagedComponentWrapper Inst = Comp.Instantiate();

            Inst.ProvideComponentProperties();

            Comp.Name        = componentName;
            Comp.Description = "bloczek OLEDBSource";

            //  Connect

            IDTSPath100 pth = dmp.PathCollection.New();

            pth.AttachPathAndPropagateNotifications(outCols, Comp.InputCollection[0]);

            //  GetConnectionManager

            ConnectionManager cm = prj.ConnectionManagerItems[conManName + ".conmgr"].ConnectionManager;

            //  Parametrize #1

            Comp.RuntimeConnectionCollection[0].ConnectionManager   = DtsConvert.GetExtendedInterface(cm);
            Comp.RuntimeConnectionCollection[0].ConnectionManagerID = cm.ID;


            Inst.SetComponentProperty("SqlCommand", sqlCmd);

            Inst.AcquireConnections(null);  //  Establishes a connection to a connection manager
            Inst.ReinitializeMetaData();    //  Called to allow the component to repair problems with the IDTSComponentMetaData100 object that were identified by the component during the Validate() method.
            Inst.ReleaseConnections();      //  Frees the connections established by the component during AcquireConnections(Object).

            //  Parametrize #2

            IDTSInput100        input  = Comp.InputCollection[0];
            IDTSVirtualInput100 vInput = input.GetVirtualInput();

            IDTSVirtualInputColumnCollection100 sourceColumns = vInput.VirtualInputColumnCollection;

            foreach (KeyValuePair <string, string> kvp in paramMapping)
            {
                IDTSVirtualInputColumn100 vColumn = vInput.VirtualInputColumnCollection[kvp.Value];
                Inst.SetUsageType(input.ID, vInput, vColumn.LineageID, DTSUsageType.UT_READONLY);

                IDTSExternalMetadataColumn100 exColumn = Comp.InputCollection[0].ExternalMetadataColumnCollection[kvp.Key];
                IDTSInputColumn100            inColumn = Comp.InputCollection[0].InputColumnCollection[kvp.Value];
                Inst.MapInputColumn(Comp.InputCollection[0].ID, inColumn.ID, exColumn.ID);
            }

            return(Comp);
        }
Exemplo n.º 32
0
 private void PopulateExternalMetadataColumn(IDTSExternalMetadataColumn100 externalColumnToPopulate, IDTSOutputColumn100 outputColumn)
 {
     externalColumnToPopulate.Name = outputColumn.Name;
     externalColumnToPopulate.Precision = outputColumn.Precision;
     externalColumnToPopulate.Length = outputColumn.Length;
     externalColumnToPopulate.DataType = outputColumn.DataType;
     externalColumnToPopulate.Scale = outputColumn.Scale;
 }
Exemplo n.º 33
0
 internal ISExternalMetadataColumn(IDTSExternalMetadataColumn100 externalMetadataColumn)
 {
     ExternalMetadataColumn = externalMetadataColumn;
 }
Exemplo n.º 34
0
 private void build()
 {
     #region Package Related
     // Package related
     Package package = new Package();
     Executable e = package.Executables.Add("STOCK:PipelineTask");
     TaskHost thMainPipe = e as TaskHost;
     MainPipe dataFlowTask = thMainPipe.InnerObject as MainPipe;
     thMainPipe.Name = "MyDFT";
     thMainPipe.DelayValidation = true;
     #endregion
     #region Add Connection Manager
     // Add Connection Manager
     ConnectionManager cm = package.Connections.Add("OLEDB");
     cm.Name = "OLEDB ConnectionManager";
     cm.ConnectionString = "Data Source=(local);" +
       "Initial Catalog=AdventureWorks;Provider=SQLOLEDB.1;" +
       "Integrated Security=SSPI;";
     #endregion
     #region Add a OleDB Source and set up basic properties
     // Add an OLE DB source to the data flow.  
     IDTSComponentMetaData100 component = dataFlowTask.ComponentMetaDataCollection.New();
     component.Name = "OLEDBSource";
     component.ComponentClassID = "Microsoft.OLEDBSource"; // check for the exact component class ID on your machine
     // Get the design time instance of the component.  
     CManagedComponentWrapper instance = component.Instantiate();
     // Initialize the component  
     instance.ProvideComponentProperties();
     // Specify the connection manager.  
     if (component.RuntimeConnectionCollection.Count > 0)
     {
         component.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(package.Connections[0]);
         component.RuntimeConnectionCollection[0].ConnectionManagerID = package.Connections[0].ID;
     }
     // Set the custom properties.  
     instance.SetComponentProperty("AccessMode", 2);
     instance.SetComponentProperty("SqlCommand", "Select * from Production.Product");
     #endregion
     #region Core example showcasing use of IDTSExternalMetadataColumn when external data source is not available.
     // Typically here we call acquireconnection, reinitmetadata etc to get the metadata from a data source that exists.
     // Instead we will populate the metadata ourselves
     #region Get External Columns Metadata
     // Get the collection of external columns
     List<Column> externalColumns = new List<Column>();
     // Hard Coding Here. But grab them from your metadata source programmatically.
     Column columnA = new Column("col_a", "DT_STR", 24, 0, 0, 1252);
     Column columnB = new Column("col_b", "DT_STR", 36, 0, 0, 1252);
     Column columnC = new Column("col_c", "DT_STR", 48, 0, 0, 1252);
     externalColumns.Add(columnA);
     externalColumns.Add(columnB);
     externalColumns.Add(columnC);
     #endregion
     #region Add External Columns to our required IDTSOutput100
     // Grab the appropriate output as needed. We will be adding ExternalColumns to this Output
     IDTSOutput100 output = component.OutputCollection[0];
     // Add each external column to the above IDTSOutPut
     foreach (Column extCol in externalColumns)
     {
         IDTSExternalMetadataColumn100 col = output.ExternalMetadataColumnCollection.New();
         col.Name = extCol.Name;
         col.Scale = extCol.Scale;
         col.Precision = extCol.Precision;
         col.Length = extCol.Length;
         col.CodePage = extCol.CodePage;
         col.DataType = (Wrapper.DataType)Enum.Parse(typeof(Wrapper.DataType), extCol.SSISDataType);
     }
     #endregion
     #region Create OutputColumn if it does not exist/or grab the output column if it Exists. Then associate it to the External Column
     // Now associate the External Column to an Output Column.
     // Here, we will simply associate the external column to an output column if the name matches (because of our use case)
     foreach (IDTSExternalMetadataColumn100 extCol in output.ExternalMetadataColumnCollection)
     {
         bool outputColExists = false;
         // Set DataTypes and Associate with external column if output col exists
         foreach (IDTSOutputColumn100 outputCol in output.OutputColumnCollection)
         {
             if (outputCol.Name == extCol.Name) // is map based on name
             {
                 // Set the data type properties
                 outputCol.SetDataTypeProperties(extCol.DataType, extCol.Length, extCol.Precision, extCol.Scale, extCol.CodePage);
                 // Associate the external column and the output column
                 outputCol.ExternalMetadataColumnID = extCol.ID;
                 outputColExists = true;
                 break;
             }
         }
         // Create an IDTSOutputColumn if not exists. 
         if (!(outputColExists))
         {
             IDTSOutputColumn100 outputCol = output.OutputColumnCollection.New();
             outputCol.Name = extCol.Name;  // map is based on name
             // Set the data type properties
             outputCol.SetDataTypeProperties(extCol.DataType, extCol.Length, extCol.Precision, extCol.Scale, extCol.CodePage);
             // Associate the external column and the output column
             outputCol.ExternalMetadataColumnID = extCol.ID;
         }
     }
     #endregion
     #endregion
     #region Save the Package to disk
     new Application().SaveToXml(@"C:\Temp\Pkg.dtsx", package, null);
     #endregion
 }
Exemplo n.º 35
0
        public override void ReinitializeMetaData()
        {
            base.ReinitializeMetaData();

            IDTSInput100 input = ComponentMetaData.InputCollection[0];

            if (!this.validExternalMetadata && this.isConnected)
            {
                input.ExternalMetadataColumnCollection.RemoveAll();
                input.InputColumnCollection.RemoveAll();
                this.validExternalMetadata = true;

                Layer       OGRLayer      = this.getLayer();
                FeatureDefn OGRFeatureDef = OGRLayer.GetLayerDefn();

                int i = 0;
                while (i < OGRFeatureDef.GetFieldCount())
                {
                    //map OGR field type to SSIS data type
                    FieldDefn OGRFieldDef    = OGRFeatureDef.GetFieldDefn(i);
                    DataType  BufferDataType = this.OGRTypeToBufferType(OGRFieldDef.GetFieldType());
                    int       length         = 0;
                    int       precision      = OGRFieldDef.GetWidth();
                    int       scale          = OGRFieldDef.GetPrecision();
                    int       codepage       = 1252;

                    switch (BufferDataType)
                    {
                    case DataType.DT_WSTR:
                        length    = precision;
                        codepage  = 0;
                        precision = 0;
                        scale     = 0;
                        //check for length == 0
                        if (length == 0)
                        {
                            BufferDataType = DataType.DT_NTEXT;
                        }
                        break;

                    default:
                        length    = 0;
                        precision = 0;
                        codepage  = 0;
                        scale     = 0;
                        break;
                    }

                    IDTSExternalMetadataColumn100 ecol = input.ExternalMetadataColumnCollection.New();
                    ecol.Name      = OGRFieldDef.GetName();
                    ecol.DataType  = BufferDataType;
                    ecol.Length    = length;
                    ecol.Precision = precision;
                    ecol.Scale     = scale;
                    ecol.CodePage  = codepage;

                    i++;
                }

                //get geometry column
                string geomtryColumn = (OGRLayer.GetGeometryColumn() != "") ? OGRLayer.GetGeometryColumn() : "GEOMETRY";

                //Set OGRGeometry external metadata column
                IDTSExternalMetadataColumn100 egeomCol = input.ExternalMetadataColumnCollection.New();

                egeomCol.Name      = geomtryColumn;
                egeomCol.DataType  = DataType.DT_IMAGE;
                egeomCol.Precision = 0;
                egeomCol.Length    = 0;
                egeomCol.Scale     = 0;
                egeomCol.CodePage  = 0;

                //set geometry column custom property
                ComponentMetaData.CustomPropertyCollection["Geometry Column"].Value = geomtryColumn;
            }

            if (!ComponentMetaData.AreInputColumnsValid)
            {
                ComponentMetaData.RemoveInvalidInputColumns();
            }
        }
Exemplo n.º 36
0
        // Rebuild the component outputs based on the model
        public override void ReinitializeMetaData()
        {
            // Clean out the outputs
            ComponentMetaData.OutputCollection.RemoveAll();

            // Get the model
            JSONDataModel model = getModel();

            // For every output table model crete the SSIS outputs
            foreach (DataTable table in model.Tables)
            {
                // Define a new output
                IDTSOutput100 output = ComponentMetaData.OutputCollection.New();
                output.Name = table.TableName;

                // For every column definition in the model, create the corresponding output column
                foreach (DataRow row in table.Rows)
                {
                    // Create a new Output Column
                    IDTSOutputColumn100 outColumn = output.OutputColumnCollection.New();

                    // Set column data type properties.
                    bool isLong = false;

                    // Assume string for missing datatypes
                    Type dataType = row["datatype"].Equals("")
                        ? typeof(string)
                        : Type.GetType(row["datatype"].ToString());

                    // Translate the datatype into the SSIS intermediate type
                    DataType dt = DataRecordTypeToBufferType(dataType);
                    dt = ConvertBufferDataTypeToFitManaged(dt, ref isLong);

                    // Enforce numeric datatypes
                    switch (dt)
                    {
                    case DataType.DT_R4:
                    case DataType.DT_R8:
                    case DataType.DT_DECIMAL:
                        dt = DataType.DT_NUMERIC;
                        break;

                    case DataType.DT_BOOL:
                    case DataType.DT_I1:
                    case DataType.DT_I2:
                    case DataType.DT_I4:
                        dt = DataType.DT_I4;
                        break;

                    case DataType.DT_UI1:
                    case DataType.DT_UI2:
                    case DataType.DT_UI4:
                        dt = DataType.DT_UI4;
                        break;

                    case DataType.DT_DBTIMESTAMP:
                    case DataType.DT_DBTIMESTAMP2:
                    case DataType.DT_DBDATE:
                    case DataType.DT_DATE:
                    case DataType.DT_FILETIME:
                        dt = DataType.DT_DBTIMESTAMP;
                        break;
                    }


                    // Assume defaults and limits
                    int length    = 0;
                    int precision = 2000;
                    int scale     = 0;
                    int codepage  = table.Locale.TextInfo.ANSICodePage;

                    // Handle the datatype cases
                    switch (dt)
                    {
                    // The length cannot be zero, and the code page property must contain a valid code page.
                    case DataType.DT_STR:
                    case DataType.DT_TEXT:
                        length    = precision;
                        precision = 0;
                        scale     = 0;
                        break;

                    case DataType.DT_WSTR:
                        length    = precision;
                        codepage  = 0;
                        scale     = 0;
                        precision = 0;
                        break;

                    case DataType.DT_NUMERIC:
                        length    = 0;
                        codepage  = 0;
                        precision = 24;
                        scale     = 6;
                        break;

                    default:
                        length    = 0;
                        precision = 0;
                        codepage  = 0;
                        scale     = 0;
                        break;
                    }


                    // Set the properties of the output column.
                    outColumn.Name        = (string)row["shortColumn"];
                    outColumn.Description = (string)row["xpath"];
                    outColumn.SetDataTypeProperties(dt, length, precision, scale, codepage);

                    // Set the properties of the metadata column to facilitate automatic binding
                    IDTSExternalMetadataColumn100 extColumn = output.ExternalMetadataColumnCollection.New();
                    extColumn.Name           = (string)row["shortColumn"];
                    extColumn.Description    = (string)row["xpath"];
                    extColumn.DataType       = dt;
                    extColumn.Length         = length;
                    extColumn.Precision      = precision;
                    extColumn.Scale          = scale;
                    extColumn.CodePage       = codepage;
                    extColumn.MappedColumnID = outColumn.ID;
                }
            }
        }
 public DataFlowMetadataColumnNodeFactory(IDTSExternalMetadataColumn100 input)
 {
     _input = input;
 }