using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Volo.Abp.BackgroundWorkers; using Volo.Abp.Threading; using Volo.Abp.Uow; using Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent.Incoming; namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent; public class EosIncomingBackgroundWorker : AsyncPeriodicBackgroundWorkerBase { private readonly string Incoming = "EOS Incoming"; private readonly IOptions _options; public EosIncomingBackgroundWorker( AbpAsyncTimer timer, IOptions options, IServiceScopeFactory serviceScopeFactory ) : base(timer, serviceScopeFactory) { _options = options; Timer.Period = options.Value.IncomingOptions.PeriodSeconds * 1000; //default 10 minutes } [UnitOfWork] protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) { Logger.LogInformation($"Starting: Handling {Incoming}"); if (!_options.Value.IncomingOptions.Active) { Logger.LogInformation($"{Incoming} is not active!"); return; } Logger.LogInformation($"Read Plan"); var planReader = workerContext.ServiceProvider.GetRequiredService(); var planConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存Plan var plansFromExternalList = await planReader.ReadAsync().ConfigureAwait(false); //转换Plan await planConverter.ConvertAsync(plansFromExternalList).ConfigureAwait(false); Logger.LogInformation($"Read Ship"); var shipHandleService = workerContext.ServiceProvider.GetRequiredService(); var shipConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保持Ship var shipsFromExternalList = await shipHandleService.ReadAsync().ConfigureAwait(false); //转换Ship await shipConverter.ConvertAsync(shipsFromExternalList).ConfigureAwait(false); Logger.LogInformation($"Read Product"); var productHandleService = workerContext.ServiceProvider.GetRequiredService(); var productConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保持Product var productsFromExternalList = await productHandleService.ReadAsync().ConfigureAwait(false); // 转换Product await productConverter.ConvertAsync(productsFromExternalList).ConfigureAwait(false); Logger.LogInformation($"Completed: Handling {Incoming}"); } }