Exemple #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);
        }
Exemple #2
0
        public void Test_TableFilter()
        {
            using (var testPipeline = new Pipeline())
            {
                var reader = new FlatFileReader()
                {
                    File = this.testDataPath + @"cd2.csv"
                };
                reader.Formatter = new CsvToDataTableFormatter()
                {
                    Separator = ";", Enclosure = "\""
                };
                testPipeline.Commands.Add(reader);

                var filter = new TableFilter();
                filter.FilterConditions.Add(new Condition()
                {
                    Token = "name", Operator = ConditionOperators.Contains, Value = "restaur"
                });
                reader.AddChild(filter);

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

                var result = testPipeline.ValidatePipeline();
                if (result.Any())
                {
                    throw new ArgumentException(string.Join(Environment.NewLine, result));
                }

                testPipeline.ExecutePipeline();
            }
        }
Exemple #3
0
        public void Test_ReadCsv_WriteCsv_Cd()
        {
            using (var testPipeline = new Pipeline())
            {
                var reader = new FlatFileReader()
                {
                    File = this.testDataPath + @"cd2.csv"
                };
                reader.Formatter = new CsvToDataTableFormatter()
                {
                    Separator = ";"
                };
                testPipeline.Commands.Add(reader);

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

                //testPipeline.CommandHook = (cmd) =>
                //{
                //};
                testPipeline.OnExecuteCommand += (cmd) =>
                {
                };

                testPipeline.ExecutePipeline();
            }

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

            Assert.AreEqual(sourcelineCount, targetlineCount);

            if (!FileUtil.CompareFiles(this.testDataPath + "cd2.csv", this.resultPath + "cd2_copy.csv"))
            {
                throw new Exception("Original and copied file do not match");
            }
        }
Exemple #4
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);
        }
Exemple #5
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();
            }
        }
Exemple #6
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);
        }