Example #1
0
        public override void transform(ref PipelineBuffer buffer, int defaultOutputId, int inputColumnBufferIndex, int outputColumnBufferIndex)
        {
            //Get OGR Geometry from buffer
            byte[] geomBytes = new byte[buffer.GetBlobLength(inputColumnBufferIndex)];
            geomBytes = buffer.GetBlobData(inputColumnBufferIndex, 0, geomBytes.Length);
            Geometry geom = Geometry.CreateFromWkb(geomBytes);

            double area = geom.GetArea();

            buffer.SetDouble(outputColumnBufferIndex, area);
            buffer.DirectRow(defaultOutputId);
        }
        public override void transform(ref PipelineBuffer buffer, int defaultOutputId, int inputColumnBufferIndex, int outputColumnBufferIndex)
        {
            //Get WKT from buffer
            String wkt = buffer.GetString(inputColumnBufferIndex);

            Geometry geom = Geometry.CreateFromWkt(wkt);

            byte[] geomBytes = new byte[geom.WkbSize()];
            geom.ExportToWkb(geomBytes);
            buffer.AddBlobData(outputColumnBufferIndex, geomBytes);
            buffer.DirectRow(defaultOutputId);
        }
Example #3
0
        public override void transform(ref PipelineBuffer buffer, int defaultOutputId, int inputColumnBufferIndex, int outputColumnBufferIndex)
        {
            //Get WKT from buffer
            String wkt = buffer.GetString(inputColumnBufferIndex);

            Geometry geom = Geometry.CreateFromWkt(wkt);

            byte[] geomBytes = new byte[geom.WkbSize()];
            geom.ExportToWkb(geomBytes);
            buffer.AddBlobData(outputColumnBufferIndex, geomBytes);
            buffer.DirectRow(defaultOutputId);
        }
Example #4
0
        public override void transform(ref PipelineBuffer buffer, int defaultOutputId, int inputColumnBufferIndex, int outputColumnBufferIndex)
        {
            //Get OGR Geometry from buffer
            byte[] geomBytes = new byte[buffer.GetBlobLength(inputColumnBufferIndex)];
            geomBytes = buffer.GetBlobData(inputColumnBufferIndex, 0, geomBytes.Length);
            Geometry geom = Geometry.CreateFromWkb(geomBytes);

            double area = geom.GetArea();

            buffer.SetDouble(outputColumnBufferIndex, area);
            buffer.DirectRow(defaultOutputId);
        }
        public override void transform(ref PipelineBuffer buffer, int defaultOutputId, int inputColumnBufferIndex, int outputColumnBufferIndex)
        {
            //Get OGR Geometry from buffer
            byte[] geomBytes = new byte[buffer.GetBlobLength(inputColumnBufferIndex)];
            geomBytes = buffer.GetBlobData(inputColumnBufferIndex, 0, geomBytes.Length);
            Geometry geom = Geometry.CreateFromWkb(geomBytes);

            string kml;
            kml = geom.ExportToKML(null);

            buffer.SetString(outputColumnBufferIndex, kml);
            buffer.DirectRow(defaultOutputId);
        }
Example #6
0
        public override void transform(ref PipelineBuffer buffer, int defaultOutputId, int inputColumnBufferIndex, int outputColumnBufferIndex)
        {
            //Get OGR Geometry from buffer
            byte[] geomBytes = new byte[buffer.GetBlobLength(inputColumnBufferIndex)];
            geomBytes = buffer.GetBlobData(inputColumnBufferIndex, 0, geomBytes.Length);
            Geometry geom = Geometry.CreateFromWkb(geomBytes);

            string json;

            json = geom.ExportToJson(null);

            buffer.SetString(outputColumnBufferIndex, json);
            buffer.DirectRow(defaultOutputId);
        }
Example #7
0
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            var geoCodingService = new GeoCodingService();

            var output = ComponentMetaData.OutputCollection["Output"];

            while (buffer.NextRow())
            {
                bool   modified = false;
                string address  = GetFullAddressFromBuffer(buffer);

                if (!string.IsNullOrWhiteSpace(address))
                {
                    var coordinates = geoCodingService.GeoCodeAddress(address);
                    if (coordinates != null)
                    {
                        if (_columnIndices.ContainsKey(LatitudeColumnName))
                        {
                            buffer.SetDecimal(_columnIndices[LatitudeColumnName], coordinates.Latitude);
                            modified = true;
                        }

                        if (_columnIndices.ContainsKey(LongitudeColumnName))
                        {
                            buffer.SetDecimal(_columnIndices[LongitudeColumnName], coordinates.Longitude);
                            modified = true;
                        }

                        if (_columnIndices.ContainsKey(LocationColumnName))
                        {
                            var pointTaggedText = new SqlChars(string.Format("POINT({0} {1})", coordinates.Longitude, coordinates.Latitude));
                            var sqlGeography    = SqlGeography.STPointFromText(pointTaggedText, 4326);

                            _tmpMemoryStream.SetLength(0);
                            sqlGeography.Write(_tmpBinaryWriter);
                            _tmpBinaryWriter.Flush();

                            buffer.AddBlobData(_columnIndices[LocationColumnName], _tmpMemoryStream.GetBuffer(), (int)_tmpMemoryStream.Length);
                            modified = true;
                        }
                    }
                }

                if (modified)
                {
                    // send buffered row to output
                    buffer.DirectRow(output.ID);
                }
            }
        }
        public override void transform(ref PipelineBuffer buffer, int defaultOutputId, int inputColumnBufferIndex, int outputColumnBufferIndex)
        {
            //Get OGR Geometry from buffer
            byte[] geomBytes = new byte[buffer.GetBlobLength(inputColumnBufferIndex)];
            geomBytes = buffer.GetBlobData(inputColumnBufferIndex, 0, geomBytes.Length);
            Geometry geom = Geometry.CreateFromWkb(geomBytes);

            if (this.isMultipart(geom))
            {
                for (int i = 0; i < geom.GetGeometryCount(); i++)
                {
                    Geometry geomPart = geom.GetGeometryRef(i);
                    geomBytes = new byte[geom.WkbSize()];
                    geomPart.ExportToWkb(geomBytes);
                    buffer.ResetBlobData(inputColumnBufferIndex);
                    buffer.AddBlobData(inputColumnBufferIndex, geomBytes);
                    buffer.DirectRow(defaultOutputId);
                }
            }
            else
            {
                buffer.DirectRow(defaultOutputId);
            }
        }
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            int colIndex = 0;

            while (buffer.NextRow())
            {
                try
                {
                    foreach (ColumnInfo col in _columnInfos)
                    {
                        colIndex = col.BufferIndex;
                        if (Utility.ContainsFlag(col.Operation, CleaningOperation.SetNullDefault))
                        {
                            ReplaceNullValueWithDefault(buffer, col);
                        }

                        if (Utility.ContainsFlag(col.Operation, CleaningOperation.TrimString))
                        {
                            TrimString(buffer, col);
                        }

                        if (Utility.ContainsFlag(col.Operation, CleaningOperation.FormatValue))
                        {
                            FormatValue(buffer, col);
                        }

                        if (Utility.ContainsFlag(col.Operation, CleaningOperation.ValidateRange))
                        {
                            ValidateRange(buffer, col);
                        }

                        if (Utility.ContainsFlag(col.Operation, CleaningOperation.ValidateKnownGood))
                        {
                            ValidateKnownGoodValue(buffer, col);
                        }
                    }

                    buffer.DirectRow(_outputId);
                }
                catch (Exception)
                {
                    buffer.DirectErrorRow(_errorOutId, 100, colIndex);
                }
            }
        }
        public override void transform(ref PipelineBuffer buffer, int defaultOutputId, int inputColumnBufferIndex, int outputColumnBufferIndex)
        {
            //Get OGR Geometry from buffer
            byte[] geomBytes = new byte[buffer.GetBlobLength(inputColumnBufferIndex)];
            geomBytes = buffer.GetBlobData(inputColumnBufferIndex, 0, geomBytes.Length);
            Geometry geom = Geometry.CreateFromWkb(geomBytes);

            geom = geom.SimplifyPreserveTopology(this.tolerance);

            geomBytes = new byte[geom.WkbSize()];
            geom.ExportToWkb(geomBytes);

            buffer.ResetBlobData(inputColumnBufferIndex);
            buffer.AddBlobData(inputColumnBufferIndex, geomBytes);

            //Direct row to default output
            buffer.DirectRow(defaultOutputId);
        }
Example #11
0
        public override void transform(ref PipelineBuffer buffer, int defaultOutputId, int inputColumnBufferIndex, int outputColumnBufferIndex)
        {
            //Get OGR Geometry from buffer
            byte[] geomBytes = new byte[buffer.GetBlobLength(inputColumnBufferIndex)];
            geomBytes = buffer.GetBlobData(inputColumnBufferIndex, 0, geomBytes.Length);
            Geometry geom = Geometry.CreateFromWkb(geomBytes);

            geom.FlattenTo2D();

            geomBytes = new byte[geom.WkbSize()];
            geom.ExportToWkb(geomBytes);

            buffer.ResetBlobData(inputColumnBufferIndex);
            buffer.AddBlobData(inputColumnBufferIndex, geomBytes);

            //Direct row to default output
            buffer.DirectRow(defaultOutputId);
        }
Example #12
0
        //Run Time - Validate Phone Number
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            if (!buffer.EndOfRowset)
            {
                while (buffer.NextRow())
                {
                    try
                    {
                        var phoneNumberColumnIndex  = _phneNumberColumnInfo.PhoneNumberBufferIndex;
                        var bufferColDataType       = buffer.GetColumnInfo(inputBufferColumnIndex[_phneNumberColumnInfo.PhoneNumberBufferIndex]).DataType;
                        var parsedPhoneNumberResult = GetParsedPhoneNumberResult(buffer, phoneNumberColumnIndex, bufferColDataType);
                        SetPhoneNumberResultValuesToOutput(buffer, phoneNumberColumnIndex, parsedPhoneNumberResult);

                        buffer.DirectRow(_outputId);
                    }
                    catch (Exception e)
                    {
                        buffer.DirectErrorRow(_errorOutId, 100, _phonenumberLinage);
                    }
                }
            }
        }
Example #13
0
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            int          errorOutputID    = -1;
            int          errorOutputIndex = -1;
            int          GoodOutputId     = -1;
            IDTSInput100 inp = ComponentMetaData.InputCollection.GetObjectByID(inputID);

            #region Output IDs
            GetErrorOutputInfo(ref errorOutputID, ref errorOutputIndex);
            // There is an error output defined
            errorOutputID = ComponentMetaData.OutputCollection["RSErrors"].ID;
            GoodOutputId  = ComponentMetaData.OutputCollection["RSout"].ID;
            #endregion

            while (buffer.NextRow())
            {
                // Check if we have columns to process
                if (_inputColumnInfos.Length == 0)
                {
                    // We do not have to have columns. This is a Sync component so the
                    // rows will flow through regardless. Could expand Validate to check
                    // for columns in the InputColumnCollection
                    buffer.DirectRow(GoodOutputId);
                }
                else
                {
                    try
                    {
                        for (int x = 0; x < _inputColumnInfos.Length; x++)
                        {
                            ColumnInfo columnInfo = _inputColumnInfos[x];
                            if (!buffer.IsNull(columnInfo.bufferColumnIndex))
                            {
                                // Get value as character array
                                char[] chars = buffer.GetString(columnInfo.bufferColumnIndex).ToString().ToCharArray();
                                // Reverse order of characters in array
                                Array.Reverse(chars);
                                // Reassemble reversed value as string
                                string s = new string(chars);
                                // Set output value in buffer
                                buffer.SetString(columnInfo.bufferColumnIndex, s);
                            }
                        }
                        buffer.DirectRow(GoodOutputId);
                    }
                    catch (Exception ex)
                    {
                        switch (inp.ErrorRowDisposition)
                        {
                        case DTSRowDisposition.RD_RedirectRow:
                            buffer.DirectErrorRow(errorOutputID, 0, buffer.CurrentRow);
                            break;

                        case DTSRowDisposition.RD_FailComponent:
                            throw new Exception("Error processing " + ex.Message);

                        case DTSRowDisposition.RD_IgnoreFailure:
                            buffer.DirectRow(GoodOutputId);
                            break;
                        }
                    }
                }
            }
        }
        public override void ProcessInput(int inputID, PipelineBuffer buffer) {
            var geoCodingService = new GeoCodingService();

            var output = ComponentMetaData.OutputCollection["Output"];

            while (buffer.NextRow())
            {
                bool modified = false;
                string address = GetFullAddressFromBuffer(buffer);

                if (!string.IsNullOrWhiteSpace(address))
                {
                    var coordinates = geoCodingService.GeoCodeAddress(address);
                    if (coordinates != null)
                    {
                        if (_columnIndices.ContainsKey(LatitudeColumnName))
                        {
                            buffer.SetDecimal(_columnIndices[LatitudeColumnName], coordinates.Latitude);
                            modified = true;
                        }

                        if (_columnIndices.ContainsKey(LongitudeColumnName))
                        {
                            buffer.SetDecimal(_columnIndices[LongitudeColumnName], coordinates.Longitude);
                            modified = true;
                        }

                        if (_columnIndices.ContainsKey(LocationColumnName))
                        {
                            var pointTaggedText = new SqlChars(string.Format("POINT({0} {1})", coordinates.Longitude, coordinates.Latitude));
	                        var sqlGeography = SqlGeography.STPointFromText(pointTaggedText, 4326);
                            
                            _tmpMemoryStream.SetLength(0);
                            sqlGeography.Write(_tmpBinaryWriter);
                            _tmpBinaryWriter.Flush();

                            buffer.AddBlobData(_columnIndices[LocationColumnName], _tmpMemoryStream.GetBuffer(), (int)_tmpMemoryStream.Length);
                            modified = true;
                        }
                    }
                }

                if (modified)
                {
                    // send buffered row to output
                    buffer.DirectRow(output.ID);
                }
            }
        }
        /// <summary>
        /// Process the rows from the datasource
        /// </summary>
        /// <param name="inputID"></param>
        /// <param name="buffer"></param>
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            EntityCollection           newEntityCollection = new EntityCollection();
            List <OrganizationRequest> Rqs = new List <OrganizationRequest>();


            Mapping.MappingItem mappedColumn;
            IDTSInputColumn100  inputcolumn;

            IDTSInput100 input = ComponentMetaData.InputCollection.GetObjectByID(inputID);


            Entity newEntity;

            while (buffer.NextRow())
            {
                try
                {
                    newEntity = new Entity(EntityName);


                    bchCnt++;
                    //adds the row to output buffer for futher processing.



                    foreach (int col in mapInputColsToBufferCols)
                    {
                        inputcolumn = ComponentMetaData.InputCollection[0].InputColumnCollection[col];

                        mappedColumn = mapping.ColumnList.Find(x => x.ExternalColumnName == inputcolumn.Name && x.Map == true);

                        if (mappedColumn != null)
                        {
                            if (buffer.IsNull(col) == false)
                            {
                                AttributesBuilder(mappedColumn, buffer[col], ref newEntity);
                            }
                            else
                            {
                                AttributesBuilder(mappedColumn, mappedColumn.DefaultValue, ref newEntity);
                            }
                        }
                    }


                    switch ((Operations)operation)
                    {    //Create
                    case Operations.Create:
                        Rqs.Add(new CreateRequest {
                            Target = newEntity
                        });
                        newEntity.Attributes["ownerid"] = new EntityReference("systemuser", currentUserId);
                        break;

                    //Update
                    case Operations.Update:
                        Rqs.Add(new UpdateRequest {
                            Target = newEntity
                        });
                        newEntity.Attributes["ownerid"] = new EntityReference("systemuser", currentUserId);
                        break;

                    //Delete
                    case Operations.Delete:
                        Rqs.Add(new DeleteRequest {
                            Target = newEntity.ToEntityReference()
                        });
                        break;

                    //status
                    case Operations.Status:
                        Rqs.Add(new SetStateRequest
                        {
                            EntityMoniker = newEntity.ToEntityReference(),
                            State         = new OptionSetValue((int)newEntity.Attributes["statecode"]),
                            Status        = new OptionSetValue((int)newEntity.Attributes["statuscode"])
                        });
                        break;

                    case Operations.Upsert:
                        Rqs.Add(new UpsertRequest {
                            Target = newEntity
                        });
                        newEntity.Attributes["ownerid"] = new EntityReference("systemuser", currentUserId);
                        break;

                    case Operations.Workflow:
                        newEntity.Attributes["ownerid"] = new EntityReference("systemuser", currentUserId);
                        Rqs.Add(new ExecuteWorkflowRequest {
                            EntityId = newEntity.Id, WorkflowId = Guid.Parse(WorkflowId)
                        });

                        break;
                    }
                    newEntityCollection.Entities.Add(newEntity);
                    rowIndexList.Add(ir);



                    if (bchCnt == batchSize * 2 || (buffer.CurrentRow == buffer.RowCount || (buffer.RowCount % 2 != 0 && buffer.CurrentRow == buffer.RowCount - 1)))
                    {
                        int            startBuffIndex  = buffer.CurrentRow - (bchCnt - 1);
                        CRMIntegrate[] IntegrationRows = SendRowsToCRM(newEntityCollection, EntityName, Rqs);

                        sendOutputResults(IntegrationRows, buffer, startBuffIndex);
                    }

                    ir++;
                }

                catch (Exception ex)
                {
                    switch (input.ErrorRowDisposition)
                    {
                    case DTSRowDisposition.RD_RedirectRow:
                        buffer.DirectErrorRow(errorOutputId, 0, buffer.CurrentRow);
                        break;

                    case DTSRowDisposition.RD_IgnoreFailure:
                        buffer.DirectRow(defaultOuputId);
                        break;

                    case DTSRowDisposition.RD_FailComponent:
                        throw new Exception("There was and error processing rows. " + ex.Message);
                    }
                }
            }
        }
        /// <summary>
        /// Sends Outputs to files. //TODO: Rewrite this method
        /// </summary>
        /// <param name="Integ"></param>
        /// <param name="buffer"></param>
        /// <param name="startBuffIndex"></param>
        private void sendOutputResults(CRMIntegrate[] Integ, PipelineBuffer buffer, int startBuffIndex)
        {
            IEnumerable <ExecuteMultipleResponseItem> FltResp;
            IEnumerable <ExecuteMultipleResponseItem> OkResp;

            int current = buffer.CurrentRow;

            buffer.CurrentRow = startBuffIndex;

            foreach (CRMIntegrate irsp in Integ)
            {
                if (irsp.Resp != null)
                {
                    if (irsp.Resp.IsFaulted)
                    {
                        FltResp = irsp.Resp.Responses.Where(r => r.Fault != null);

                        foreach (ExecuteMultipleResponseItem itm in FltResp)
                        {
                            buffer.DirectErrorRow(errorOutputId, itm.Fault.ErrorCode, buffer.CurrentRow);


                            if (buffer.CurrentRow < buffer.RowCount)
                            {
                                buffer.NextRow();
                            }
                        }
                    }

                    OkResp = irsp.Resp.Responses.Where(r => r.Fault == null);

                    //int ResponseColumn = ComponentMetaData.InputCollection[0].InputColumnCollection.Count + ComponentMetaData.OutputCollection[0].OutputColumnCollection.Count;
                    int ResponseColumn = ComponentMetaData.OutputCollection[0].OutputColumnCollection.Count - 1;

                    foreach (ExecuteMultipleResponseItem itm in OkResp)
                    {
                        //Add the inserted GUID for Create Operation

                        switch ((Operations)operation)
                        {
                        case Operations.Create:

                            buffer.SetString(ResponseColumn, ((CreateResponse)itm.Response).id.ToString());
                            break;

                        case Operations.Update:
                            buffer.SetString(ResponseColumn, ((UpdateResponse)itm.Response).Results.FirstOrDefault().Value.ToString());
                            break;

                        case Operations.Delete:
                            buffer.SetString(ResponseColumn, ((DeleteResponse)itm.Response).Results.FirstOrDefault().Value.ToString());
                            break;

                        case Operations.Upsert:
                            buffer.SetString(ResponseColumn, ((UpsertResponse)itm.Response).Results.FirstOrDefault().Value.ToString());
                            break;

                        case Operations.Status:
                            buffer.SetString(ResponseColumn, ((SetStateResponse)itm.Response).Results.FirstOrDefault().Value.ToString());
                            break;

                        case Operations.Workflow:
                            buffer.SetString(ResponseColumn, ((ExecuteWorkflowResponse)itm.Response).Results.FirstOrDefault().Value.ToString());
                            break;
                        }


                        buffer.DirectRow(defaultOuputId);
                        if (buffer.CurrentRow < buffer.RowCount)
                        {
                            buffer.NextRow();
                        }
                    }
                }
                else if (irsp.ExceptionMessage != "")
                {
                    buffer.DirectErrorRow(errorOutputId, -1, buffer.CurrentRow);
                    if (buffer.CurrentRow < buffer.RowCount)
                    {
                        buffer.NextRow();
                    }
                }
            }

            buffer.CurrentRow = current;
        }
Example #17
0
        public override void ProcessInput(int inputId, PipelineBuffer buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            IDTSInput100 input = this.ComponentMetaData.InputCollection.GetObjectByID(inputId);

            int errorOutputId    = -1;
            int errorOutputIndex = -1;
            int defaultOutputId  = -1;

            this.GetErrorOutputInfo(ref errorOutputId, ref errorOutputIndex);

            if (errorOutputIndex == 0)
            {
                defaultOutputId = this.ComponentMetaData.OutputCollection[1].ID;
            }
            else
            {
                defaultOutputId = this.ComponentMetaData.OutputCollection[0].ID;
            }

            while (buffer.NextRow())
            {
                // If the columnInfos array has zero dimensions, then
                // no input columns have been selected for the component.
                // Direct the row to the default output.
                if (this.inputColumnInfos.Length == 0)
                {
                    buffer.DirectRow(defaultOutputId);
                }

                // TODO - namespace table.
                StringBuilder sb = new StringBuilder();
                using (
                    XmlWriter writer = XmlWriter.Create(
                        sb,
                        new XmlWriterSettings {
                    OmitXmlDeclaration = !this.includeXMLTag
                }))
                {
                    if (!string.IsNullOrEmpty(this.xmlNamespace))
                    {
                        writer.WriteAttributeString("xmlns", this.xmlNamespace);
                    }

                    writer.WriteStartElement(this.rowElementName);

                    if (this.elementFormat)
                    {
                        this.FormatElementOutput(buffer, writer);
                    }
                    else
                    {
                        this.FormatAttributeOutput(buffer, writer);
                    }

                    writer.WriteEndElement();
                }

                buffer.SetString(this.outputColumnInfos[0].BufferColumnIndex, sb.ToString());

                // Finished processing each of the columns in this row.
                buffer.DirectRow(defaultOutputId);
            }
        }
Example #18
0
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (!buffer.EndOfRowset)
            {
                IDTSInput100 input = ComponentMetaData.InputCollection.GetObjectByID(inputID);

                int errorOutputID    = -1;
                int errorOutputIndex = -1;
                int defaultOutputId  = -1;

                GetErrorOutputInfo(ref errorOutputID, ref errorOutputIndex);

                defaultOutputId = errorOutputIndex == 0 ? ComponentMetaData.OutputCollection[1].ID : ComponentMetaData.OutputCollection[0].ID;

                while (buffer.NextRow())
                {
                    if (inputColumnInfos.Length == 0)
                    {
                        buffer.DirectRow(defaultOutputId);
                    }
                    else
                    {
                        var  isError           = false;
                        var  inputByteBuffer   = new byte[1000];
                        var  bufferUsed        = 0;
                        uint blobLength        = 0;
                        var  columnToProcessID = 0;

                        for (int i = 0; i < inputColumnInfos.Length; i++)
                        {
                            ColumnInfo info = inputColumnInfos[i];
                            columnToProcessID = info.bufferColumnIndex;

                            if (!buffer.IsNull(columnToProcessID))
                            {
                                switch (buffer.GetColumnInfo(columnToProcessID).DataType)
                                {
                                case DataType.DT_BOOL:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetBoolean(columnToProcessID));
                                    break;

                                case DataType.DT_IMAGE:
                                    blobLength = buffer.GetBlobLength(columnToProcessID);
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetBlobData(columnToProcessID, 0, (int)blobLength));
                                    break;

                                case DataType.DT_BYTES:
                                    byte[] bytesFromBuffer = buffer.GetBytes(columnToProcessID);
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, bytesFromBuffer);
                                    break;

                                case DataType.DT_CY:
                                case DataType.DT_DECIMAL:
                                case DataType.DT_NUMERIC:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetDecimal(columnToProcessID));
                                    break;

                                //case DataType.DT_DBTIMESTAMPOFFSET:
                                //    DateTimeOffset dateTimeOffset = buffer.GetDateTimeOffset(columnToProcessID);
                                //    Utility.Append(ref inputByteBuffer, ref bufferUsed, dateTimeOffset);
                                //    break;
                                case DataType.DT_DBDATE:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetDate(columnToProcessID), millisecondHandling);
                                    break;

                                case DataType.DT_DATE:
                                case DataType.DT_DBTIMESTAMP:
                                case DataType.DT_DBTIMESTAMP2:
                                case DataType.DT_FILETIME:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetDateTime(columnToProcessID), millisecondHandling);
                                    break;

                                case DataType.DT_DBTIME:
                                case DataType.DT_DBTIME2:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetTime(columnToProcessID));
                                    break;

                                case DataType.DT_GUID:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetGuid(columnToProcessID));
                                    break;

                                case DataType.DT_I1:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetSByte(columnToProcessID));
                                    break;

                                case DataType.DT_I2:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetInt16(columnToProcessID));
                                    break;

                                case DataType.DT_I4:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetInt32(columnToProcessID));
                                    break;

                                case DataType.DT_I8:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetInt64(columnToProcessID));
                                    break;

                                case DataType.DT_STR:
                                case DataType.DT_TEXT:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetString(columnToProcessID), Encoding.ASCII);
                                    break;

                                case DataType.DT_NTEXT:
                                case DataType.DT_WSTR:
                                    var wstr = buffer.GetString(columnToProcessID);
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetString(columnToProcessID), Encoding.Unicode);
                                    break;

                                case DataType.DT_R4:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetSingle(columnToProcessID));
                                    break;

                                case DataType.DT_R8:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetDouble(columnToProcessID));
                                    break;

                                case DataType.DT_UI1:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetByte(columnToProcessID));
                                    break;

                                case DataType.DT_UI2:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetUInt16(columnToProcessID));
                                    break;

                                case DataType.DT_UI4:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetUInt32(columnToProcessID));
                                    break;

                                case DataType.DT_UI8:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetUInt64(columnToProcessID));
                                    break;

                                case DataType.DT_EMPTY:
                                case DataType.DT_NULL:
                                default:
                                    break;
                                }
                            }
                            else if (!string.IsNullOrEmpty(nullValue))
                            {
                                Utility.Append(ref inputByteBuffer, ref bufferUsed, nullValue, Encoding.ASCII);
                            }
                        }

                        var iByteBuffer       = bufferUsed;
                        var trimmedByteBuffer = new byte[bufferUsed];
                        Array.Copy(inputByteBuffer, trimmedByteBuffer, iByteBuffer);

                        var sha1HashDual = new SHA1CryptoServiceProvider();
                        var hash         = BitConverter.ToString(sha1HashDual.ComputeHash(trimmedByteBuffer)).Replace("-", "");
                        buffer.SetString(outputColumnInfos[0].bufferColumnIndex, hash);

                        if (!isError)
                        {
                            buffer.DirectRow(defaultOutputId);
                        }
                    }
                }
            }
        }
Example #19
0
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            int errorOutputID = -1;
            int errorOutputIndex = -1;
            int GoodOutputId = -1;
            IDTSInput100 inp = ComponentMetaData.InputCollection.GetObjectByID(inputID);
            #region Output IDs
            GetErrorOutputInfo(ref errorOutputID, ref errorOutputIndex);
            // There is an error output defined
            errorOutputID = ComponentMetaData.OutputCollection["RSErrors"].ID;
            GoodOutputId = ComponentMetaData.OutputCollection["RSout"].ID;
            #endregion

            while (buffer.NextRow())
            {
                // Check if we have columns to process
                if (_inputColumnInfos.Length == 0)
                {
                    // We do not have to have columns. This is a Sync component so the
                    // rows will flow through regardless. Could expand Validate to check
                    // for columns in the InputColumnCollection
                    buffer.DirectRow(GoodOutputId);
                }
                else
                {
                    try
                    {
                        for (int x = 0; x < _inputColumnInfos.Length; x++)
                        {
                            ColumnInfo columnInfo = _inputColumnInfos[x];
                            if (!buffer.IsNull(columnInfo.bufferColumnIndex))
                            {
                                // Get value as character array
                                char[] chars = buffer.GetString(columnInfo.bufferColumnIndex).ToString().ToCharArray();
                                // Reverse order of characters in array
                                Array.Reverse(chars);
                                // Reassemble reversed value as string
                                string s = new string(chars);
                                // Set output value in buffer
                                buffer.SetString(columnInfo.bufferColumnIndex, s);
                            }
                        }
                        buffer.DirectRow(GoodOutputId);
                    }
                    catch (Exception ex)
                    {
                        switch (inp.ErrorRowDisposition)
                        {
                            case DTSRowDisposition.RD_RedirectRow:
                                buffer.DirectErrorRow(errorOutputID, 0, buffer.CurrentRow);
                                break;

                            case DTSRowDisposition.RD_FailComponent:
                                throw new Exception("Error processing " + ex.Message);
                            case DTSRowDisposition.RD_IgnoreFailure:
                                buffer.DirectRow(GoodOutputId);
                                break;
                        }
                    }
                }
            }
        }
Example #20
0
        /// <summary>
        /// Called when a PipelineBuffer is passed to the component.
        /// </summary>
        /// <param name="inputID">The ID of the Input that the buffer contains rows for.</param>
        /// <param name="buffer">The PipelineBuffer containing the columns defined in the IDTSInput100.</param>
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (!buffer.EndOfRowset)
            {
                IDTSInput100 input = ComponentMetaData.InputCollection.GetObjectByID(inputID);

                var errorOutputID    = -1;
                var errorOutputIndex = -1;
                var defaultOutputId  = -1;

                GetErrorOutputInfo(ref errorOutputID, ref errorOutputIndex);


                defaultOutputId = errorOutputIndex == 0 ? ComponentMetaData.OutputCollection[1].ID : ComponentMetaData.OutputCollection[0].ID;


                while (buffer.NextRow())
                {
                    /// If the inputColumnInfos array has zero dimensions, then
                    /// no input columns have been selected for the component.
                    /// Direct the row to the default output.
                    if (inputColumnInfos.Length == 0)
                    {
                        buffer.DirectRow(defaultOutputId);
                    }
                    else
                    {
                        var isError         = false;
                        var inputByteBuffer = new byte[1000];
                        var bufferUsed      = 0;
                        var nullHandling    = String.Empty;

                        foreach (var columnToProcessID in inputColumnInfos.Select(info => info.bufferColumnIndex))
                        {
                            if (!buffer.IsNull(columnToProcessID))
                            {
                                nullHandling += "N";
                                switch (buffer.GetColumnInfo(columnToProcessID).DataType)
                                {
                                case DataType.DT_BOOL:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetBoolean(columnToProcessID));
                                    break;

                                case DataType.DT_IMAGE:
                                    uint blobLength = buffer.GetBlobLength(columnToProcessID);
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetBlobData(columnToProcessID, 0, (int)blobLength));
                                    nullHandling += blobLength.ToString(CultureInfo.InvariantCulture);
                                    break;

                                case DataType.DT_BYTES:
                                    byte[] bytesFromBuffer = buffer.GetBytes(columnToProcessID);
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, bytesFromBuffer);
                                    nullHandling += bytesFromBuffer.GetLength(0).ToString(CultureInfo.InvariantCulture);
                                    break;

                                case DataType.DT_CY:
                                case DataType.DT_DECIMAL:
                                case DataType.DT_NUMERIC:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetDecimal(columnToProcessID));
                                    break;

//#if SQL2005
//#else
                                //case DataType.DT_DBTIMESTAMPOFFSET:
                                //    DateTimeOffset dateTimeOffset = buffer.GetDateTimeOffset(columnToProcessID);
                                //    Utility.Append(ref inputByteBuffer, ref bufferUsed, dateTimeOffset);
                                //    break;
                                case DataType.DT_DBDATE:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetDate(columnToProcessID), millisecondHandling);
                                    break;

//#endif
                                case DataType.DT_DATE:
                                case DataType.DT_DBTIMESTAMP:
#if SQL2005
#else
                                case DataType.DT_DBTIMESTAMP2:
                                case DataType.DT_FILETIME:
#endif
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetDateTime(columnToProcessID), millisecondHandling);
                                    break;

#if SQL2005
#else
                                case DataType.DT_DBTIME:
                                case DataType.DT_DBTIME2:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetTime(columnToProcessID));
                                    break;
#endif
                                case DataType.DT_GUID:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetGuid(columnToProcessID));
                                    break;

                                case DataType.DT_I1:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetSByte(columnToProcessID));
                                    break;

                                case DataType.DT_I2:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetInt16(columnToProcessID));
                                    break;

                                case DataType.DT_I4:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetInt32(columnToProcessID));
                                    break;

                                case DataType.DT_I8:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetInt64(columnToProcessID));
                                    break;

                                case DataType.DT_NTEXT:
                                case DataType.DT_STR:
                                case DataType.DT_TEXT:
                                case DataType.DT_WSTR:
                                    String stringFromBuffer = buffer.GetString(columnToProcessID);
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, stringFromBuffer, Encoding.UTF8);
                                    nullHandling += stringFromBuffer.Length.ToString();
                                    break;

                                case DataType.DT_R4:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetSingle(columnToProcessID));
                                    break;

                                case DataType.DT_R8:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetDouble(columnToProcessID));
                                    break;

                                case DataType.DT_UI1:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetByte(columnToProcessID));
                                    break;

                                case DataType.DT_UI2:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetUInt16(columnToProcessID));
                                    break;

                                case DataType.DT_UI4:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetUInt32(columnToProcessID));
                                    break;

                                case DataType.DT_UI8:
                                    Utility.Append(ref inputByteBuffer, ref bufferUsed, buffer.GetUInt64(columnToProcessID));
                                    break;

                                case DataType.DT_EMPTY:
                                case DataType.DT_NULL:
                                default:
                                    break;
                                }
                            }
                            else
                            {
                                nullHandling += "Y";
                            }
                        }

                        Utility.Append(ref inputByteBuffer, ref bufferUsed, nullHandling, Encoding.UTF8);

                        var sha1HashDual      = new SHA1CryptoServiceProvider();
                        var fhash             = sha1HashDual.ComputeHash(inputByteBuffer);
                        var reverseByteBuffer = inputByteBuffer.Reverse().ToArray();
                        var rhash             = sha1HashDual.ComputeHash(reverseByteBuffer);

                        var hash1 = BitConverter.ToString(fhash).Replace("-", ""); // + "~" + BitConverter.ToString(rhash);
                        var hash2 = BitConverter.ToString(rhash).Replace("-", "");
                        buffer.SetString(outputColumnInfos[0].bufferColumnIndex, hash1);
                        buffer.SetString(outputColumnInfos[1].bufferColumnIndex, hash2);
                        //buffer.SetInt16(outputColumnInfos[2].bufferColumnIndex, (Int16)(Math.Abs(BitConverter.ToInt16(fhash, 0)) % noOfPartitions));

                        /// Finished processing each of the columns in this row.
                        /// If an error occurred and the error output is configured, then the row has already been directed to the error output, if configured.
                        /// If not, then direct the row to the default output.
                        if (!isError)
                        {
                            buffer.DirectRow(defaultOutputId);
                        }
                    }
                }
            }
        }