コード例 #1
0
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            PrepareType(_entity);
            FluentFile engine;
            var        inserts = 0;

            try {
                engine = new FluentFile(Type)
                {
                    Encoding = _connection.Encoding.Equals("utf-8w/obom") ?
                               new UTF8Encoding(false) :
                               Encoding.GetEncoding(_connection.Encoding)
                };
            } catch (Exception ex) {
                throw new TransformalizeException(Logger, EntityName, ex.Message);
            }

            if (!_connection.Header.Equals(string.Empty))
            {
                PrepareHeader(_entity);
                engine.HeaderText = HeaderText;
            }

            if (!_connection.Footer.Equals(string.Empty))
            {
                PrepareFooter(_entity);
                engine.FooterText = FooterText;
            }

            using (var file = engine.To(FileInfo.FullName)) {
                foreach (var row in rows)
                {
                    foreach (var field in _stringFields)
                    {
                        var value = row[field].ToString();
                        if (_isCsv)
                        {
                            row[field] = value.Replace("\r\n", "\n");
                        }
                        else if (_connection.Delimiter != SPACE)
                        {
                            row[field] = value.Replace(_connection.Delimiter, SPACE);
                        }
                    }
                    foreach (var field in _mapFields)
                    {
                        row[field.Identifier] = row[field.Alias];
                    }
                    var record = row.ToObject(Type);
                    file.Write(record);
                    inserts++;
                }
            }
            _entity.Inserts = inserts;
            yield break;
        }
コード例 #2
0
ファイル: UserFullWrite.cs プロジェクト: thiagottt/etl
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            FluentFile engine = FluentFile.For <UserFullRecord>();

            engine.HeaderText = "Id\tName\tAddress";
            using (FileEngine file = engine.To(filePath))
            {
                foreach (Row row in rows)
                {
                    file.Write(row.ToObject <UserFullRecord>());

                    //pass through rows if needed for another later operation
                    yield return(row);
                }
            }
        }
コード例 #3
0
ファイル: WriteUsersToFile.cs プロジェクト: xliang/rhino-etl
        /// <summary>
        /// Executes this operation
        /// </summary>
        /// <param name="rows">The rows.</param>
        /// <returns></returns>
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            FluentFile engine = FluentFile.For <UserRecord>();

            engine.HeaderText = "Id\tName\tEmail";
            using (FileEngine file = engine.To("users.txt"))
            {
                foreach (Row row in rows)
                {
                    UserRecord record = new UserRecord();

                    record.Id    = (int)row["id"];
                    record.Name  = (string)row["name"];
                    record.Email = (string)row["email"];

                    file.Write(record);
                }
            }
            yield break;
        }
コード例 #4
0
        protected override async Task ExecuteYield(IAsyncEnumerable <Row> rows, AsyncEnumerator <Row> .Yield yield,
                                                   CancellationToken cancellationToken = default)
        {
            FluentFile engine = FluentFile.For <UserRecord>();

            engine.HeaderText = "Id\tName\tEmail";
            using (FileEngine file = engine.To("users.txt"))
            {
                await rows.ForEachAsync(row =>
                {
                    UserRecord record = new UserRecord();

                    record.Id    = (int)row["id"];
                    record.Name  = (string)row["name"];
                    record.Email = (string)row["email"];

                    file.Write(record);
                }, cancellationToken);
            }
            @yield.Break();
        }
コード例 #5
0
        public override IEnumerable<Row> Execute(IEnumerable<Row> rows) {

            PrepareType(_entity);
            FluentFile engine;
            var inserts = 0;

            try {
                engine = new FluentFile(Type) {
                    Encoding = _connection.Encoding.Equals("utf-8w/obom") ?
                        new UTF8Encoding(false) :
                        Encoding.GetEncoding(_connection.Encoding)
                };
            } catch (Exception ex) {
                throw new TransformalizeException(Logger, EntityName, ex.Message);
            }

            if (!_connection.Header.Equals(string.Empty)) {
                PrepareHeader(_entity);
                engine.HeaderText = HeaderText;
            }

            if (!_connection.Footer.Equals(string.Empty)) {
                PrepareFooter(_entity);
                engine.FooterText = FooterText;
            }

            using (var file = engine.To(FileInfo.FullName)) {
                foreach (var row in rows) {
                    foreach (var field in _stringFields) {
                        var value = row[field].ToString();
                        if (_isCsv) {
                            row[field] = value.Replace("\r\n", "\n");
                        } else if (_connection.Delimiter != SPACE) {
                            row[field] = value.Replace(_connection.Delimiter, SPACE);
                        }
                    }
                    foreach (var field in _mapFields) {
                        row[field.Identifier] = row[field.Alias];
                    }
                    var record = row.ToObject(Type);
                    file.Write(record);
                    inserts++;
                }
            }
            _entity.Inserts = inserts;
            yield break;
        }