Example #1
0
        public void Test_ReadWriteCopyCsv()
        {
            using (var testPipeline = new Pipeline())
            {
                var looper = new FileLooper()
                {
                    SourceDirectory = this.testDataPath, FileFilter = @"*.csv"
                };
                testPipeline.Commands.Add(looper);

                var reader = new FlatFileReader()
                {
                    File = "{File}"
                };
                reader.Formatter = new CsvToDataTableFormatter()
                {
                    Separator = ";"
                };
                looper.AddChild(reader);

                reader.AddChild(new TableFilter()
                {
                });
                var writer = new FlatFileWriter()
                {
                    File = this.resultPath + @"pipeline\{FileName}"
                };
                writer.Formatter = new DataTableToCsvFormatter();
                reader.AddChild(writer);

                looper.AddChild(new FileMover()
                {
                    SourceFile = @"{File}", TargetDirectory = this.resultPath + @"Archive", Mode = FileMover.FileMoveModes.Copy
                });
                looper.AddChild(new FileZipper()
                {
                    SourceFile = @"{File}", TargetDirectory = this.resultPath + @"Archive\Zipped", ZipName = "Archive_{yyyyMMdd}.zip", RemoveSourceFile = true
                });

                testPipeline.ExecutePipeline();
            }

            // check
            int sourceFileCount  = Directory.GetFiles(this.testDataPath, @"*.csv", SearchOption.TopDirectoryOnly).Length;
            int targetFileCount  = Directory.GetFiles(this.resultPath + @"pipeline", @"*.csv", SearchOption.TopDirectoryOnly).Length;
            int archiveFileCount = Directory.GetFiles(this.resultPath + @"Archive", @"*.csv", SearchOption.TopDirectoryOnly).Length;
            int zipFileCount     = Directory.GetFiles(this.resultPath + @"Archive\Zipped", @"Archive_*.zip", SearchOption.TopDirectoryOnly).Length;

            Assert.AreEqual(sourceFileCount, targetFileCount);
            Assert.AreEqual(0, archiveFileCount);
            Assert.AreEqual(1, zipFileCount);
        }
Example #2
0
        public void Test_ReadCsv_WriteFixedLength_Cd2()
        {
            using (var testPipeline = new Pipeline())
            {
                var looper = new FileLooper()
                {
                    SourceDirectory = this.testDataPath, FileFilter = @"cd2.csv"
                };
                testPipeline.Commands.Add(looper);

                var reader = new FlatFileReader()
                {
                    File = "{File}"
                };
                reader.Formatter = new CsvToDataTableFormatter()
                {
                    Separator = ";", Enclosure = "\""
                };
                looper.AddChild(reader);

                var formatter = new DataTableToFixedLengthFormatter();
                formatter.FieldDefinitions.Add(new FieldDefinition(new Field("name", 15)));
                formatter.FieldDefinitions.Add(new FieldDefinition(new Field("addr", 25)));
                formatter.FieldDefinitions.Add(new FieldDefinition(new Field("telefon", 10)));

                var writer = new FlatFileWriter()
                {
                    File = this.resultPath + @"{FileName}"
                };
                writer.Formatter = formatter;
                reader.AddChild(writer);

                testPipeline.ExecutePipeline();
            }

            // check
            var sourcelineCount = File.ReadLines(this.testDataPath + @"cd2.csv").Count();
            var targetlineCount = File.ReadLines(this.resultPath + @"cd2.csv").Count();

            Assert.AreEqual(sourcelineCount, targetlineCount);
        }
Example #3
0
        public void Test_SqlTableImport()
        {
            using (var testPipeline = new Pipeline()
            {
                StreamingBlockSize = 20
            })
            {
                var looper = new FileLooper()
                {
                    SourceDirectory = this.resultPath, FileFilter = "mis.*.txt"
                };

                testPipeline.Commands.Add(looper);

                var reader = new FlatFileReader()
                {
                    File      = "{File}",
                    Formatter = new CsvToDataTableFormatter()
                    {
                        Separator = ";"
                    }
                };

                looper.AddChild(reader);

                var tableWriter = new DbTableWriter
                {
                    ConnectionInfo = new OracleNativeDbConnectionInfo()
                    {
                        UserName = "", Password = "", Database = "ORACLE01", Host = "COMPUTER01"
                    },
                    DeleteBefore = false,
                    TableName    = "{DataName}_bak"
                };

                reader.AddChild(tableWriter);

                testPipeline.ExecutePipeline();
            }
        }
Example #4
0
        public void Test_ReadFixedLength_WriteCsv_Fixed2()
        {
            using (var testPipeline = new Pipeline())
            {
                var looper = new FileLooper()
                {
                    SourceDirectory = this.testDataPath, FileFilter = @"FixedText2.txt"
                };
                testPipeline.Commands.Add(looper);

                var formatter = new FixedLengthToDataTableFormatter();
                formatter.FieldDefinitions.Add(new FieldDefinition(new Field("Header1", 15)));
                formatter.FieldDefinitions.Add(new FieldDefinition(new Field("Header2", 25)));
                formatter.FieldDefinitions.Add(new FieldDefinition(new Field("Header3", 10)));

                var reader = new FlatFileReader()
                {
                    File = "{File}", Formatter = formatter
                };
                looper.AddChild(reader);

                var writer = new FlatFileWriter()
                {
                    File = this.resultPath + @"{FileName}"
                };
                writer.Formatter = new DataTableToCsvFormatter();
                reader.AddChild(writer);

                testPipeline.ExecutePipeline();
            }

            // check
            var sourcelineCount = File.ReadLines(this.testDataPath + @"FixedText2.txt").Count();
            var targetlineCount = File.ReadLines(this.resultPath + @"FixedText2.txt").Count();

            Assert.AreEqual(sourcelineCount, targetlineCount);
        }