Esempio n. 1
0
        private bool HasAged(DictionaryRow entry, TimeSpan maxAge)
        {
            var entryAge = (entry != null) ?
                           DateTime.UtcNow.Subtract(entry.DateModified ?? entry.DateCreated) :
                           TimeSpan.MaxValue;

            return(entryAge > maxAge);
        }
Esempio n. 2
0
        /// <summary>
        /// Executa ação definida para o registro no objeto de destino
        /// </summary>
        /// <param name="rowOp">Operação que deverás er executada</param>
        /// <param name="transformedRow">Linha que foi transformada</param>
        public void ProcessTransformedRow(RowOperation rowOp, DictionaryRow transformedRow)
        {
            if (this.RowBeforeProcess != null)
            {
                this.RowBeforeProcess(transformedRow, rowOp);
            }

            try
            {
                switch (rowOp)
                {
                case RowOperation.Process:
                    _dest.Process(transformedRow);
                    break;

                case RowOperation.Insert:
                    _dest.Insert(transformedRow);
                    break;

                case RowOperation.Update:
                    _dest.Update(transformedRow);
                    break;

                case RowOperation.Delete:
                    _dest.Delete(transformedRow);
                    break;
                }

                if (this.RowSuccess != null && rowOp != RowOperation.Ignore)
                {
                    this.RowSuccess(transformedRow, rowOp);
                }
            }
            catch (Exception exRow)
            {
                if (this.RowError != null)
                {
                    this.RowError(transformedRow, rowOp, exRow);
                }
                else
                {
                    throw exRow;
                }
            }

            if (this.RowAfterProcess != null)
            {
                this.RowAfterProcess(transformedRow, rowOp);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Indica que está no contexto de transformação do objeto
        /// </summary>
        /// <param name="context">Contexto de transformação</param>
        /// <param name="action">Ação que será executada para a transformação</param>
        protected override void InTransformContext(Unimake.ETL.ITransform context, System.Action action)
        {
            ObjectResult = new T();

            foreach (var inputRow in context.Source.Rows)
            {
                RowValidation rowValidation = new RowValidation();
                context.DoRowValidation(inputRow, rowValidation);
                if (rowValidation.HasErrors)
                {
                    context.RaiseRowInvalid(inputRow, rowValidation);
                }
                else
                {
                    RowOperation rowOp = context.GetRowOperation(inputRow);
                    if (rowOp != RowOperation.Ignore)
                    {
                        DictionaryRow transformedRow = new DictionaryRow();
                        foreach (var mapping in context.TransformMap)
                        {
                            object rowValue = inputRow[mapping.Key];
                            Func <object, object> transformFunc;
                            if (context.TransformFuncs.TryGetValue(mapping.Key, out transformFunc))
                            {
                                rowValue = transformFunc(rowValue);
                            }
                            transformedRow[mapping.Value] = rowValue;

                            //aqui temos que preencher o objeto com suas propriedades
                            SetValue(mapping, rowValue);
                        }

                        context.ProcessTransformedRow(rowOp, transformedRow);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <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);
        }
 public DictionaryRowChangeEvent(DictionaryRow row, global::System.Data.DataRowAction action) {
     this.eventRow = row;
     this.eventAction = action;
 }
 public void RemoveDictionaryRow(DictionaryRow row) {
     this.Rows.Remove(row);
 }
 public void AddDictionaryRow(DictionaryRow row) {
     this.Rows.Add(row);
 }