Пример #1
0
        public void Test_ReadXml_WriteCsv_Kunden()
        {
            using (var testPipeline = new Pipeline())
            {
                var reader = new XmlFileReader()
                {
                    File     = this.testDataPath + @"kunden.xml",
                    RowXPath = "/adre/kunde"
                };
                reader.Formatter = new XPathToDataTableFormatter();
                testPipeline.Commands.Add(reader);

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

                testPipeline.ExecutePipeline();
            }

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

            Assert.AreEqual(3, targetlineCount);
        }
Пример #2
0
        public void Test_RestService_GetCountries()
        {
            using (var testPipeline = new Pipeline())
            {
                var httpClient = new HttpClient()
                {
                    Url       = @"http://services.groupkt.com/country/get/all",
                    Formatter = new JsonToDataTableFormatter()
                    {
                        RowXPath = "/RestResponse/result"
                    }
                };

                testPipeline.Commands.Add(httpClient);

                var writer = new FlatFileWriter()
                {
                    File = this.resultPath + @"allcountries.txt", DeleteBefore = true
                };
                writer.Formatter = new DataTableToCsvFormatter()
                {
                    Separator = ";"
                };
                httpClient.AddChild(writer);

                testPipeline.ExecutePipeline();
            }

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

            Assert.AreEqual(250, targetlineCount);
        }
Пример #3
0
        public void Test_EmailDownloader()
        {
            using (var testPipeline = new Pipeline())
            {
                var emailer = new EmailDownloader();
                emailer.Host         = "pop.gmx.de";
                emailer.User         = "";
                emailer.Password     = "";
                emailer.EnableSecure = true;
                emailer.FilterConditions.Add(new Condition()
                {
                    Token = "EmailFrom", Operator = ConditionOperators.Contains, Value = "pearl"
                });

                testPipeline.Commands.Add(emailer);

                var writer = new FlatFileWriter()
                {
                    File = this.resultPath + "{File}", DeleteBefore = true
                };
                writer.Formatter = new DefaultFormatter();
                emailer.AddChild(writer);
                testPipeline.OnExecuteCommand += delegate(DataCommand cmd)
                {
                };
                testPipeline.ExecutePipeline();
            }

            int emailFileCount = Directory.GetFiles(this.resultPath, @"*.html", SearchOption.TopDirectoryOnly).Length;

            Assert.IsTrue(emailFileCount > 0, "No emails were downloaded");
        }
Пример #4
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);
        }
Пример #5
0
        public void Test_Soap_ReadMedicareSupplier()
        {
            using (var testPipeline = new Pipeline())
            {
                var reader = new SoapClient()
                {
                    Wsdl       = "http://www.webservicex.net/medicareSupplier.asmx?WSDL",
                    MethodName = "GetSupplierByCity",
                    Formatter  = new XPathToDataTableFormatter()
                    {
                        RowXPath = "/GetSupplierByCityResponse/SupplierDataLists/SupplierDatas/SupplierData"
                    }
                };

                reader.DataMappings.Add(new DataMapping()
                {
                    Name = "City", Value = "Fort Worth"
                });

                testPipeline.Commands.Add(reader);

                var writer = new FlatFileWriter()
                {
                    File      = this.resultPath + @"MedicareSupplier.csv",
                    Formatter = new DataTableToCsvFormatter()
                };

                reader.AddChild(writer);
                //testPipeline.OnExecuteCommand += (cmd) =>
                //{
                //};
                testPipeline.ExecutePipeline();
            }

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

            Assert.AreNotSame(0, targetlineCount);

            var resultContent = File.ReadAllText(this.resultPath + @"MedicareSupplier.csv");

            if (resultContent.Length <= 4)
            {
                throw new AssertFailedException("No content in MedicareSupplier.csv");
            }
        }
Пример #6
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");
            }
        }
Пример #7
0
    private void CreateFile(KPOrder kpOrder)
    {
        //随便写写,谁叫他们不给钱的
        #region 抽取数据导入文件
        string   fileFolder = "D:\\Dss\\out\\";
        string   fileName   = "SCONIT_QAD_" + DateTime.Now.ToString("yyyyMMddhhmmss") + "_KPCONF.REQ";
        string[] line1      = new string[]
        {
            "1",
            kpOrder.QAD_ORDER_ID,
            DateTime.Now.ToShortDateString()
        };

        string[][]     data           = new string[][] { line1 };
        StreamWriter   streamWriter   = new StreamWriter(fileFolder + fileName, false, Encoding.GetEncoding(Encoding.Default.WebName));
        FlatFileWriter flatFileWriter = new FlatFileWriter(streamWriter, Environment.NewLine, "|");
        flatFileWriter.Write(data);
        flatFileWriter.Dispose();
        #endregion
    }
Пример #8
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);
        }
Пример #9
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();
            }
        }
Пример #10
0
        public void Test_Soap_ReadCustomerService()
        {
            using (var testPipeline = new Pipeline())
            {
                var reader = new SoapClient()
                {
                    Wsdl       = "http://www.predic8.com:8080/crm/CustomerService?wsdl",
                    MethodName = "getAll",
                    Formatter  = new XPathToDataTableFormatter()
                    {
                        RowXPath = "/getAllResponse/customer"
                    }
                };

                testPipeline.Commands.Add(reader);

                var writer = new FlatFileWriter()
                {
                    File      = this.resultPath + @"CustomerService.csv",
                    Formatter = new DataTableToCsvFormatter()
                };

                reader.AddChild(writer);

                testPipeline.ExecutePipeline();
            }

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

            Assert.AreNotSame(0, targetlineCount);

            var resultContent = File.ReadAllText(this.resultPath + @"CustomerService.csv");

            if (resultContent.Length <= 4)
            {
                throw new AssertFailedException("No content in CustomerService.csv");
            }
        }
Пример #11
0
        public void Test_HttpTrigger()
        {
            using (var testPipeline = new Pipeline())
            {
                var httpTrigger = new HttpTrigger()
                {
                    Port = 8080,
                    UseAuthentication = true,
                    User     = "******",
                    Password = "******"
                };

                testPipeline.Commands.Add(httpTrigger);

                var writer = new FlatFileWriter()
                {
                    File = this.resultPath + @"http-parameter.txt", DeleteBefore = false
                };
                writer.Formatter = new DataTableToCsvFormatter()
                {
                    Separator = ";"
                };
                httpTrigger.AddChild(writer);

                testPipeline.ExecutePipeline();
            }

            using (var webClient = new WebClient())
            {
                webClient.SetCredentials(new NetworkCredential("Hello", "World"));
                webClient.QueryString.Add("Name", "Donald T.");
                webClient.QueryString.Add("Address", "Washington");

                string response = webClient.DownloadString("http://localhost:8080/");

                Assert.AreEqual(response, "<Message>Triggered successfull</Message>");
            }
        }
Пример #12
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);
        }
Пример #13
0
 public void SetUp()
 {
     theWriter = new FlatFileWriter(new List <string>());
 }
Пример #14
0
        public void ProcessOutbound(DssOutboundControl dssOutboundControl)
        {
            log.Info("Start process outbound.");
            this.Initital_DBCache();

            #region Initailize
            this._dssObjectMapping = this.dssObjectMappingMgr.GetAllDssObjectMapping();
            #endregion

            string outFolder = dssOutboundControl.OutFolder;
            //string serviceName = dssOutboundControl.ServiceName;
            string archiveFolder = dssOutboundControl.ArchiveFolder;
            string tempFolder    = dssOutboundControl.TempFolder;
            //string encoding = dssOutboundControl.FileEncoding;
            string encoding   = Encoding.Default.WebName;
            string filePrefix = this.GetFilePrefix(dssOutboundControl);

            #region 初始化本地目录
            outFolder = outFolder.Replace("\\", "/");
            if (!outFolder.EndsWith("/"))
            {
                outFolder += "/";
            }

            if (!Directory.Exists(outFolder))
            {
                Directory.CreateDirectory(outFolder);
            }

            archiveFolder = archiveFolder.Replace("\\", "/");
            if (!archiveFolder.EndsWith("/"))
            {
                archiveFolder += "/";
            }

            if (!Directory.Exists(archiveFolder))
            {
                Directory.CreateDirectory(archiveFolder);
            }

            tempFolder = tempFolder.Replace("\\", "/");
            if (!tempFolder.EndsWith("/"))
            {
                tempFolder += "/";
            }

            if (Directory.Exists(tempFolder))
            {
                Directory.Delete(tempFolder, true);
            }
            Directory.CreateDirectory(tempFolder);
            #endregion

            #region 抽取数据
            log.Info("Begin to extract data:extsyscode:" + dssOutboundControl.ExternalSystem.Code + ",extobjcode:" + dssOutboundControl.ExternalObjectCode + ",service:" + dssOutboundControl.ServiceName);
            IList <DssExportHistory> dataList = this.GetHisList(dssOutboundControl.Id);

            #region 缓存数据
            IList <DssExportHistory> dssExportHistoryList = ExtractOutboundData(dssOutboundControl);
            this.ObjectMapping(dssExportHistoryList);
            dssExportHistoryList = this.FilterList(dssExportHistoryList);
            if (dssExportHistoryList != null && dssExportHistoryList.Count > 0)
            {
                this.CreateDssExportHistory(dssExportHistoryList, dssOutboundControl);
                dataList = dataList.Concat(dssExportHistoryList).ToList();

                log.Info("DssExportHistory count:" + dataList.Count + ",update new mark:" + dssOutboundControl.Mark);
            }
            #endregion

            #endregion

            #region 循环处理抽取数据
            if (dataList != null && dataList.Count > 0)
            {
                //if (dssOutboundControl.Id != 7)
                //{
                #region 非iss-so
                foreach (DssExportHistory dssExportHistory in dataList)
                {
                    try
                    {
                        object obj = null;
                        try
                        {
                            obj = GetOutboundData(dssExportHistory);
                        }
                        catch (BusinessErrorException ex)
                        {
                            log.Warn("Get no outbound data:", ex);
                            continue;
                        }

                        if (obj == null)
                        {
                            continue;
                        }

                        #region 对象转换为数组
                        object     o       = Serialize(obj);
                        DateTime   effDate = (DateTime)((object[])o)[0];
                        string[][] data    = (string[][])((object[])o)[1];
                        #endregion

                        #region 抽取数据导入文件
                        string transNo = this.GetTransNumber(dssOutboundControl, filePrefix, effDate);
                        //modified by [email protected]
                        //2012/5
                        string location  = dssExportHistory.Location;
                        bool   partyfrom = dssExportHistory.PartyFrom == "1001" ? true : false;
                        bool   partyto   = dssExportHistory.PartyTo == "1001" ? true : false;
                        //string region = locationMgr.LoadLocation(location).Region.Code;
                        string bj_region = partyfrom || partyto == true ? "BJ" : "";
                        string fileName  = this.GetFileName(dssOutboundControl, filePrefix, transNo, bj_region);
                        //modified end
                        StreamWriter   streamWriter   = new StreamWriter(tempFolder + fileName, false, Encoding.GetEncoding(encoding));
                        FlatFileWriter flatFileWriter = new FlatFileWriter(streamWriter, Environment.NewLine, "|");
                        flatFileWriter.Write(data);
                        flatFileWriter.Dispose();
                        #endregion

                        #region 文件移至目录
                        try
                        {
                            File.Copy(tempFolder + fileName, archiveFolder + fileName);     //备份目录
                            File.Move(tempFolder + fileName, outFolder + fileName);         //导出目录

                            #region 更新导出标记
                            dssExportHistory.IsActive = false;
                            dssExportHistory.TransNo  = transNo;
                            dssExportHistoryMgr.UpdateDssExportHistory(dssExportHistory);
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            log.Error("Create export file error.", ex);
                            if (File.Exists(archiveFolder + fileName))
                            {
                                File.Delete(archiveFolder + fileName);
                            }

                            if (File.Exists(outFolder + fileName))
                            {
                                File.Delete(outFolder + fileName);
                            }
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        log.Error("Export data error.", ex);
                        break;    //2012-10-24 发生错误执行下一任务 djin
                    }
                }
                #endregion
                //}
                //else
                //{
                //    var dataListGroup = (from i in dataList select i.DefinedString1).Distinct().ToList();
                //    foreach (var i in dataListGroup)
                //    {
                //        IList<string[][]> outString = new List<string[][]>();
                //        var result = (from x in dataList where x.DefinedString1 == i select x).ToList();
                //        #region  iss-so

                //        if (result != null && result.Count > 0)
                //        {
                //            foreach (DssExportHistory dssExportHistory in result)
                //            {
                //                try
                //                {
                //                    object obj = null;
                //                    try
                //                    {
                //                        obj = GetOutboundData(dssExportHistory);
                //                    }
                //                    catch (BusinessErrorException ex)
                //                    {
                //                        log.Warn("Get no outbound data:", ex);
                //                        continue;
                //                    }

                //                    if (obj == null)
                //                        continue;

                //                    #region 对象转换为数组
                //                    object o = Serialize(obj);

                //                    string[][] data = (string[][])((object[])o)[1];

                //                    outString.Add(data);

                //                    #endregion
                //                }
                //                catch (Exception ex)
                //                {
                //                    log.Error("Export data error.", ex);
                //                    break;//2012-10-24 发生错误执行下一任务 djin
                //                }
                //            }

                //            #region 抽取数据导入文件
                //            try
                //            {
                //                DateTime effDate = (DateTime)((object[])Serialize(GetOutboundData(result[0])))[0];

                //                string transNo = this.GetTransNumber(dssOutboundControl, filePrefix, effDate);
                //                //modified by [email protected]
                //                //2012/5
                //                string location = result[0].Location;
                //                bool partyfrom = result[0].PartyFrom == "1001" ? true : false;
                //                bool partyto = result[0].PartyTo == "1001" ? true : false;
                //                //string region = locationMgr.LoadLocation(location).Region.Code;
                //                string bj_region = partyfrom || partyto == true ? "BJ" : "";
                //                string fileName = this.GetFileName(dssOutboundControl, filePrefix, transNo, bj_region);
                //                fileName = fileName.Split(new char[] { '.' })[0].TrimEnd(new char[] { '1' }) +"."+ fileName.Split(new char[] { '.' })[1];
                //                //modified end
                //                StreamWriter streamWriter = new StreamWriter(tempFolder + fileName, false, Encoding.GetEncoding(encoding));
                //                FlatFileWriter flatFileWriter = new FlatFileWriter(streamWriter, Environment.NewLine, "|");
                //                flatFileWriter.WriteWithNewLine(((string[][])(outString[0]))[0]);
                //                foreach (string[][] str in outString)
                //                {
                //                    flatFileWriter.WriteWithNewLine(str[1]);
                //                }
                //                flatFileWriter.Dispose();
                //            #endregion

                //                #region 文件移至目录
                //                try
                //                {
                //                    File.Copy(tempFolder + fileName, archiveFolder + fileName);  //备份目录
                //                    File.Move(tempFolder + fileName, outFolder + fileName);     //导出目录

                //                    #region 更新导出标记
                //                    foreach (DssExportHistory dssExportHistory in dataList)
                //                    {
                //                        dssExportHistory.IsActive = false;
                //                        dssExportHistory.TransNo = transNo;
                //                        dssExportHistoryMgr.UpdateDssExportHistory(dssExportHistory);
                //                    }
                //                    #endregion
                //                }
                //                catch (Exception ex)
                //                {
                //                    log.Error("Create export file error.", ex);
                //                    if (File.Exists(archiveFolder + fileName))
                //                    {
                //                        File.Delete(archiveFolder + fileName);
                //                    }

                //                    if (File.Exists(outFolder + fileName))
                //                    {
                //                        File.Delete(outFolder + fileName);
                //                    }
                //                }
                //                #endregion
                //            }
                //            catch (Exception ex)
                //            {
                //                continue;
                //            }
                //        #endregion
                //        }
                //    }
                //}
            }
            else
            {
                log.Info("No data export.");
            }
            #endregion

            this.Initital_DBCache();
            log.Info("Start process outbound successful.");
        }
Пример #15
0
 public void SetUp()
 {
     theWriter = new FlatFileWriter(new List<string>());
 }