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 : IPublishStep, IDisposable where TContext : PublishContextBase { protected ILoggerFacade Looger => LazyServiceProvider.Instance.LazyGetService(); protected ICurrentUser CurrentUser => LazyServiceProvider.Instance.LazyGetService(); public abstract string Description { get; } public async Task 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 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(); } }