/// <summary> /// Executa o evento de linha inválida /// </summary> /// <param name="inputRow">linha atual, que causou a invalidação</param> /// <param name="rowValidation">Resultado da validação</param> void ITransform.RaiseRowInvalid(IRow inputRow, RowValidation rowValidation) { if (RowInvalid != null) { RowInvalid(inputRow, rowValidation); } }
/// <summary> /// Executa o processo de transformação do objeto e retorna o resultado transformado /// </summary> /// <returns></returns> public Transform Execute() { if (TransformMap.Count == 0) { throw new InvalidOperationException("No mappings defined."); } if (this.Start != null) { this.Start(this); } try { Source.InTransformContext(this, () => { _dest.InTransformContext(this, () => { foreach (var inputRow in Source.Rows) { RowValidation rowValidation = new RowValidation(); DoRowValidation(inputRow, rowValidation); if (rowValidation.HasErrors) { if (this.RowInvalid != null) { this.RowInvalid(inputRow, rowValidation); } } else { RowOperation rowOp = this.GetRowOperation(inputRow); if (rowOp != RowOperation.Ignore) { DictionaryRow transformedRow = new DictionaryRow(); foreach (var mapping in TransformMap) { object rowValue = inputRow[mapping.Key]; Func <object, object> transformFunc; if (TransformFuncs.TryGetValue(mapping.Key, out transformFunc)) { rowValue = transformFunc(rowValue); } transformedRow[mapping.Value] = rowValue; } ProcessTransformedRow(rowOp, transformedRow); } } } }); }); } catch (Exception exTransform) { if (this.Error != null) { this.Error(this, exTransform); } else { throw exTransform; } } if (this.Complete != null) { this.Complete(this); } return(this); }