60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
using MAX.Core.DependencyInjection;
|
|
using MAX.Core.Logger;
|
|
using MAX.Framework.Logger;
|
|
using Newtonsoft.Json.Linq;
|
|
using Store.Framework.Inerterfaces;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Store.Product.Publish;
|
|
|
|
public abstract class PublishStep<TContext> : IPublishStep<TContext>, IDisposable where TContext : PublishContextBase
|
|
{
|
|
protected ILoggerFacade Looger => LazyServiceProvider.Instance.LazyGetService<ILoggerFacade>();
|
|
protected ICurrentUser CurrentUser => LazyServiceProvider.Instance.LazyGetService<ICurrentUser>();
|
|
public abstract string Description { get; }
|
|
public async Task<bool> CanExecuteAsync(TContext context, CancellationToken token)
|
|
{
|
|
try
|
|
{
|
|
token.ThrowIfCancellationRequested();
|
|
return await CanExecuteProvider(context, token);
|
|
}
|
|
catch (OperationCanceledException ex)
|
|
{
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Looger.Error(ex);
|
|
return false;
|
|
}
|
|
}
|
|
protected virtual Task<bool> CanExecuteProvider(TContext context, CancellationToken token) => Task.FromResult(true);
|
|
|
|
public async Task ExecuteAsync(TContext context, CancellationToken token)
|
|
{
|
|
try
|
|
{
|
|
token.ThrowIfCancellationRequested();
|
|
await ExecuteProvider(context, token);
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
Looger.Error(ex);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
protected abstract Task ExecuteProvider(TContext context, CancellationToken token);
|
|
|
|
public void Dispose()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|