/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

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