PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Rhino.Etl.Tests/UsingDAL/ReadUsersFromFileDynamic.cs

http://github.com/ayende/rhino-etl
C# | 38 lines | 33 code | 3 blank | 2 comment | 0 complexity | 30d9329f108794c4a6e87e07bfec9a7d MD5 | raw file
 1using System;
 2using FileHelpers;
 3using FileHelpers.RunTime;
 4
 5namespace Rhino.Etl.Tests.UsingDAL
 6{
 7    using System.Collections.Generic;
 8    using Core;
 9    using Rhino.Etl.Core.Files;
10    using Rhino.Etl.Core.Operations;
11    using System.Linq;
12
13    public class ReadUsersFromFileDynamic : AbstractOperation
14    {
15        private Type _tblClass;
16        public ReadUsersFromFileDynamic()
17        {
18            var userRecordClassBuilder = new DelimitedClassBuilder("UserRecord","\t");
19            userRecordClassBuilder.IgnoreFirstLines = 1;
20            userRecordClassBuilder.AddField("Id", typeof(Int32));
21            userRecordClassBuilder.AddField("Name", typeof(String));
22            userRecordClassBuilder.AddField("Email", typeof(String));
23            _tblClass = userRecordClassBuilder.CreateRecordClass();
24        }
25
26        public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
27        {
28            var file = new FileHelperEngine(_tblClass);
29            //var ary = new[] {"one", "two", "three"};
30            //var items = from a in ary select a;
31            var items = file.ReadFile("users.txt");
32            foreach (object obj in items)
33            {
34                yield return Row.FromObject(obj);
35            }
36        }
37    }
38}