PageRenderTime 224ms CodeModel.GetById 121ms app.highlight 3ms RepoModel.GetById 98ms app.codeStats 0ms

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