using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Store.Product.Publish; public class PublishPipeline where TContext : PublishContextBase { private readonly IEnumerable> _steps; public PublishPipeline(IEnumerable> steps) { _steps = steps; } public async Task ExecuteAsync( TContext context, CancellationToken token = default) { try { foreach (var step in _steps) { token.ThrowIfCancellationRequested(); if (await step.CanExecuteAsync(context, token)) { await step.ExecuteAsync(context, token); } // 步骤正常提前结束(提交成功/上传到草稿箱)时会写入 Result 并标记完成,此处跳出后续步骤。 if (context.Parameters?.IsCompleted == true) { break; } } } catch (Store.Product.Publish.Steps.Wx.PublishCompletedException ex) { context.Parameters.Result = ex.Result; context.Parameters.IsCompleted = true; } catch (OperationCanceledException) { throw; } catch (Exception) { throw; } } }