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; using System.Threading.Tasks; namespace PartSource.Automation.Jobs { public class ExecuteSsisPackages : IAutomationJob { private readonly EmailService _emailService; private readonly FtpService _ftpService; private readonly SsisService _ssisService; private readonly ILogger _logger; // TODO: set from config private readonly string[] _ssisPackages = { "Parts Availability" }; public ExecuteSsisPackages(EmailService emailService, IConfiguration configuration, SsisService ssisService, ILogger logger) { FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AzureConfiguration").Get(); _emailService = emailService; _ftpService = new FtpService(ftpConfiguration); _ssisService = ssisService; _logger = logger; } public async Task Run(CancellationToken token, params string[] arguments) { 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; } } // _emailService.Send("Database Updates Complete", "Database updates to support pricing and availability have completed successfully."); }); } } }