/Rhino.Etl.Core/EtlProcessBase.cs

http://github.com/ayende/rhino-etl · C# · 80 lines · 38 code · 8 blank · 34 comment · 0 complexity · 43214109bf9042cad811ef082a8fd474 MD5 · raw file

  1. namespace Rhino.Etl.Core
  2. {
  3. using System.Collections.Generic;
  4. using Operations;
  5. /// <summary>
  6. /// Base class for etl processes, provider registration and management
  7. /// services for the pipeline
  8. /// </summary>
  9. /// <typeparam name="TDerived">The type of the derived.</typeparam>
  10. public class EtlProcessBase<TDerived> : WithLoggingMixin
  11. where TDerived : EtlProcessBase<TDerived>
  12. {
  13. /// <summary>
  14. /// Internal field to indicate if a transaction is used. Defaulting to true.
  15. /// </summary>
  16. private bool useTransaction = true;
  17. /// <summary>
  18. /// Ordered list of the operations in this process that will be added to the
  19. /// operations list after the initialization is completed.
  20. /// </summary>
  21. private readonly List<IOperation> lastOperations = new List<IOperation>();
  22. /// <summary>
  23. /// Ordered list of the operations in this process
  24. /// </summary>
  25. protected readonly List<IOperation> operations = new List<IOperation>();
  26. /// <summary>
  27. /// Gets the name of this instance
  28. /// </summary>
  29. /// <value>The name.</value>
  30. public virtual string Name
  31. {
  32. get { return GetType().Name; }
  33. }
  34. /// <summary>
  35. /// Gets or sets whether we are using a transaction
  36. /// </summary>
  37. /// <value>True or value.</value>
  38. public bool UseTransaction
  39. {
  40. get { return useTransaction; }
  41. set { useTransaction = value; }
  42. }
  43. /// <summary>
  44. /// Registers the specified operation.
  45. /// </summary>
  46. /// <param name="operation">The operation.</param>
  47. public TDerived Register(IOperation operation)
  48. {
  49. operation.UseTransaction = UseTransaction;
  50. operations.Add(operation);
  51. Debug("Register {0} in {1}", operation.Name, Name);
  52. return (TDerived) this;
  53. }
  54. /// <summary>
  55. /// Registers the operation at the end of the operations queue
  56. /// </summary>
  57. /// <param name="operation">The operation.</param>
  58. public TDerived RegisterLast(IOperation operation)
  59. {
  60. lastOperations.Add(operation);
  61. Debug("RegisterLast {0} in {1}", operation.Name, Name);
  62. return (TDerived) this;
  63. }
  64. /// <summary>
  65. /// Merges the last operations to the operations list.
  66. /// </summary>
  67. protected void MergeLastOperationsToOperations()
  68. {
  69. operations.AddRange(lastOperations);
  70. }
  71. }
  72. }