67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using PartSource.Automation.Models.Configuration;
|
|
using System.Configuration;
|
|
using System.Diagnostics;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace PartSource.Automation.Services
|
|
{
|
|
public class SsisService
|
|
{
|
|
private readonly SsisConfiguration _ssisConfiguration;
|
|
|
|
public SsisService(IConfiguration configuration)
|
|
{
|
|
_ssisConfiguration = configuration.GetSection("ssisConfiguration").Get<SsisConfiguration>();
|
|
}
|
|
|
|
public bool Execute(string packageName)
|
|
{
|
|
try
|
|
{
|
|
using Process process = new Process
|
|
{
|
|
StartInfo = new ProcessStartInfo
|
|
{
|
|
FileName = "dtexec",
|
|
Arguments = $"/file \"{_ssisConfiguration.Directory}\\{packageName}\"",
|
|
UseShellExecute = false,
|
|
CreateNoWindow = false,
|
|
RedirectStandardOutput = true,
|
|
RedirectStandardError = true
|
|
}
|
|
};
|
|
|
|
process.Start();
|
|
|
|
//process.WaitForExit();
|
|
|
|
string stdout = process.StandardOutput.ReadToEnd();
|
|
string stderr = process.StandardError.ReadToEnd();
|
|
|
|
Console.WriteLine(stdout);
|
|
Console.WriteLine(stderr);
|
|
|
|
// Application application = new Application();
|
|
//Package package = application.LoadPackage($"{_ssisConfiguration.Directory}\\{packageName}", null);
|
|
|
|
//DTSExecResult result = package.Execute();
|
|
|
|
return true; //result == DTSExecResult.Success;
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|