Ejemplo n.º 1
0
        private void ReadStockFile()
        {
            var ftpManager = new FtpManager(_ftpSetting.FtpUri, null, false, true);
            var regex      = FileNameRegex;

            foreach (var fileName in ftpManager.GetFiles())
            {
                if (!regex.IsMatch(fileName))
                {
                    continue;
                }
                using (var stream = ftpManager.Download(Path.GetFileName(fileName)))
                {
                    using (var streamReader = new StreamReader(stream))
                    {
                        var engine            = new FileHelperEngine(typeof(DatColStock));
                        var listOfVendorStock = engine.ReadStream(streamReader) as DatColStock[];
                        ProcessStock(listOfVendorStock);

                        try
                        {
                            ftpManager.Upload(stream, Path.Combine("History", fileName));
                        }
                        catch (Exception e) {
                        }
                    }
                }
                _archiveService.CopyToArchive(ftpManager.BaseUri.AbsoluteUri, SaveTo.StockDirectory, fileName);

                ftpManager.Delete(fileName);
            }
        }
Ejemplo n.º 2
0
        private void ProcessFiles()
        {
            var ftpManager = new FtpManager(_ftpSetting.FtpUri, null, false, true);
            var regex      = FileNameRegex;

            foreach (var fileName in ftpManager.GetFiles())
            {
                if (!regex.IsMatch(fileName))
                {
                    continue;
                }

                using (var stream = ftpManager.Download(Path.GetFileName(fileName)))
                {
                    using (var streamReader = new StreamReader(stream))
                    {
                        try
                        {
                            var engine            = new FileHelperEngine(typeof(DatColPurchaseOrder));
                            var listofPickTickets = engine.ReadStream(streamReader) as DatColPurchaseOrder[];

                            ProcessFile(listofPickTickets);

                            _archiveService.CopyToArchive(ftpManager.BaseUri.AbsoluteUri, SaveTo.PurchaseOrderDirectory, fileName);

                            ftpManager.Delete(fileName);
                        }
                        catch (Exception)
                        {
                            _log.AuditError(string.Format("Failed to process the Purchase order file. File name: '{0}'", fileName));
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void ReadCustomerInformation()
        {
            _ftpSetting.Path = _vendorSettingRepo.GetVendorSetting(SapphVendorID, CustomerInformationDirectorySettingKey);
            var ftpManager = new FtpManager(_ftpSetting.FtpUri, null, false, usePassive: true);

            var regex = FileNameRegex;

            foreach (var fileName in ftpManager.GetFiles())
            {
                if (!regex.IsMatch(fileName))
                {
                    continue;
                }
                try
                {
                    _log.Info(string.Format("Processing file: {0}", fileName));

                    using (var stream = ftpManager.Download(Path.GetFileName(fileName)))
                    {
                        using (var excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream))
                        {
                            excelReader.IsFirstRowAsColumnNames = true;
                            var result = excelReader.AsDataSet();
                            var dt     = result.Tables[0];

                            var customerInformationList = (
                                from ci in dt.AsEnumerable()
                                select new DatColCustomerInformation
                            {
                                CustomerNumber = ci.Field <string>(ColumnCustomerNumber),
                                SupplierName = ci.Field <string>(ColumnSupplierName),
                                SupplierAdress = ci.Field <string>(ColumnSupplierAdress),
                                ExpeditionCity = ci.Field <string>(ColumnExpeditionCity),
                                ExpeditionPc = ci.Field <string>(ColumnExpeditionZip),
                                ExpeditionCountry = ci.Field <string>(ColumnExpeditionCountry)
                            })
                                                          .ToList();
                            UploadCustomerInformationToTnt(customerInformationList);
                        }
                    }

                    _archiveService.CopyToArchive(ftpManager.BaseUri.AbsoluteUri, SaveTo.CustomerInformationDirectory, fileName);
                    ftpManager.Delete(Path.GetFileName(fileName));
                }
                catch (Exception e)
                {
                    _log.Info(string.Format("Failed to process file {0}. Error: {1}", fileName, e.Message));
                }
            }
        }
Ejemplo n.º 4
0
        protected virtual void LoadDocuments(string sourceUri)
        {
            var ftpManager = new FtpManager(sourceUri, Log, usePassive: true);
            var regex      = FileNameRegex;

            foreach (var fileName in ftpManager.GetFiles())
            {
                if (regex.IsMatch(fileName))
                {
                    using (var stream = ftpManager.Download(fileName))
                    {
                        Documents[fileName] = XDocument.Load(stream);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void LoadDocuments(string currentAxaptaAccountNumber)
        {
            var regex = new Regex(".*_" + currentAxaptaAccountNumber + ".xml", RegexOptions.IgnoreCase);

            //#if DEBUG
            //foreach (var fileName in Directory.GetFiles(@"D:\tmp\Sapph\Axapta\ArticleInformation"))
            //{
            //  if (regex.IsMatch(Path.GetFileName(fileName)))
            //  {
            //    using (var stream = File.Open(fileName, FileMode.Open))
            //    {
            //      Documents[fileName] = XDocument.Load(stream);
            //    }
            //  }
            //}
            //#endif

            var ftpManager = new FtpManager(GetFtpUri(), Log, usePassive: true);

            foreach (var fileName in ftpManager.GetFiles())
            {
                if (Documents.Count >= 10)
                {
                    return;
                }

                if (!regex.IsMatch(fileName))
                {
                    continue;
                }

                using (var stream = ftpManager.Download(Path.GetFileName(fileName)))
                {
                    Documents[fileName] = XDocument.Load(stream);
                }
            }
        }
Ejemplo n.º 6
0
        public void CopyToArchive(string ftpUri, SaveTo saveTo, string fileNameToCopy)
        {
            SetArchiveDirectoryPath(saveTo);

            var ftpManager = new FtpManager(ftpUri, null, false, true);

            foreach (var file in ftpManager.GetFiles())
            {
                var fileName = Path.GetFileName(file);

                if (fileName != null && !fileName.Equals(Path.GetFileName(fileNameToCopy)))
                {
                    continue;
                }
                try
                {
                    using (var stream = ftpManager.Download(fileName))
                    {
                        var filePath = Path.Combine(_directoryPathName, fileNameToCopy);

                        try
                        {
                            SaveStreamToFile(filePath, stream);
                        }
                        catch (IOException exception)
                        {
                            throw new Exception(exception.Message);
                        }
                    }
                    return;
                }
                catch (Exception e)
                {
                    throw new Exception(string.Format("Could not process file {0}! Error: {1}", file, e.Message));
                }
            }
        }
Ejemplo n.º 7
0
        private void CopyArticleInformationToTnt(string fileNameToCopy)
        {
            try
            {
                Vendor vendor;

                using (var unit = GetUnitOfWork())
                {
                    vendor = unit.Scope.Repository <Vendor>().GetSingle(x => x.Name.Equals("Sapph"));
                }

                var ftpAddress  = vendor.VendorSettings.GetValueByKey("FtpAddress", string.Empty);
                var ftpUsername = HttpUtility.UrlEncode(vendor.VendorSettings.GetValueByKey("FtpUsername", string.Empty));
                var ftpPassword = HttpUtility.UrlEncode(vendor.VendorSettings.GetValueByKey("FtpPassword", string.Empty));
                var ftpPath     = vendor.VendorSettings.GetValueByKey("Ax Ftp Dir ArticleInformation", string.Empty);
                var ftpUri      = string.Format("ftp://{0}:{1}@{2}/{3}", ftpUsername, ftpPassword, ftpAddress, ftpPath);

                var tntFtpSetting = vendor.VendorSettings.GetValueByKey("TNTDestinationURI", string.Empty);

                var archiveDirectoryPath = vendor.VendorSettings.GetValueByKey("Archive Directory", string.Empty);

                var fileNameRegex = new Regex(".*\\.xml$", RegexOptions.IgnoreCase);

                var axaptaFtpManager = new FtpManager(ftpUri, null, false, usePassive: true);
                var tnTftpManager    = new FtpManager(tntFtpSetting, log, usePassive: true);

                foreach (var articleInformatioFile in axaptaFtpManager.GetFiles())
                {
                    var fileName = Path.GetFileName(articleInformatioFile);

                    if (!fileNameRegex.IsMatch(articleInformatioFile))
                    {
                        continue;
                    }
                    if (fileName != null && !fileName.Equals(Path.GetFileName(fileNameToCopy)))
                    {
                        continue;
                    }

                    try
                    {
                        log.InfoFormat("Processing file {0}", articleInformatioFile);

                        using (var stream = axaptaFtpManager.Download(fileName))
                        {
                            tnTftpManager.Upload(stream, fileName);

                            var archiveDirectory = SetArchiveDirectoryPath(archiveDirectoryPath, ftpPath);

                            SaveStreamToFile(Path.Combine(archiveDirectory, fileName), stream);

                            axaptaFtpManager.Delete(fileName);
                        }
                        return;
                    }
                    catch (Exception e)
                    {
                        log.ErrorFormat("Could not process file {0}! Error: {1}", articleInformatioFile, e.Message);
                    }
                }
            }
            catch (Exception e)
            {
                log.AuditError("Sapph passthrough product information to TNT Failed", e);
            }
        }