/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

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