54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
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<ExecuteSsisPackages> _logger;
|
|
|
|
// TODO: set from config
|
|
private readonly string[] _ssisPackages = { "Parts Availability", "Parts Price" };
|
|
|
|
public ExecuteSsisPackages(IConfiguration configuration, SsisService ssisService, ILogger<ExecuteSsisPackages> logger)
|
|
{
|
|
FtpConfiguration ftpConfiguration = configuration.GetSection("FtpServers:AzureConfiguration").Get<FtpConfiguration>();
|
|
|
|
_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;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|