You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.2 KiB
67 lines
2.2 KiB
using System;
|
|
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;
|
|
|
|
namespace Win_in.Sfs.Scp.WebApi.Agent
|
|
{
|
|
public class IncomingDataWorker : AsyncPeriodicBackgroundWorkerBase
|
|
{
|
|
private readonly IOptions<AgentOptions> _options;
|
|
|
|
public IncomingDataWorker(
|
|
AbpAsyncTimer timer,
|
|
IOptions<AgentOptions> options,
|
|
IServiceScopeFactory serviceScopeFactory
|
|
) : base(timer, serviceScopeFactory)
|
|
{
|
|
_options = options;
|
|
Timer.Period = options.Value.IncomingOptions.PeriodSeconds * 1000; //default 5 minutes
|
|
}
|
|
|
|
[UnitOfWork]
|
|
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
|
|
{
|
|
Logger.LogInformation("Starting: Handling Incoming Exchange data...");
|
|
if (!_options.Value.IncomingOptions.Active)
|
|
{
|
|
Logger.LogInformation("Incoming Exchange is not active!");
|
|
return;
|
|
}
|
|
//Resolve dependencies
|
|
var incomingDataManager = workerContext
|
|
.ServiceProvider
|
|
.GetRequiredService<IIncomingDataManager>();
|
|
//Do the work
|
|
var incomingDataList = await incomingDataManager.GetReadyListAsync();
|
|
|
|
foreach (var incomingData in incomingDataList)
|
|
{
|
|
|
|
try
|
|
{
|
|
await UpdateWmsAsync(incomingData);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e = e.GetBaseException();
|
|
incomingData.SetError(EnumExchangeDataErrorCode.Exception, e.Message);
|
|
}
|
|
//归档并删除
|
|
await incomingDataManager.FileAndDeleteAsync(incomingData);
|
|
|
|
}
|
|
|
|
Logger.LogInformation("Completed: Handling Incoming Exchange data...");
|
|
}
|
|
|
|
private async Task UpdateWmsAsync(object incomingData)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|