PageRenderTime 22ms CodeModel.GetById 9ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Rhino.Etl.Core/Operations/AbstractOperation.cs

http://github.com/ayende/rhino-etl
C# | 116 lines | 53 code | 14 blank | 49 comment | 0 complexity | 3e03b12675553046c75c8ea2ccc95203 MD5 | raw file
  1namespace Rhino.Etl.Core.Operations
  2{
  3    using System;
  4    using System.Collections.Generic;
  5
  6    /// <summary>
  7    /// Represent a single operation that can occure during the ETL process
  8    /// </summary>
  9    public abstract class AbstractOperation : WithLoggingMixin, IOperation
 10    {
 11        private readonly OperationStatistics statistics = new OperationStatistics();
 12        private bool useTransaction = true;
 13        private IPipelineExecuter pipelineExecuter;
 14
 15        /// <summary>
 16        /// Gets the pipeline executer.
 17        /// </summary>
 18        /// <value>The pipeline executer.</value>
 19        protected IPipelineExecuter PipelineExecuter
 20        {
 21            get { return pipelineExecuter; }
 22        }
 23
 24        /// <summary>
 25        /// Gets the name of this instance
 26        /// </summary>
 27        /// <value>The name.</value>
 28        public virtual string Name
 29        {
 30            get { return GetType().Name; }
 31        }
 32
 33        /// <summary>
 34        /// Gets or sets whether we are using a transaction
 35        /// </summary>
 36        /// <value>True or false.</value>
 37        public bool UseTransaction
 38        {
 39            get { return useTransaction; }
 40            set { useTransaction = value; }
 41        }
 42
 43        /// <summary>
 44        /// Gets the statistics for this operation
 45        /// </summary>
 46        /// <value>The statistics.</value>
 47        public OperationStatistics Statistics
 48        {
 49            get { return statistics; }
 50        }
 51
 52        /// <summary>
 53        /// Occurs when a row is processed.
 54        /// </summary>
 55        public virtual event Action<IOperation, Row> OnRowProcessed = delegate { };
 56
 57        /// <summary>
 58        /// Occurs when all the rows has finished processing.
 59        /// </summary>
 60        public virtual event Action<IOperation> OnFinishedProcessing = delegate { };
 61
 62        /// <summary>
 63        /// Initializes this instance
 64        /// </summary>
 65        /// <param name="pipelineExecuter">The current pipeline executer.</param>
 66        public virtual void PrepareForExecution(IPipelineExecuter pipelineExecuter)
 67        {
 68            this.pipelineExecuter = pipelineExecuter;
 69            Statistics.MarkStarted();
 70        }
 71
 72        /// <summary>
 73        /// Raises the row processed event
 74        /// </summary>
 75        /// <param name="dictionary">The dictionary.</param>
 76        void IOperation.RaiseRowProcessed(Row dictionary)
 77        {
 78            Statistics.MarkRowProcessed();
 79            OnRowProcessed(this, dictionary);
 80        }
 81
 82        /// <summary>
 83        /// Raises the finished processing event
 84        /// </summary>
 85        void IOperation.RaiseFinishedProcessing()
 86        {
 87            Statistics.MarkFinished();
 88            OnFinishedProcessing(this);
 89        }
 90
 91        /// <summary>
 92        /// Gets all errors that occured when running this operation
 93        /// </summary>
 94        /// <returns></returns>
 95        public virtual IEnumerable<Exception> GetAllErrors()
 96        {
 97            return Errors;
 98        }
 99
100        /// <summary>
101        /// Executes this operation
102        /// </summary>
103        /// <param name="rows">The rows.</param>
104        /// <returns></returns>
105        public abstract IEnumerable<Row> Execute(IEnumerable<Row> rows);
106
107        ///<summary>
108        ///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
109        ///</summary>
110        ///<filterpriority>2</filterpriority>
111        public virtual void Dispose()
112        {
113            
114        }
115    }
116}