public override void DoPostExecution() { // write the file into task's FTP define if (!string.IsNullOrEmpty(_task.FtpServer) && !string.IsNullOrEmpty(_task.FtpUser) && !string.IsNullOrEmpty(_task.FtpPassword) && _task.FtpPort != null && !string.IsNullOrEmpty(_task.RemoteFolder) ) { var ftpRequestor = new FtpWebRequestor(_task.FtpServer, _task.FtpUser, _task.FtpPassword, _task.FtpPort, _task.RemoteFolder); ftpRequestor.WriteFtpFile(_generatedFile); } else { // get the message template var customer = GetCustomer(_task.CustomerId); string[] customerEmail = { customer.EmailAddress }; string[] ccEmails = null; if (!string.IsNullOrEmpty(_task.ConfirmationEmailTos)) { ccEmails = _task.ConfirmationEmailTos.Split(','); } EmailSender.SendConfirmationMessage(customerEmail, ccEmails, _generatedFile); } // create export file record for this taks for the generated file createCustomerExportedFilesRecord(_task.Id); }
public override void DoPostExecution() { if (!_hasAnyData) { Logger.LogWarning(LogEntryType.CustomExportProductTaskService, "No products have been exported for scheduled task name: " + _task.Name); return; } // write the file into task's FTP define if (_task.ExportTo == ExportTo.FTP) { var ftpRequestor = new FtpWebRequestor(_task.FtpServer, _task.FtpUser, _task.FtpPassword, _task.FtpPort, _task.RemoteFolder); ftpRequestor.WriteFtpFile(_generatedFile); } else if (_task.ExportTo == ExportTo.EMAIL) { // get the message template var msgTemplate = getMessageTemplate(TaskType); EmailSender.SendMessage(_task.EmailTo == null ? null : _task.EmailTo.Split(','), _task.EmailCc == null ? null : _task.EmailCc.Split(','), _task.EmailSubject, msgTemplate == null ? string.Empty : msgTemplate.ContentHtml, _generatedFile); } // create export file record for this taks for the generated file createExportedFilesRecord(_task.Id); }
public override void DoPostExecution() { if (!_exportedOrderIds.Any()) { Logger.LogInfo(LogEntryType.ExportOrderTaskService, "No orders have been exported for task name: " + _task.Name); } // write the file into task's FTP define if (_task.ExportTo.Equals("FTP") && (_task.IsDropNoOrderFile || _hasOrders)) { var ftpRequestor = new FtpWebRequestor(_task.FtpServer, _task.FtpUser, _task.FtpPassword, _task.FtpPort, _task.RemoteFolder); ftpRequestor.WriteFtpFile(_generatedFile); } // send confirmation message if (!string.IsNullOrEmpty(_task.ConfirmationEmailTos)) { EmailSender.SendConfirmationMessage(_task.ConfirmationEmailTos.Split(','), _hasOrders, _generatedFile); } // insert new record for exported file logs if (_hasOrders) { createExportedFilesRecord(_task.Id); } // mark the orders as exported if (_task.MarkOrderExport && _exportedOrderIds.Any()) { markOrdersAsExported(); } }
public override void DoPostExecution() { // write the file into task's FTP define if (_purchaseOrder == null) { Logger.LogInfo(LogEntryType.GeneratePoTaskService, "No PO generated for scheduled task name: " + _task.Name); return; } if (_task.ExportTo == ExportTo.FTP) { var ftpRequestor = new FtpWebRequestor(_task.FtpServer, _task.FtpUser, _task.FtpPassword, _task.FtpPort, _task.RemoteFolder); ftpRequestor.WriteFtpFile(_generatedFile); } else if (_task.ExportTo == ExportTo.EMAIL) { EmailSender.SendPoMessage(_task.EmailTo.Split(','), string.IsNullOrEmpty(_task.EmailCc) ? null : _task.EmailCc.Split(','), _task.EmailSubject, _purchaseOrder); } // create export file record for this taks for the generated file createExportedFilesRecord(_task.Id); // update the EIS orders IsPoGenerated to TRUE markOrdersAsPoGenerated(); }
public override bool Execute() { try { Logger.LogInfo(LogEntryType.OrderService, "Started parsing the order inventory file."); TaskRepository taskRepo = new TaskRepository(); var currentTaskAlreadyImportedFiles = taskRepo.GetCurrentScheduleAlreadyImportFiles(_task.Id); var ftpRequestor = new FtpWebRequestor(_task.FtpServer, _task.FtpUser, _task.FtpPassword, _task.FtpPort, _task.RemoteFolder); var getFiles = ftpRequestor.GetFileList(_task.FileType, _task.FileName); var fileNotImported = getFiles.Where(x => !currentTaskAlreadyImportedFiles.Any(y => y.FileName.ToLower() == x.ToLower())).ToList(); OrderRepository orderRepo; foreach (var file in fileNotImported) { var orders = new List <Order>(); orderRepo = new OrderRepository(); var fileOrderItems = CsvFileDataParser.GetOrderItems(ftpRequestor.GetFileStreamReader(file), _task.HasHeader, _task.FileHeaders, _task.CustomFields); var fileOrders = CsvFileDataParser.ParseOrderFile(ftpRequestor.GetFileStreamReader(file), orders, fileOrderItems, _task.HasHeader, _task.FileHeaders, _task.CustomFields); List <Order> importedOrder = new List <Order>(); foreach (var order in orders) { if (importedOrder.Count == 0) { importedOrder.Add(order); orderRepo.ManageOrders(order); } else if (importedOrder.Count > 0) { var isImported = importedOrder.Any(x => x.OrderId == order.OrderId); if (!isImported) { importedOrder.Add(order); orderRepo.ManageOrders(order); } } } } taskRepo.ManageImportFileSchedule(fileNotImported, _task.Id); Logger.LogInfo(LogEntryType.OrderService, "Successfully parsed the order inventory file."); return(true); } catch (Exception ex) { Logger.LogError(LogEntryType.FileInventoryTaskService, "Error in parsing the import inventory file! Message: " + EisHelper.GetExceptionMessage(ex), ex.StackTrace); return(false); } }
public VendorProductFileInventoryTaskService(vendorproductfileinventorytask task) { _task = task; _service = new VendorProductService(new ImageHelper(new PersistenceHelper()), new LogService()); _ftpRequestor = new FtpWebRequestor(task.FtpServer, task.FtpUser, task.FtpPassword, task.FtpPort, task.RemoteFolder); _ftpFileFullPath = task.FtpFileFullPath; _updatedEisSupplierSKUs = new List <string>(); }
public void ReadAndParsedFile() { // use the System's date var systemDateTime = DateTime.Now; var productFileSettings = _settingRepository.GetProductFileSettings(systemDateTime); foreach (var fileSetting in productFileSettings) { try { // continue; if it's not reading time yet if (!fileSetting.IsRunNow && !isWithInReadingTime(systemDateTime, fileSetting.ReadTime.TimeOfDay)) { continue; } if (isFileSettingAlreadyExecuted(fileSetting.LastExecutedOn)) { continue; } // let's update file setting execution _settingRepository.UpdateFileSettingLastExecution(fileSetting.VendorId); // download the file from the FTP and get the downloaded file path var ftpWebRequestor = new FtpWebRequestor(fileSetting); var downloadedFilePath = ftpWebRequestor.DownloadFtpFile(); // there should be an error if the downloaded file path is null and let's continue if (downloadedFilePath == null) { Logger.LogWarn(this.GetType().Name, string.Format("The file for vendor ID {0} was not successfully downloaded, set for the next day reading!", fileSetting.VendorId)); _settingRepository.SetProductNextUploadDate(fileSetting.VendorId, systemDateTime.AddDays(1)); continue; } // delete the file from FTP server first ftpWebRequestor.DeleteFileFromFtpAsync(); // let's create file manager fileSetting.ResultDate = DateTime.UtcNow.Date; var fileManager = FileManagerFactory.CreateFileManager(new FileInfo(downloadedFilePath), fileSetting, fileSetting.FileType); // create the task for managing file for this file setting and start the parsing file var task = Task.Factory.StartNew(() => { var dataService = new FileDataService(fileManager, fileSetting, _connectionString); dataService.DeleteVendorProducts(); return(dataService.ParsedDataFile()); }).ContinueWith(t => { // set the next read date for the product file _settingRepository.SetProductNextUploadDate(t.Result.OwnerId, systemDateTime.AddDays(1)); // if it has no error update the main products table with the parsed product data file if (!t.Result.HasError) { var productService = new ProductDataService(t.Result, _connectionString); productService.UpdateProducts(); } }); } catch (Exception ex) { Console.Error.WriteLine(string.Format("Error in parsing product file for vendor ID: {0} Error message: {1}", fileSetting.VendorId, ex.Message)); Logger.LogError(this.GetType().Name, string.Format("Error in parsing product file for vendor ID: {0} Error message: {1}", fileSetting.VendorId, ex.Message), ex.StackTrace); } } }
public JsonResult _CheckFileFromFtp(Credential credential) { var result = FtpWebRequestor.CheckFileFromFtp(credential); return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult _CheckFtpConnection(Credential credential) { var result = FtpWebRequestor.CheckFtpConnection(credential); return(Json(result, JsonRequestBehavior.AllowGet)); }