public override void PrimeOutput(int outputs, int[] outputIDs, PipelineBuffer[] buffers) { //identify buffers PipelineBuffer errorBuffer = null; PipelineBuffer defaultBuffer = null; for (int x = 0; x < outputs; x++) { if (outputIDs[x] == errorOutputID) errorBuffer = buffers[x]; else defaultBuffer = buffers[x]; } //get ogrlayer and ogrlayer feature definition Layer OGRLayer; bool isSQLLayer = (!(ComponentMetaData.CustomPropertyCollection["SQL Statement"].Value == null || ComponentMetaData.CustomPropertyCollection["SQL Statement"].Value.ToString() == string.Empty)); if (isSQLLayer) { OGRLayer = getSQLLayer(); } else { OGRLayer = getLayer(); } Feature OGRFeature; FeatureDefn OGRFeatureDef = OGRLayer.GetLayerDefn(); //initialize columnInfo object columnInfo ci = new columnInfo(); //for each row in ogrlayer add row to output buffer while ((OGRFeature = OGRLayer.GetNextFeature()) != null) { try { defaultBuffer.AddRow(); //set buffer column values for (int i = 0; i < this.columnInformation.Count; i++) { ci = (columnInfo)this.columnInformation[i]; if (ci.geom) { Geometry geom = OGRFeature.GetGeometryRef(); if (geom != null) { byte[] geomBytes = new byte[geom.WkbSize()]; geom.ExportToWkb(geomBytes); defaultBuffer.AddBlobData(ci.bufferColumnIndex, geomBytes); } } else { int OGRFieldIndex = OGRFeatureDef.GetFieldIndex(ci.columnName); FieldDefn OGRFieldDef = OGRFeatureDef.GetFieldDefn(OGRFieldIndex); FieldType OGRFieldType = OGRFieldDef.GetFieldType(); //declare datetime variables int pnYear, pnMonth, pnDay, pnHour, pnMinute, pnSecond, pnTZFlag; DateTime dt; TimeSpan ts; switch (OGRFieldType) { //case FieldType.OFTBinary: // break; case FieldType.OFTDate: OGRFeature.GetFieldAsDateTime(OGRFieldIndex, out pnYear, out pnMonth, out pnDay, out pnHour, out pnMinute, out pnSecond, out pnTZFlag); dt = new DateTime(pnYear,pnMonth,pnDay); defaultBuffer.SetDate(ci.bufferColumnIndex, dt); break; case FieldType.OFTDateTime: OGRFeature.GetFieldAsDateTime(OGRFieldIndex, out pnYear, out pnMonth, out pnDay, out pnHour, out pnMinute, out pnSecond, out pnTZFlag); dt = new DateTime(pnYear,pnMonth,pnDay,pnHour,pnMinute,pnSecond); //set time zone? defaultBuffer.SetDateTime(ci.bufferColumnIndex, dt); break; case FieldType.OFTInteger: defaultBuffer.SetInt32(ci.bufferColumnIndex, OGRFeature.GetFieldAsInteger(OGRFieldIndex)); break; case FieldType.OFTReal: defaultBuffer.SetDouble(ci.bufferColumnIndex, OGRFeature.GetFieldAsDouble(OGRFieldIndex)); break; case FieldType.OFTTime: OGRFeature.GetFieldAsDateTime(OGRFieldIndex, out pnYear, out pnMonth, out pnDay, out pnHour, out pnMinute, out pnSecond, out pnTZFlag); ts = new TimeSpan(pnHour,pnMinute,pnSecond); defaultBuffer.SetTime(ci.bufferColumnIndex, ts); break; case FieldType.OFTString: default: defaultBuffer.SetString(ci.bufferColumnIndex, OGRFeature.GetFieldAsString(OGRFieldIndex)); break; } } } } catch (Exception ex) { //redirect to error buffer if (ci.errorDisposition == DTSRowDisposition.RD_RedirectRow) { // Add a row to the error buffer. errorBuffer.AddRow(); // Set the error information. int errorCode = System.Runtime.InteropServices.Marshal.GetHRForException(ex); errorBuffer.SetErrorInfo(errorOutputID, errorCode, ci.lineageID); // Remove the row that was added to the default buffer. defaultBuffer.RemoveRow(); } //fail component else if (ci.errorDisposition == DTSRowDisposition.RD_FailComponent || ci.errorDisposition == DTSRowDisposition.RD_NotUsed) { ComponentMetaData.FireError(0, "primeoutput failure", ex.ToString(), string.Empty, 0, out cancel); throw; } } } //set end of rowset for buffers if (defaultBuffer != null) defaultBuffer.SetEndOfRowset(); if (errorBuffer != null) errorBuffer.SetEndOfRowset(); //clean up layer object if (isSQLLayer) { this.OGRDataSource.ReleaseResultSet(OGRLayer); } }
public override void PreExecute() { //get default output IDTSOutput100 defaultOutput = null; this.GetErrorOutputInfo(ref errorOutputID, ref errorOutputIndex); foreach (IDTSOutput100 output in ComponentMetaData.OutputCollection) { if (output.ID != errorOutputID) defaultOutput = output; } //for each output column add columnInfo object to columnInformation arrayList foreach (IDTSOutputColumn100 col in defaultOutput.OutputColumnCollection) { columnInfo ci = new columnInfo(); ci.bufferColumnIndex = BufferManager.FindColumnByLineageID(defaultOutput.Buffer, col.LineageID); ci.lineageID = col.LineageID; ci.columnName = col.Name; ci.errorDisposition = col.ErrorRowDisposition; ci.truncationDisposition = col.TruncationRowDisposition; if (col.Name == (string)ComponentMetaData.CustomPropertyCollection["Geometry Column"].Value) { ci.geom = true; } else { ci.geom = false; } this.columnInformation.Add(ci); } }