105 lines
3.2 KiB
C#
105 lines
3.2 KiB
C#
using AutoMapper;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using PartSource.Automation.Jobs;
|
|
using PartSource.Automation.Services;
|
|
using PartSource.Data;
|
|
using PartSource.Data.AutoMapper;
|
|
using PartSource.Data.Contexts;
|
|
using PartSource.Services;
|
|
using Ratermania.Automation.DependencyInjection;
|
|
using Ratermania.Automation.Logging;
|
|
using Ratermania.Shopify.DependencyInjection;
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PartSource.Automation
|
|
{
|
|
class Program
|
|
{
|
|
static async Task Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
using IHost host = CreateHostBuilder().Build();
|
|
|
|
await host.StartAsync();
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.ToString());
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private static IHostBuilder CreateHostBuilder()
|
|
{
|
|
return Host.CreateDefaultBuilder()
|
|
.ConfigureAppConfiguration(builder =>
|
|
{
|
|
string environment = Environment.GetEnvironmentVariable("AUTOMATION_ENVIRONMENT");
|
|
|
|
builder.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
|
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true);
|
|
})
|
|
.ConfigureServices((builder, services) =>
|
|
{
|
|
services.AddDbContext<PartSourceContext>(options =>
|
|
options.UseSqlServer(builder.Configuration.GetConnectionString("PartSourceDatabase"), opts => opts.EnableRetryOnFailure())
|
|
)
|
|
|
|
.AddDbContext<FitmentContext>(options =>
|
|
options.UseSqlServer(builder.Configuration.GetConnectionString("FitmentDatabase"), opts => opts.EnableRetryOnFailure())
|
|
)
|
|
|
|
.AddShopify(options =>
|
|
{
|
|
options.ApiKey = builder.Configuration["Shopify:ApiKey"];
|
|
options.ApiSecret = builder.Configuration["Shopify:ApiSecret"];
|
|
options.ApiVersion = "2020-01";
|
|
options.ShopDomain = builder.Configuration["Shopify:ShopDomain"];
|
|
})
|
|
|
|
.AddAutomation(options =>
|
|
{
|
|
options.HasBaseInterval(new TimeSpan(0, 1, 0))
|
|
.HasMaxFailures(5)
|
|
//.HasJob<SyncronizeProducts>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
|
// .HasJob<ProcessWhiFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
|
//.HasJob<UpdateFitment>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
|
// .HasDependency<ProcessWhiFitment>()
|
|
// .StartsAt(DateTime.Today.AddHours(8))
|
|
//)
|
|
|
|
.HasJob<ExecuteSsisPackages>(options => options.HasInterval(new TimeSpan(24, 0, 0))
|
|
// .HasJob<UpdatePricing>(options => options.HasInterval(new TimeSpan(24, 0, 0)))
|
|
//.HasDependency<ExecuteSsisPackages>()
|
|
//.StartsAt(DateTime.Now.AddMinutes(15))
|
|
)
|
|
.AddApiServer(options => options.HasApiKey(Environment.GetEnvironmentVariable("AUTOMATION_API_KEY")));
|
|
})
|
|
|
|
.AddSingleton<EmailService>()
|
|
.AddSingleton<SsisService>()
|
|
.AddSingleton<WhiSeoService>()
|
|
.AddSingleton<VehicleService>()
|
|
|
|
|
|
.AddAutoMapper(typeof(PartSourceProfile));
|
|
})
|
|
.ConfigureLogging((builder, logging) =>
|
|
{
|
|
logging.AddConsole();
|
|
|
|
logging.AddProvider(new AutomationLoggerProvider());
|
|
});
|
|
}
|
|
}
|
|
}
|