diff --git a/PartSource.Automation/Jobs/BulkUpdateInventory.cs b/PartSource.Automation/Jobs/BulkUpdateInventory.cs index 7319f27..8dfcfdc 100644 --- a/PartSource.Automation/Jobs/BulkUpdateInventory.cs +++ b/PartSource.Automation/Jobs/BulkUpdateInventory.cs @@ -24,7 +24,7 @@ namespace PartSource.Automation.Jobs public BulkUpdateInventory(IConfiguration configuration, ILogger logger) { - FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AzureConfiguration").Get(); + FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AutomationConfiguration").Get(); _ftpService = new FtpService(ftpConfiguration); _connectionString = configuration.GetConnectionString("PartSourceDatabase"); diff --git a/PartSource.Automation/Jobs/ExecuteSsisPackages.cs b/PartSource.Automation/Jobs/ExecuteSsisPackages.cs index c287910..605dc15 100644 --- a/PartSource.Automation/Jobs/ExecuteSsisPackages.cs +++ b/PartSource.Automation/Jobs/ExecuteSsisPackages.cs @@ -1,9 +1,11 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using PartSource.Automation.Models.Configuration; +using PartSource.Automation.Models.Ftp; using PartSource.Automation.Services; using Ratermania.Automation.Interfaces; using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -21,7 +23,7 @@ namespace PartSource.Automation.Jobs public ExecuteSsisPackages(EmailService emailService, IConfiguration configuration, SsisService ssisService, ILogger logger) { - FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AzureConfiguration").Get(); + FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AutomationConfiguration").Get(); _emailService = emailService; _ftpService = new FtpService(ftpConfiguration); @@ -36,7 +38,18 @@ namespace PartSource.Automation.Jobs { try { - _ftpService.Download($"{package}.txt"); + FtpFileInfo lastUploadedFile = _ftpService.ListFilesExtended() + .Where(f => f.FileType == FtpFileType.File && f.Filename.IndexOf(package) > -1) + .OrderByDescending(f => f.Modified) + .FirstOrDefault(); + + if (lastUploadedFile == null) + { + _logger.LogInformation($"No {package} file available."); + return; + } + + _ftpService.Download($"{package}.txt"); _ssisService.Execute($"{package}.dtsx"); _logger.LogInformation($"Execution of SSIS package {package} completed successfully."); @@ -45,7 +58,6 @@ namespace PartSource.Automation.Jobs catch (Exception ex) { _logger.LogError($"Execution of SSIS package {package} failed.", ex); - throw; } } diff --git a/PartSource.Automation/Jobs/PartialInventoryUpdate.cs b/PartSource.Automation/Jobs/PartialInventoryUpdate.cs index 66c89f2..89ade32 100644 --- a/PartSource.Automation/Jobs/PartialInventoryUpdate.cs +++ b/PartSource.Automation/Jobs/PartialInventoryUpdate.cs @@ -24,7 +24,7 @@ namespace PartSource.Automation.Jobs public PartialInventoryUpdate(IConfiguration configuration, ILogger logger) { - FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AzureConfiguration").Get(); + FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AutomationConfiguration").Get(); _ftpService = new FtpService(ftpConfiguration); _connectionString = _connectionString = configuration.GetConnectionString("PartSourceDatabase"); diff --git a/PartSource.Automation/appsettings.json b/PartSource.Automation/appsettings.json index 005fb59..03017bf 100644 --- a/PartSource.Automation/appsettings.json +++ b/PartSource.Automation/appsettings.json @@ -11,19 +11,18 @@ "SmtpHost": "localhost" }, "FtpServers": { - "AzureConfiguration": { - "Username": "ps-ftp\\$ps-ftp", - "Password": "ycvXptffBxqkBXW4vuRYqn4Zi1soCvnvMMolTe5HNSeAlcl3bAyJYtNhG579", - "Url": "ftp://waws-prod-yq1-007.ftp.azurewebsites.windows.net/site/wwwroot", - "Destination": "C:\\Partsource.Automation\\Downloads", - "Port": 21 - }, "WhiConfiguration": { "Username": "ctc_seo", "Password": "YD3gtaQ5kPdtNKs", "Url": "ftp://ftp.whisolutions.com", "Destination": "C:\\Partsource.Automation\\Downloads\\WHI", - "Port": 3001 + "Port": 3001 + }, + "AutomationConfiguration": { + "Username": "stageuser", + "Password": "FXepK^cFYS|[H<", + "Url": "ftp://localhost", + "Destination": "C:\\Partsource.Automation\\Downloads" } }, "ssisConfiguration": {