コード例 #1
0
        public override void AcquireConnections(object transaction)
        {
            DTSValidationStatus validationStatus = this.ValidateConnection(DTSValidationStatus.VS_ISVALID);

            if (validationStatus == DTSValidationStatus.VS_ISVALID)
            {
                IDTSConnectionManager100 connectionManager = this.ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager;
                try
                {
                    this.fileName = (string)connectionManager.AcquireConnection(transaction);
                }
                catch (Exception)
                {
                    this.PostErrorAndThrow(MessageStrings.CannotGetFileNameFromConnection);
                }

                if (!System.IO.File.Exists(this.fileName))
                {
                    this.PostErrorAndThrow(MessageStrings.FileDoesNotExist(this.fileName));
                }
            }
            else
            {
                throw new COMException(string.Empty, E_FAIL);
            }
        }
コード例 #2
0
        private bool CheckRowOverflow(RowData rowData)
        {
            bool rowHandled = false;

            if (rowData.ColumnCount > this.bufferService.ColumnCount)
            {
                string errorMessage = MessageStrings.RowOveflow(this.currentRowCount, rowData.ColumnCount, this.bufferService.ColumnCount);
                if (this.bufferService.ErrorOutputUsed)
                {
                    if (this.output.TruncationRowDisposition == DTSRowDisposition.RD_RedirectRow)
                    {
                        this.bufferService.AddErrorRow(errorMessage, string.Empty, rowData.RowText);
                        rowHandled = true;
                    }
                    else if (this.output.TruncationRowDisposition == DTSRowDisposition.RD_IgnoreFailure)
                    {
                        rowHandled = true;
                    }
                }

                if (!rowHandled)
                {
                    throw new BufferSinkException(errorMessage);
                }
            }
            // If the row is handled here it will be ignored in the main output.
            return(rowHandled);
        }
コード例 #3
0
        private void HandleColumnErrorDistribution(DTSRowDisposition rowDisposition, string columnIdString, string columnData, string rowData, Exception ex)
        {
            bool rowHandled = false;

            string errorMessage = MessageStrings.FailedToAssignColumnValue(this.currentRowCount, columnData, columnIdString);

            if (this.bufferService.ErrorOutputUsed)
            {
                if (rowDisposition == DTSRowDisposition.RD_RedirectRow)
                {
                    this.bufferService.AddErrorRow(errorMessage, columnData, rowData);
                    rowHandled = true;
                }
                else if (rowDisposition == DTSRowDisposition.RD_IgnoreFailure)
                {
                    rowHandled = true;
                }
            }

            this.bufferService.RemoveRow();

            if (!rowHandled)
            {
                throw new BufferSinkException(errorMessage, ex);
            }
        }
コード例 #4
0
 public static void CheckFileNameArgument(string fileName)
 {
     CheckStringArgument(fileName, "fileName");
     if (!File.Exists(fileName))
     {
         throw new ArgumentException(MessageStrings.FileDoesNotExist(fileName));
     }
 }
コード例 #5
0
 DTSValidationStatus ValidateBooleanProperty(string propertyName, object propertyValue)
 {
     if (propertyValue is bool)
     {
         return(DTSValidationStatus.VS_ISVALID);
     }
     else
     {
         this.PostError(MessageStrings.InvalidPropertyValue(propertyName, propertyValue));
         return(DTSValidationStatus.VS_ISCORRUPT);
     }
 }
コード例 #6
0
 DTSValidationStatus ValidateDelimiterProperty(string propertyName, object propertyValue)
 {
     if (propertyValue is string)
     {
         string value = (string)propertyValue;
         if (value.Length < MaxDelimLength)
         {
             return(DTSValidationStatus.VS_ISVALID);
         }
         else
         {
             this.PostError(MessageStrings.PropertyStringTooLong(propertyName, propertyValue.ToString()));
             return(DTSValidationStatus.VS_ISBROKEN);
         }
     }
     else
     {
         this.PostError(MessageStrings.InvalidPropertyValue(propertyName, propertyValue));
         return(DTSValidationStatus.VS_ISCORRUPT);
     }
 }
コード例 #7
0
        public override void PrimeOutput(int outputs, int[] outputIDs, PipelineBuffer[] buffers)
        {
            PipelineBuffer mainBuffer  = null;
            PipelineBuffer errorBuffer = null;
            IDTSOutput100  mainOutput  = null;

            int errorOutID    = 0;
            int errorOutIndex = 0;

            // If there is an error output, figure out which output is the main
            // and which is the error
            if (outputs == 2)
            {
                GetErrorOutputInfo(ref errorOutID, ref errorOutIndex);

                if (outputIDs[0] == errorOutID)
                {
                    mainBuffer  = buffers[1];
                    errorBuffer = buffers[0];
                    mainOutput  = this.ComponentMetaData.OutputCollection[1];
                }
                else
                {
                    mainBuffer  = buffers[0];
                    errorBuffer = buffers[1];
                    mainOutput  = this.ComponentMetaData.OutputCollection[0];
                }
            }
            else
            {
                mainBuffer = buffers[0];
                mainOutput = this.ComponentMetaData.OutputCollection[0];
            }

            bool firstRowColumnNames = (bool)this.GetComponentPropertyValue(PropertiesManager.ColumnNamesInFirstRowPropName);
            bool treatNulls          = (bool)this.GetComponentPropertyValue(PropertiesManager.TreatEmptyStringsAsNullPropName);

            FileReader             reader        = new FileReader(this.fileName, this.GetEncoding());
            DelimitedFileParser    parser        = this.CreateParser();
            ComponentBufferService bufferService = new ComponentBufferService(mainBuffer, errorBuffer);

            BufferSink bufferSink = new BufferSink(bufferService, mainOutput, treatNulls);

            bufferSink.CurrentRowCount = parser.HeaderRowsToSkip + parser.DataRowsToSkip + (firstRowColumnNames ? 1 : 0);

            try
            {
                parser.SkipInitialRows(reader);

                RowData rowData = new RowData();
                while (!reader.IsEOF)
                {
                    parser.ParseNextRow(reader, rowData);
                    if (rowData.ColumnCount == 0)
                    {
                        // Last row with no data will be ignored.
                        break;
                    }
                    bufferSink.AddRow(rowData);
                }
            }
            catch (ParsingBufferOverflowException ex)
            {
                this.PostErrorAndThrow(MessageStrings.ParsingBufferOverflow(bufferSink.CurrentRowCount + 1, ex.ColumnIndex + 1, FieldParser.ParsingBufferMaxSize));
            }
            catch (RowColumnNumberOverflow)
            {
                this.PostErrorAndThrow(MessageStrings.MaximumColumnNumberOverflow(bufferSink.CurrentRowCount + 1, RowParser.MaxColumnNumber));
            }
            finally
            {
                reader.Close();
            }

            foreach (PipelineBuffer buffer in buffers)
            {
                buffer.SetEndOfRowset();
            }
        }