private void InsertEntity(Object obj)
        {
            DataPerThread data = obj as DataPerThread;

            if (data != null)
            {
                try
                {
                    _Container.InsertEntity(data.Entity);

                    // Add to perf counter information
                    ComponentMetaData.IncrementPipelinePerfCounter(DTS_PIPELINE_CTR_ROWSWRITTEN, 1);
                }
                catch (Exception e)
                {
                    // Redirect to error output
                    data.Buffer.DirectErrorRow(data.Entity.Row, _errorOutputId, 1, _idColumnIndex);

                    string errMessage = e.Message;
                    if (e.InnerException != null)
                    {
                        errMessage = string.Format(CultureInfo.CurrentUICulture, "{0}. Inner: {1}", e.Message, e.InnerException.Message);
                    }
                    string msg = string.Format(CultureInfo.CurrentUICulture, "Failed to insert entity '{0}'. Error: '{1}'", data.Entity.Id, errMessage);
                    ComponentMetaData.FireInformation(0, "SSDS Destination", msg, string.Empty, 0, ref _cancel);
                }

                // release the references
                data.Clear();

                // trigger that the thread work is complete
                data.Set();
            }
        }
        /// <summary>
        /// Add the rows from the input buffer to the to the Container
        /// </summary>
        /// <param name="inputID">The ID of the IDTSInput100</param>
        /// <param name="buffer">The PipelineBuffer containing the records to process</param>
        public override void ProcessInput(int inputID, PipelineBuffer buffer)
        {
            while (buffer.NextRow() == true)
            {
                // First we determine the ID
                string id = string.Empty;
                if (_CreateNewID)
                {
                    id = Guid.NewGuid().ToString();
                }
                else
                {
                    if (!buffer.IsNull(_idColumnIndex))
                    {
                        id = buffer[_idColumnIndex].ToString();
                    }
                    else
                    {
                        ComponentMetaData.FireError(0, ComponentMetaData.Name, string.Format("The ID column '{0}' has a NULL value", _idColumnName), string.Empty, 0, out this._cancel);
                        buffer.DirectErrorRow(_errorOutputId, 1, _idColumnId);
                        continue;
                    }
                }

                if (string.IsNullOrEmpty(id))
                {
                    ComponentMetaData.FireError(0, ComponentMetaData.Name, string.Format("Null or empty value from ID Column '{0}'", _idColumnName), string.Empty, 0, out this._cancel);
                    buffer.DirectErrorRow(_errorOutputId, 1, _idColumnId);
                    continue;
                }

                // Now fill in the rest of the entity information
                Entity entity = new Entity(id, buffer.CurrentRow);
                entity.Kind = _EntityKind;

                // All the other properties
                foreach (InputColumnInfo col in _inputColumnInfo)
                {
                    object value = col.GetColumnValue(buffer);
                    if (value != null)
                    {
                        entity.Properties[col.Name] = value;
                    }
                }

                // Perform the insert
                if (_multithread)
                {
                    DataPerThread threadData = new DataPerThread(entity, buffer);
                    _threadPool.QueueUserWorkItem(new WaitCallback(InsertEntity), threadData);
                }
                else
                {
                    _Container.InsertEntity(entity);
                }

                // this.ComponentMetaData.FireInformation(0, "SSDS Destination", "Sent Entity with ID:" + obj.Id, string.Empty, 0, ref _cancel);
            }

            if (_multithread)
            {
                // Wait for all of our work items to finish processing
                _threadPool.WaitOne();
            }
        }
Beispiel #3
0
		/// <summary>
		/// Add the rows from the input buffer to the to the Container
		/// </summary>
		/// <param name="inputID">The ID of the IDTSInput100</param>
		/// <param name="buffer">The PipelineBuffer containing the records to process</param>
		public override void ProcessInput(int inputID, PipelineBuffer buffer)
		{
			while (buffer.NextRow() == true)
			{
				// First we determine the ID
				string id = string.Empty;
                if (_CreateNewID)
                {
                    id = Guid.NewGuid().ToString();
                }
                else
                {
                    if (!buffer.IsNull(_idColumnIndex))
                    {
                        id = buffer[_idColumnIndex].ToString();
                    }
                    else
                    {
                        ComponentMetaData.FireError(0, ComponentMetaData.Name, string.Format("The ID column '{0}' has a NULL value", _idColumnName), string.Empty, 0, out this._cancel);
                        buffer.DirectErrorRow(_errorOutputId, 1, _idColumnId);
                        continue;
                    }
                }

                if (string.IsNullOrEmpty(id))
                {
                    ComponentMetaData.FireError(0, ComponentMetaData.Name, string.Format("Null or empty value from ID Column '{0}'", _idColumnName), string.Empty, 0, out this._cancel);
                    buffer.DirectErrorRow(_errorOutputId, 1, _idColumnId);
                    continue;
                }

				// Now fill in the rest of the entity information
				Entity entity = new Entity(id, buffer.CurrentRow);
				entity.Kind = _EntityKind;

				// All the other properties
				foreach (InputColumnInfo col in _inputColumnInfo)
				{
                    object value = col.GetColumnValue(buffer);
                    if (value != null)
                    {
                        entity.Properties[col.Name] = value;
                    }
				}

                // Perform the insert
                if (_multithread)
                {
                    DataPerThread threadData = new DataPerThread(entity, buffer);
                    _threadPool.QueueUserWorkItem(new WaitCallback(InsertEntity), threadData);
                }
                else
                {
                    _Container.InsertEntity(entity);
                }

                // this.ComponentMetaData.FireInformation(0, "SSDS Destination", "Sent Entity with ID:" + obj.Id, string.Empty, 0, ref _cancel);
			}

            if (_multithread)
            {
                // Wait for all of our work items to finish processing
                _threadPool.WaitOne();
            }
		}