public override void PreExecute() { // STEP 1= // Destination file management /* 1.1: gets the filename, test if the file exist (and delete it )*/ this.FileName = this.ComponentMetaData.CustomPropertyCollection[Const_FileName_AttributeName].Value.ToString(); if (System.IO.File.Exists(this.FileName)) { System.IO.File.Delete(this.FileName); } /*1.2: Creates the XmlWriter */ XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = Encoding.UTF8; xmlSettings.Indent = true; this.Xml = XmlWriter.Create(this.FileName, xmlSettings); /*1.3: Writes the initial headers */ Xml.WriteStartDocument(true); Xml.WriteStartElement(_Xml_RootTag); base.PreExecute(); // STEP 2= // Gathers information on columns and place it into a ColumnInformation Array IDTSInput90 input = ComponentMetaData.InputCollection[0]; colInfos = new ColumnInformation[input.InputColumnCollection.Count]; for (int i = 0; i < input.InputColumnCollection.Count; i++) { ColumnInformation colInfo = new ColumnInformation(); colInfo.ColumnName = input.InputColumnCollection[i].Name; colInfo.BufferIndex = BufferManager.FindColumnByLineageID(input.Buffer, input.InputColumnCollection[i].LineageID); colInfo.DataType = input.InputColumnCollection[i].DataType; colInfos[i] = colInfo; } }
using System; using System.Collections.Generic; using System.Text; using Microsoft.SqlServer.Dts.Runtime.Wrapper; [assembly: CLSCompliant(false)] namespace BILab.Technical.BI.ETL.Pipeline.Common { public class ColumnInformation { private int _bufferIndex; public int BufferIndex { get { return _bufferIndex; } set { _bufferIndex = value; } } private string columnName; public string ColumnName { get { return columnName; } set { columnName = value; } } private DataType _dataType; public DataType DataType { get { return _dataType; } set { _dataType = value; } } } }
int FindColumnByLineageID ( int hBufferType, /* Id du buffer concern, ici input.Buffer */ int nLineageID /* clef/id de la colonne identifer */ )
public override void ProcessInput(int inputID, PipelineBuffer buffer) { int colIt; string text; string columnName =""; int retain = -1; Type[] types = new Type[0]; ; if (buffer.EndOfRowset == false) { try { while (buffer.NextRow()) { this.Xml.WriteStartElement(_Xml_RowTag); if (!buffer.IsNull(colInfos[colIt].BufferIndex)) { text = buffer[colInfos[colIt].BufferIndex].ToString(); } else { text = ""; } columnName = colInfos[colIt].ColumnName; this.Xml.WriteElementString(columnName, text); retain = colIt; //this.Xml.WriteStartElement(colInfos[colIt].ColumnName); //this.Xml.WriteEndElement(); } this.Xml.WriteEndElement(); LineCounter++; } } catch (System.Exception ex) { bool cancel = false; StringBuilder sb = new StringBuilder(); sb.Append("Caught Exception : "); sb.Append(ex.Message); sb.Append(" - iteration : "); sb.Append(retain); sb.Append(" - Nb of columns : "); sb.Append(colInfos.Length); ComponentMetaData.FireError(0, ComponentMetaData.Name, sb.ToString(), string.Empty, 0, out cancel); throw new ApplicationException(Resource.CouldNotProcessInput); } } }
public override void PostExecute() { if ((bool)this.ComponentMetaData.CustomPropertyCollection[Const_OutputNbOfRows_AttributeName].Value) { Xml.WriteElementString(_Xml_NbOfRowsTag, Convert.ToString(this.LineCounter)); Xml.WriteEndElement(); } Xml.WriteEndDocument(); Xml.Close(); base.PostExecute(); }