using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using PartSource.Automation.Models.Configuration; using PartSource.Automation.Services; using Ratermania.Automation.Interfaces; using System; using System.Threading.Tasks; namespace PartSource.Automation.Jobs { public class ExecuteSsisPackages : IAutomationJob { private readonly FtpService _ftpService; private readonly SsisService _ssisService; private readonly ILogger _logger; // TODO: set from config private readonly string[] _ssisPackages = { "Parts Availability", "Parts Price" }; public ExecuteSsisPackages(IConfiguration configuration, SsisService ssisService, ILogger logger) { FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AzureConfiguration").Get(); _ftpService = new FtpService(ftpConfiguration); _ssisService = ssisService; _logger = logger; } public async Task Run() { await Task.Run(() => { foreach (string package in _ssisPackages) { try { _ftpService.Download($"{package}.txt"); _ssisService.Execute($"{package}.dtsx"); _logger.LogInformation($"Execution of SSIS package {package} completed successfully."); } catch (Exception ex) { _logger.LogError($"Execution of SSIS package {package} failed.", ex); throw; } } }); } } }