PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Rhino.Etl.Core/Files/FileEngine.cs

http://github.com/ayende/rhino-etl
C# | 81 lines | 42 code | 8 blank | 31 comment | 0 complexity | b871ea9b48762246af544a9f028851b0 MD5 | raw file
 1namespace Rhino.Etl.Core.Files
 2{
 3    using System;
 4    using System.Collections;
 5    using System.Text;
 6    using FileHelpers;
 7
 8    /// <summary>
 9    /// Adapter class to facilitate the nicer syntax
10    /// </summary>
11    public class FileEngine : IDisposable, IEnumerable
12    {
13        private readonly FileHelperAsyncEngine engine;
14
15        /// <summary>
16        /// Initializes a new instance of the <see cref="FileEngine"/> class.
17        /// </summary>
18        /// <param name="engine">The engine.</param>
19        public FileEngine(FileHelperAsyncEngine engine)
20        {
21            this.engine = engine;
22        }
23
24        /// <summary>
25        /// Writes the specified object ot the file
26        /// </summary>
27        /// <param name="t">The t.</param>
28        public void Write(object t)
29        {
30            engine.WriteNext(t);
31        }
32
33        /// <summary>
34        /// Set the behavior on error
35        /// </summary>
36        /// <param name="errorMode">The error mode.</param>
37        public FileEngine OnError(ErrorMode errorMode)
38        {
39            engine.ErrorManager.ErrorMode = errorMode;
40            return this;
41        }
42
43        /// <summary>
44        /// Gets a value indicating whether this instance has errors.
45        /// </summary>
46        public bool HasErrors
47        {
48            get { return engine.ErrorManager.HasErrors;  }
49        }
50
51        /// <summary>
52        /// Outputs the errors to the specified file
53        /// </summary>
54        /// <param name="file">The file.</param>
55        public void OutputErrors(string file)
56        {
57            engine.ErrorManager.SaveErrors(file);
58        }
59
60        /// <summary>
61        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
62        /// </summary>
63        public void Dispose()
64        {
65            IDisposable d = engine;
66            d.Dispose();
67        }
68
69        /// <summary>
70        /// Returns an enumerator that iterates through a collection.
71        /// </summary>
72        /// <returns>
73        /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
74        /// </returns>
75        public IEnumerator GetEnumerator()
76        {
77            IEnumerable e = engine;
78            return e.GetEnumerator();
79        }
80    }
81}