Пример #1
0
        public override void PreExecute()
        {
            this.columnInformation = new ArrayList();
            IDTSOutput100 output = ComponentMetaData.OutputCollection[0];

            foreach (IDTSOutputColumn100 col in output.OutputColumnCollection) {
                ColumnInfo ci = new ColumnInfo();
                ci.BufferColumnIndex = BufferManager.FindColumnByLineageID(output.Buffer, col.LineageID);
                ci.ColumnName = col.Name;
                ci.ColumnDataType = col.DataType;
                this.columnInformation.Add(ci);
            }
        }
Пример #2
0
        /// <summary>
        /// Will perform the user-specified behaviour when a processing error occurs
        /// </summary>
        /// <param name="disposition">How the error should be handled</param>
        /// <param name="defaultBuffer">The default output buffer</param>
        /// <param name="errorBuffer">The error output buffer</param>
        /// <param name="failingColumnInfo">The information for the problematic column</param>
        /// <param name="ex">The exception caught from processing (optional)</param>
        private void HandleProcessingError(DTSRowDisposition disposition, PipelineBuffer defaultBuffer, PipelineBuffer errorBuffer, ColumnInfo failingColumnInfo, Exception ex)
        {
            switch (disposition)
            {
                case DTSRowDisposition.RD_RedirectRow:
                    if (errorBuffer == null) throw new InvalidOperationException("There must be an error output defined if redirection was specified");

                    // Add a row to the error buffer.
                    errorBuffer.AddRow();

                    // Get the values from the default buffer
                    // and copy them to the error buffer.
                    var errorOutputColumns = GetErrorOutputColumns().ToArray();
                    foreach (IDTSOutputColumn100 column in errorOutputColumns)
                    {
                        ColumnInfo copiedColumnInfo = GetColumnInfo(column.Name);
                        if (copiedColumnInfo != null)
                            errorBuffer[copiedColumnInfo.ErrorOuputBufferColumnIndex] = defaultBuffer[copiedColumnInfo.OuputBufferColumnIndex];
                    }

                    // Set the error information.
                    int errorCode = (ex == null ? 0 : System.Runtime.InteropServices.Marshal.GetHRForException(ex));
                    errorBuffer.SetErrorInfo(errorOutputID, errorCode, failingColumnInfo.OutputColumn.LineageID);

                    // Remove the row that was added to the default buffer.
                    defaultBuffer.RemoveRow();
                    break;
                case DTSRowDisposition.RD_FailComponent:
                    throw new Exception(String.Format("There was an issue with column: {0}", failingColumnInfo.OutputColumn.Name), ex);
            }
        }
Пример #3
0
        private object GetValue(BsonDocument document, ColumnInfo ci)
        {
            BsonValue value = document.GetValue(ci.ColumnName);

            return GetDataTypeValueFromBsonValue(value, ci.ColumnDataType);
        }
Пример #4
0
        /// <summary>
        /// Will perform the user-specified behaviour when a processing error occurs
        /// </summary>
        /// <param name="disposition">How the error should be handled</param>
        /// <param name="defaultBuffer">The default output buffer</param>
        /// <param name="errorBuffer">The error output buffer</param>
        /// <param name="failingColumnInfo">The information for the problematic column</param>
        /// <param name="ex">The exception caught from processing (optional)</param>
        private void HandleProcessingError(DTSRowDisposition disposition, PipelineBuffer defaultBuffer, PipelineBuffer errorBuffer, ColumnInfo failingColumnInfo, Exception ex)
        {
            switch (disposition)
            {
            case DTSRowDisposition.RD_RedirectRow:
                if (errorBuffer == null)
                {
                    throw new InvalidOperationException("There must be an error output defined if redirection was specified");
                }

                // Add a row to the error buffer.
                errorBuffer.AddRow();

                // Get the values from the default buffer
                // and copy them to the error buffer.
                var errorOutputColumns = GetErrorOutputColumns().ToArray();
                foreach (IDTSOutputColumn100 column in errorOutputColumns)
                {
                    ColumnInfo copiedColumnInfo = GetColumnInfo(column.Name);
                    if (copiedColumnInfo != null)
                    {
                        errorBuffer[copiedColumnInfo.ErrorOuputBufferColumnIndex] = defaultBuffer[copiedColumnInfo.OuputBufferColumnIndex];
                    }
                }

                // Set the error information.
                int errorCode = (ex == null ? 0 : System.Runtime.InteropServices.Marshal.GetHRForException(ex));
                errorBuffer.SetErrorInfo(errorOutputID, errorCode, failingColumnInfo.OutputColumn.LineageID);

                // Remove the row that was added to the default buffer.
                defaultBuffer.RemoveRow();
                break;

            case DTSRowDisposition.RD_FailComponent:
                throw new Exception(String.Format("There was an issue with column: {0}", failingColumnInfo.OutputColumn.Name), ex);
            }
        }
Пример #5
0
        private object GetValue(BsonDocument document, ColumnInfo ci)
        {
            BsonValue value = document.GetValue(ci.ColumnName);

            return(GetDataTypeValueFromBsonValue(value, ci.ColumnDataType));
        }
Пример #6
0
        /// <summary>
        /// Called at run time for source components and transformation components with
        ///     asynchronous outputs to let these components add rows to the output buffers.
        /// </summary>
        /// <param name="outputs">The number of elements in the outputIDs and buffers arrays.</param>
        /// <param name="outputIDs">An array of Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSOutput100 ID's.</param>
        /// <param name="buffers">An array of Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer objects.</param>
        public override void PrimeOutput(int outputs, int[] outputIDs, PipelineBuffer[] buffers)
        {
            // Determine which buffer is for regular output, and which is for error output
            PipelineBuffer errorBuffer   = null;
            PipelineBuffer defaultBuffer = null;

            for (int outputIndex = 0; outputIndex < outputs; outputIndex++)
            {
                if (outputIDs[outputIndex] == errorOutputID)
                {
                    errorBuffer = buffers[outputIndex];
                }
                else
                {
                    defaultBuffer = buffers[outputIndex];
                }
            }

            var cursor = GetCollectionCursor(ComponentMetaData.CustomPropertyCollection[COLLECTION_NAME_PROP_NAME].Value);
            var defaultOutputColumns = GetDefaultOutputColumns().ToArray();

            foreach (BsonDocument document in cursor)
            {
                ColumnInfo failingColumnInfo = null;
                try
                {
                    defaultBuffer.AddRow();
                    foreach (ColumnInfo columnInfo in this.columnInformata)
                    {
                        failingColumnInfo = columnInfo;
                        if (document.Contains(columnInfo.ColumnName) && document[columnInfo.ColumnName] != null)
                        {
                            if (document.GetValue(columnInfo.ColumnName).IsBsonNull)
                            {
                                defaultBuffer.SetNull(columnInfo.OuputBufferColumnIndex);
                            }
                            else
                            {
                                var value = GetValue(document, columnInfo);
                                try
                                {
                                    defaultBuffer[columnInfo.OuputBufferColumnIndex] = value;
                                }
                                catch (DoesNotFitBufferException ex)
                                {
                                    if (failingColumnInfo.OutputColumn.TruncationRowDisposition == DTSRowDisposition.RD_IgnoreFailure)
                                    {
                                        if (value is string)
                                        {
                                            defaultBuffer[columnInfo.OuputBufferColumnIndex] = value.ToString().Substring(0, columnInfo.OutputColumn.Length);
                                        }
                                        else
                                        {
                                            ComponentMetaData.FireWarning(0,
                                                                          "MongoDataSource",
                                                                          string.Format("Truncation of column {0} failed, as truncation of type {1} currently unsupported.", columnInfo.OutputColumn.Name, value.GetType().FullName),
                                                                          String.Empty, 0);
                                        }
                                    }
                                    else
                                    {
                                        throw ex;
                                    }
                                }
                            }
                        }
                        else
                        {
                            defaultBuffer.SetNull(columnInfo.OuputBufferColumnIndex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    DTSRowDisposition disposition = DTSRowDisposition.RD_NotUsed;
                    if (ex is DoesNotFitBufferException)
                    {
                        disposition = failingColumnInfo.OutputColumn.TruncationRowDisposition;
                    }
                    else
                    {
                        disposition = failingColumnInfo.OutputColumn.ErrorRowDisposition;
                    }

                    HandleProcessingError(disposition, defaultBuffer, errorBuffer, failingColumnInfo, ex);
                }
            }

            if (defaultBuffer != null)
            {
                defaultBuffer.SetEndOfRowset();
            }

            if (errorBuffer != null)
            {
                errorBuffer.SetEndOfRowset();
            }
        }