├── logo.png ├── OSS.PipeLine ├── Base │ ├── Mos │ │ ├── SignalFlag.cs │ │ ├── EmptyContext.cs │ │ ├── PipeRoute.cs │ │ ├── PipeLineOption.cs │ │ ├── PipeType.cs │ │ └── TrafficSignal.cs │ ├── Interface │ │ ├── IPipeAppender.cs │ │ ├── IPipeMeta.cs │ │ └── IPipeInPart.cs │ ├── Extension │ │ ├── PipeExtension.Gateway.cs │ │ ├── PipeExtension.cs │ │ ├── PipeExtension.Activity.cs │ │ └── PipeExtension.Msg.cs │ ├── Base │ │ ├── InterImpls │ │ │ └── PipeRetryEvent.cs │ │ ├── BasePipePart.cs │ │ └── BasePipe.cs │ ├── BaseThreeWayPipe.cs │ ├── BaseThreeWayPassivePipe.cs │ └── BaseFourWayPipe.cs ├── Utils │ └── InterUtil.cs ├── Activity │ ├── Default │ │ ├── SimpleFuncEffectActivity.cs │ │ ├── EmptyActivity.cs │ │ ├── SimpleFuncActivity.cs │ │ ├── SimpleEffectActivity.cs │ │ └── SimpleActivity.cs │ ├── BasePassiveEffectActivity.cs │ ├── BaseEffectActivity.cs │ ├── BasePassiveActivity.cs │ └── BaseActivity.cs ├── Pipeline │ ├── EmptyEntryPipeline.cs │ ├── InterImpls │ │ └── Watcher │ │ │ ├── WatchResult.cs │ │ │ ├── WatchDataItem.cs │ │ │ └── PipeWatcherProxy.cs │ ├── Interface │ │ ├── IPipeLine.cs │ │ └── IPipeLineWatcher.cs │ ├── Extension │ │ └── PipeLineExtension.cs │ └── Pipeline.cs ├── Msg │ ├── Default │ │ ├── SimpleMsgSubscriber.cs │ │ ├── SimpleMsgEnumerator.cs │ │ ├── SimpleMsgConvertor.cs │ │ ├── SimpleMsgFlow.cs │ │ └── SimpleMsgPublisher.cs │ ├── BaseMsgConverter.cs │ ├── BaseMsgSubcriber.cs │ ├── MsgEnumerator.cs │ ├── BaseMsgPublisher.cs │ └── BaseMsgFlow.cs ├── OSS.PipeLine.csproj └── Gateway │ ├── Extension │ ├── BranchExtension.cs │ ├── BranchExtension.Msg.cs │ └── BranchExtension.Activity.cs │ ├── Default │ └── SimpleBranchGateway.cs │ ├── InterImpls │ └── BranchNodeWrap.cs │ └── BaseBranchGateway.cs ├── OSS.PipeLine.Tests ├── Flow │ ├── FlowItems │ │ ├── PayGateway.cs │ │ ├── AutoAuditActivity.cs │ │ ├── ApplyActivity.cs │ │ ├── PayActivity.cs │ │ ├── StockActivity.cs │ │ └── SendEmailActivity.cs │ ├── FlowWatcher.cs │ └── BuyFlow.cs ├── OSS.PipeLine.Tests.csproj ├── BuyFlowTests.cs └── Order │ └── Activities.cs ├── OSS.PipeLine.sln ├── .gitignore ├── README.md └── LICENSE /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinWG/OSS.PipeLine/HEAD/logo.png -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Mos/SignalFlag.cs: -------------------------------------------------------------------------------- 1 | namespace OSS.Pipeline; 2 | 3 | /// 4 | /// 通行信号 5 | /// 6 | public enum SignalFlag 7 | { 8 | /// 9 | /// 正常通过 10 | /// 11 | Green_Pass, 12 | 13 | /// 14 | /// 暂时等待 15 | /// 16 | Yellow_Wait, 17 | 18 | /// 19 | /// 异常阻塞 20 | /// 21 | Red_Block 22 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Utils/InterUtil.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace OSS.Pipeline.InterImpls 4 | { 5 | internal static class InterUtil 6 | { 7 | //public static readonly Task GreenTrafficResultTask =Task.FromResult(TrafficResult.GreenResult); 8 | 9 | public static readonly Task GreenTrafficSignalTask = Task.FromResult(TrafficSignal.GreenSignal); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/Flow/FlowItems/PayGateway.cs: -------------------------------------------------------------------------------- 1 | using OSS.Pipeline.Interface; 2 | using OSS.Tools.Log; 3 | 4 | namespace OSS.Pipeline.Tests.FlowItems 5 | { 6 | public class PayGateway : BaseBranchGateway 7 | { 8 | public PayGateway():base("PayGateway") 9 | { 10 | } 11 | 12 | protected override bool FilterBranchCondition(PayContext branchContext, IPipeMeta branch) 13 | { 14 | LogHelper.Info($"通过{PipeCode} 判断分支 {branch.PipeCode} 是否满足分流条件!"); 15 | return base.FilterBranchCondition(branchContext, branch); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/Flow/FlowItems/AutoAuditActivity.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using OSS.Tools.Log; 3 | 4 | namespace OSS.Pipeline.Tests.FlowItems 5 | { 6 | public class AutoAuditActivity : BaseEffectActivity 7 | { 8 | public AutoAuditActivity():base("AuditActivity") 9 | { 10 | } 11 | 12 | 13 | 14 | protected override Task> Executing(long id) 15 | { 16 | LogHelper.Info($"通过{PipeCode} 自动审核通过申请(编号:{id})"); 17 | return Task.FromResult(new TrafficSignal(true)); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/Flow/FlowItems/ApplyActivity.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using OSS.Tools.Log; 3 | 4 | namespace OSS.Pipeline.Tests.FlowItems 5 | { 6 | public class ApplyActivity : BaseEffectActivity 7 | { 8 | public ApplyActivity():base("ApplyActivity") 9 | { 10 | } 11 | 12 | protected override Task> Executing(ApplyContext para) 13 | { 14 | LogHelper.Info($" 通过{PipeCode}发起 [{para.name}] 采购申请"); 15 | return Task.FromResult(new TrafficSignal(100000001L)); 16 | } 17 | } 18 | 19 | public class ApplyContext 20 | { 21 | public string name { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/Flow/FlowItems/PayActivity.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using OSS.Tools.Log; 3 | 4 | namespace OSS.Pipeline.Tests.FlowItems 5 | { 6 | public class PayActivity : BasePassiveActivity 7 | { 8 | public PayActivity():base("PayActivity") 9 | { 10 | } 11 | 12 | 13 | protected override Task> Executing(PayContext para) 14 | { 15 | LogHelper.Info($"通过{PipeCode} 支付动作执行,数量:{para.count},金额:{para.money})"); 16 | return Task.FromResult(new TrafficSignal(true)); 17 | } 18 | } 19 | 20 | public class PayContext 21 | { 22 | public int count { get; set; } 23 | public decimal money { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Mos/EmptyContext.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 空上下文 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | namespace OSS.Pipeline 15 | { 16 | /// 17 | /// 空值 18 | /// 19 | public readonly struct Empty 20 | { 21 | /// 22 | /// 默认空上下文 23 | /// 24 | public static Empty Default { get; } 25 | 26 | static Empty() { 27 | Default = new Empty(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Mos/PipeRoute.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道路由 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System.Collections.Generic; 15 | 16 | namespace OSS.Pipeline 17 | { 18 | /// 19 | /// 管道路由信息 20 | /// 21 | public class PipeLink 22 | { 23 | /// 24 | /// 上级管道编码 25 | /// 26 | public string pre_pipe_code { get; set; } 27 | 28 | /// 29 | /// 管道编码 30 | /// 31 | public string pipe_code { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/OSS.PipeLine.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Interface/IPipeAppender.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 流体基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-28 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | namespace OSS.Pipeline.Interface 15 | { 16 | /// 17 | /// 管道链接器 18 | /// 19 | /// 20 | public interface IPipeAppender : IPipeAppender 21 | { 22 | internal void InterAppend(IPipeInPart nextPipe); 23 | } 24 | 25 | /// 26 | /// 管道链接器 27 | /// 28 | public interface IPipeAppender : IPipeMeta 29 | { 30 | internal void InterAppend(IPipeInPart nextPipe); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Activity/Default/SimpleFuncEffectActivity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace OSS.Pipeline 5 | { 6 | /// 7 | public class SimplePassiveEffectActivity :BasePassiveEffectActivity 8 | { 9 | private readonly Func>> _exeFunc; 10 | 11 | /// 12 | public SimplePassiveEffectActivity(string pipeCode,Func>> exeFunc):base(pipeCode) 13 | { 14 | if (!string.IsNullOrEmpty(pipeCode)) 15 | { 16 | PipeCode = pipeCode; 17 | } 18 | _exeFunc = exeFunc ?? throw new ArgumentNullException(nameof(exeFunc), "执行方法不能为空!"); 19 | } 20 | 21 | 22 | /// 23 | protected override Task> Executing(TPassivePara contextData) 24 | { 25 | return _exeFunc(contextData); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/Flow/FlowWatcher.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using OSS.Pipeline.Interface; 3 | using OSS.Tools.Log; 4 | 5 | namespace OSS.Pipeline.Tests.Flow 6 | { 7 | public class FlowWatcher:IPipeLineWatcher 8 | { 9 | public Task PreCall(string pipeCode, PipeType pipeType, object input) 10 | { 11 | LogHelper.Info($"进入 {pipeCode} 管道","PipePreCall","PipelineWatcher"); 12 | return Task.CompletedTask; 13 | } 14 | 15 | public Task Executed(string pipeCode, PipeType pipeType, object input, WatchResult watchResult) 16 | { 17 | LogHelper.Info($"管道 {pipeCode} 执行结束,结束信号:{watchResult.signal}", "PipeExecuted", "PipelineWatcher"); 18 | return Task.CompletedTask; 19 | } 20 | 21 | public Task Blocked(string pipeCode, PipeType pipeType, object input, WatchResult watchResult) 22 | { 23 | LogHelper.Info($"管道 {pipeCode} 阻塞", "PipeBlocked", "PipelineWatcher"); 24 | return Task.CompletedTask; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/Flow/FlowItems/StockActivity.cs: -------------------------------------------------------------------------------- 1 | using OSS.Tools.Log; 2 | using System.Threading.Tasks; 3 | 4 | namespace OSS.Pipeline.Tests.FlowItems 5 | { 6 | public class StockActivity : BaseActivity 7 | { 8 | public StockActivity():base("StockActivity") 9 | { 10 | } 11 | 12 | protected override Task Executing(StockContext data) 13 | { 14 | LogHelper.Info($"分流-2({PipeCode})增加库存,数量:" + data.count); 15 | return Task.FromResult(TrafficSignal.GreenSignal); 16 | } 17 | } 18 | 19 | public class StockContext 20 | { 21 | public int count { get; set; } 22 | } 23 | 24 | public class StockConnector : BaseMsgConverter 25 | { 26 | public StockConnector():base("StockConnector") 27 | { 28 | } 29 | 30 | protected override StockContext Convert(PayContext inContextData) 31 | { 32 | return new StockContext() {count = inContextData.count}; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Mos/PipeLineOption.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 外部动作活动 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.DataFlow; 15 | using OSS.Pipeline.Interface; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 管道流可选项 21 | /// 22 | public class PipeLineOption 23 | { 24 | /// 25 | /// 监控器 26 | /// 27 | public IPipeLineWatcher Watcher { get; set; } 28 | 29 | /// 30 | /// 监控器使用的消息流 31 | /// 32 | public string WatcherDataFlowKey { get; set; } 33 | 34 | /// 35 | /// 监控器消息流的可选项 36 | /// 37 | public DataFlowOption WatcherDataFlowOption { get; set; } 38 | } 39 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Extension/PipeExtension.Gateway.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道扩展 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.Pipeline.Interface; 15 | 16 | namespace OSS.Pipeline 17 | { 18 | /// 19 | /// 管道扩展类 20 | /// 21 | public static partial class PipeExtension 22 | { 23 | /// 24 | /// 追加分支管道 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | public static void Append(this IPipeAppender pipe, BaseBranchGateway nextPipe) 31 | { 32 | pipe.InterAppend(nextPipe); 33 | } 34 | 35 | } 36 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Pipeline/EmptyEntryPipeline.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using OSS.Pipeline.Base; 3 | using OSS.Pipeline.Interface; 4 | 5 | namespace OSS.Pipeline 6 | { 7 | /// 8 | public class EmptyEntryPipeline : Pipeline 9 | { 10 | /// 11 | public EmptyEntryPipeline(IPipeInPart startPipe, IPipeAppender endPipeAppender, string pipeCode=null) 12 | : base(startPipe, endPipeAppender, pipeCode) 13 | { 14 | } 15 | 16 | /// 17 | public EmptyEntryPipeline(IPipeInPart startPipe, IPipeAppender endPipeAppender, PipeLineOption option,string pipeCode= null) 18 | : base( startPipe, endPipeAppender, option,pipeCode) 19 | { 20 | 21 | } 22 | 23 | #region 管道启动 24 | /// 25 | /// 启动 26 | /// 27 | /// 28 | public Task Execute() 29 | { 30 | return InterPreCall(Empty.Default); 31 | } 32 | 33 | #endregion 34 | } 35 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/Default/SimpleMsgSubscriber.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 默认消息订阅者实现 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.DataFlow; 15 | 16 | namespace OSS.Pipeline 17 | { 18 | /// 19 | /// 消息订阅者 20 | /// 21 | /// 22 | public class SimpleMsgSubscriber:BaseMsgSubscriber 23 | { 24 | /// 25 | public SimpleMsgSubscriber(string msgKey, string pipeCode = null) : base(msgKey, pipeCode) 26 | { 27 | } 28 | 29 | 30 | /// 31 | protected override void RegisterSubscriber(string pipeDataKey, IDataSubscriber subscriber) 32 | { 33 | DataFlowFactory.RegisterSubscriber(pipeDataKey, subscriber); 34 | } 35 | 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/Default/SimpleMsgEnumerator.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2021 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.PipeLine - 简单消息枚举器 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2021-7-5 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using System.Collections.Generic; 16 | using OSS.Pipeline; 17 | 18 | namespace OSS.PipeLine.Msg.Default 19 | { 20 | /// 21 | /// 简单消息枚举器(继承至 IList 22 | /// 23 | /// 24 | public class SimpleMsgList : MsgEnumerator, TMsg> 25 | { 26 | /// 27 | /// 简单消息枚举器(继承至 IList 28 | /// 29 | /// 30 | /// 31 | public SimpleMsgList(string pipeCode = null, Func, IList> msgFilter = null) : 32 | base(pipeCode, msgFilter) 33 | { 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /OSS.PipeLine/Pipeline/InterImpls/Watcher/WatchResult.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 外部动作活动 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | namespace OSS.Pipeline 15 | { 16 | public class WatchResult: TrafficSignal 17 | { 18 | public WatchResult(SignalFlag signal, object activityResult, string msg):base(signal,msg) 19 | { 20 | activity_result = activityResult; 21 | } 22 | 23 | /// 24 | /// 活动(activity)的执行结果 25 | /// 26 | public object activity_result { get; } 27 | } 28 | internal static class WatchResultMap 29 | { 30 | public static WatchResult ToWatchResult(this TrafficSignal tRes) 31 | { 32 | return new WatchResult(tRes.signal, tRes.result, tRes.msg); 33 | } 34 | 35 | } 36 | } -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/Flow/FlowItems/SendEmailActivity.cs: -------------------------------------------------------------------------------- 1 | 2 | using OSS.Tools.Log; 3 | using System.Threading.Tasks; 4 | 5 | namespace OSS.Pipeline.Tests.FlowItems 6 | { 7 | public class SendEmailActivity : BaseActivity 8 | { 9 | public SendEmailActivity():base("SendEmailActivity") 10 | { 11 | } 12 | 13 | protected override Task Executing(SendEmailContext data) 14 | { 15 | LogHelper.Info($"分流-1({PipeCode})邮件发送,内容:" + data.body); 16 | return Task.FromResult(TrafficSignal.GreenSignal); 17 | } 18 | } 19 | 20 | public class SendEmailContext 21 | { 22 | public string body { get; set; } 23 | } 24 | 25 | public class PayEmailConnector : BaseMsgConverter 26 | { 27 | public PayEmailConnector():base("PayEmailConnector") 28 | { 29 | } 30 | protected override SendEmailContext Convert(PayContext inContextData) 31 | { 32 | // ...... 33 | return new SendEmailContext() { body = $" 您成功支付了订单,总额:{inContextData.money}" }; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /OSS.PipeLine/Pipeline/Interface/IPipeLine.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using OSS.Pipeline.InterImpls.Watcher; 3 | 4 | namespace OSS.Pipeline.Interface 5 | { 6 | /// 7 | /// 管道基础接口 8 | /// 9 | internal interface IPipeLine : IPipeMeta 10 | { 11 | /// 12 | /// 开始管道 13 | /// 14 | IPipeMeta StartPipe { get; } 15 | 16 | /// 17 | /// 结束管道 18 | /// 19 | IPipeMeta EndPipe { get; } 20 | 21 | /// 22 | /// 获取路由 23 | /// 24 | /// 25 | List ToRoute(); 26 | 27 | // 获取内部监控代理器 28 | internal PipeWatcherProxy GetWatchProxy(); 29 | 30 | // 获取内部路由字典 31 | internal Dictionary GetLinkDics(); 32 | 33 | } 34 | 35 | /// 36 | /// Pipeline管道 37 | /// 38 | /// 39 | /// 40 | internal interface IPipeLine : IPipeLine //, IPipeLineEntry 41 | { 42 | } 43 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Pipeline/InterImpls/Watcher/WatchDataItem.cs: -------------------------------------------------------------------------------- 1 | namespace OSS.Pipeline 2 | { 3 | /// 4 | /// 5 | /// 6 | public struct WatchDataItem 7 | { 8 | /// 9 | /// 节点编码 10 | /// 11 | public string PipeCode { get; set; } 12 | 13 | /// 14 | /// 节点类型 15 | /// 16 | public PipeType PipeType { get; set; } 17 | 18 | /// 19 | /// 动作类型 20 | /// 21 | public WatchActionType ActionType { get; set; } 22 | 23 | /// 24 | /// 输入参数 25 | /// 26 | public object Para { get; set; } 27 | 28 | /// 29 | /// 结果 30 | /// 31 | public WatchResult Result { get; set; } 32 | } 33 | 34 | public enum WatchActionType 35 | { 36 | /// 37 | /// 上游管道调用 38 | /// 39 | PreCall, 40 | 41 | /// 42 | /// 执行完成 43 | /// 44 | Executed, 45 | 46 | /// 47 | /// 堵塞 48 | /// 49 | Blocked, 50 | } 51 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Activity/Default/EmptyActivity.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Threading.Tasks; 3 | 4 | namespace OSS.Pipeline 5 | { 6 | /// 7 | /// 空组件(多用于开始结尾) 8 | /// 9 | public class EmptyActivity : BaseActivity 10 | { 11 | public EmptyActivity(string pipeCode = null) : base(pipeCode) 12 | { 13 | } 14 | private static readonly Task _result = Task.FromResult(TrafficSignal.GreenSignal); 15 | protected override Task Executing() 16 | { 17 | return _result; 18 | } 19 | } 20 | 21 | /// 22 | /// 空组件(多用于开始结尾) 23 | /// 24 | public class EmptyActivity : BaseActivity 25 | { 26 | /// 27 | /// 空组件 28 | /// 29 | /// 30 | public EmptyActivity(string pipeCode = null) : base(pipeCode) 31 | { 32 | } 33 | 34 | private static readonly Task _result = Task.FromResult(TrafficSignal.GreenSignal); 35 | protected override Task Executing(TContext para) 36 | { 37 | return _result; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /OSS.PipeLine/Pipeline/Interface/IPipeLineWatcher.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 流体监视器 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System.Threading.Tasks; 15 | 16 | namespace OSS.Pipeline.Interface 17 | { 18 | /// 19 | /// 管道监视器 20 | /// 21 | public interface IPipeLineWatcher 22 | { 23 | /// 24 | /// 上游管道通知 25 | /// 26 | public Task PreCall(string pipeCode, PipeType pipeType, object inputContextPara); 27 | 28 | /// 29 | /// 当前执行完成 30 | /// 31 | public Task Executed(string pipeCode, PipeType pipeType, object inputContextPara, WatchResult watchResult); 32 | 33 | /// 34 | /// 管道阻塞 35 | /// 36 | public Task Blocked(string pipeCode, PipeType pipeType, object inputContextPara, WatchResult watchResult); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/Default/SimpleMsgConvertor.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 消息内部实现 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | using System; 14 | 15 | namespace OSS.Pipeline 16 | { 17 | /// 18 | /// 内部转化连接器的实现 19 | /// 20 | /// 21 | /// 22 | public class SimpleMsgConvertor : BaseMsgConverter 23 | { 24 | private readonly Func _convert; 25 | 26 | /// 27 | public SimpleMsgConvertor(Func convertFunc,string pipeCode = null) :base(pipeCode) 28 | { 29 | _convert = convertFunc ?? throw new ArgumentNullException(nameof(convertFunc), "转换方法必须传入!"); 30 | } 31 | 32 | /// 33 | protected override TOut Convert(TIn inContextData) 34 | { 35 | return _convert(inContextData); 36 | } 37 | } 38 | 39 | 40 | 41 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Interface/IPipeMeta.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2021 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 流体基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2021-02-09 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.DataFlow.Event; 15 | 16 | namespace OSS.Pipeline.Interface 17 | { 18 | /// 19 | /// 管道基础接口 20 | /// 21 | public interface IPipeMeta 22 | { 23 | /// 24 | /// 管道类型 25 | /// 26 | PipeType PipeType { get; } 27 | 28 | /// 29 | /// 管道编码 30 | /// 31 | string PipeCode { get; set; } 32 | } 33 | 34 | /// 35 | /// 管道接口 36 | /// 37 | /// 38 | /// 39 | public interface IPipe : IPipeInPart, IPipeAppender, IPipeRetry 40 | { 41 | } 42 | 43 | public interface IPipeRetry 44 | { 45 | internal void SetErrorRetry(FlowEventOption option); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/Default/SimpleMsgFlow.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 默认消息流体实现 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | using OSS.DataFlow; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 消息流 21 | /// 22 | /// 23 | internal class SimpleMsgFlow : BaseMsgFlow 24 | { 25 | /// 26 | public SimpleMsgFlow(string msgKey, string pipeCode = null) : base(msgKey, pipeCode) 27 | { 28 | } 29 | 30 | /// 31 | public SimpleMsgFlow(string msgKey, DataFlowOption option, string pipeCode = null) : base(msgKey, option, pipeCode) 32 | { 33 | } 34 | 35 | protected override IDataPublisher CreateFlow(string pipeDataKey, IDataSubscriber subscriber, DataFlowOption option) 36 | { 37 | return DataFlowFactory.RegisterFlow(pipeDataKey, subscriber, option); 38 | } 39 | 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /OSS.PipeLine/Activity/Default/SimpleFuncActivity.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 外部动作活动 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | using System; 16 | using System.Threading.Tasks; 17 | 18 | namespace OSS.Pipeline 19 | { 20 | 21 | /// 22 | public class SimplePassiveActivity : BasePassiveActivity 23 | { 24 | private readonly Func>> _exeFunc; 25 | 26 | /// 27 | public SimplePassiveActivity(string pipeCode,Func>> exeFunc):base(pipeCode) 28 | { 29 | if (!string.IsNullOrEmpty(pipeCode)) 30 | { 31 | PipeCode = pipeCode; 32 | } 33 | _exeFunc = exeFunc ?? throw new ArgumentNullException(nameof(exeFunc), "执行方法不能为空!"); 34 | } 35 | 36 | 37 | /// 38 | protected override Task> Executing(TPassivePara contextData) 39 | { 40 | return _exeFunc(contextData); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /OSS.PipeLine/OSS.PipeLine.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 事件流管理引擎框架,处理事件中的数据传递和协作,可用于搭建 BPMN 标准的流程业务管理 6 | 2.6.1 7 | 8 | latest 9 | https://github.com/KevinWG/OSS.Pipeline 10 | https://github.com/KevinWG/OSS.Pipeline 11 | logo.png 12 | True 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | True 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /OSS.PipeLine/Gateway/Extension/BranchExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OSS.Pipeline.Interface; 3 | 4 | namespace OSS.Pipeline; 5 | 6 | public static partial class BranchExtension 7 | { 8 | /// 9 | /// 添加条件分支 10 | /// 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 分支条件判断 16 | /// 17 | public static IPipe Append(this IBranchGateway pipe, Func branchCondition, IPipe nextPipe) 18 | { 19 | pipe.SetCondition(nextPipe, branchCondition); 20 | pipe.InterAppend(nextPipe); 21 | 22 | return nextPipe; 23 | } 24 | 25 | /// 26 | /// 添加条件分支 27 | /// 28 | /// 29 | /// 当前分支输出类型 30 | /// 31 | /// 32 | /// 分支条件判断 33 | /// 34 | public static IPipe Append(this IBranchGateway pipe, Func branchCondition, IPipe nextPipe) 35 | { 36 | pipe.SetCondition(nextPipe, branchCondition); 37 | pipe.InterAppend(nextPipe); 38 | 39 | return nextPipe; 40 | } 41 | } -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/BuyFlowTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OSS.Pipeline.Tests.FlowItems; 4 | using OSS.Pipeline.Tests.Order; 5 | 6 | namespace OSS.Pipeline.Tests 7 | { 8 | [TestClass] 9 | public class BuyFlowTests 10 | { 11 | private static readonly BuyFlow _flow = new BuyFlow(); 12 | 13 | [TestMethod] 14 | public async Task FlowTest() 15 | { 16 | await _flow.ApplyActivity.Execute(new ApplyContext() 17 | { 18 | name = "冰箱" 19 | }); 20 | 21 | // 延后一秒,假装有支付操作 22 | await Task.Delay(1000); 23 | 24 | await _flow.PayActivity.Execute(new PayContext() 25 | { 26 | count = 10, 27 | money = 10000 28 | }); 29 | await Task.Delay(1000);// 等待异步日志执行完成 30 | } 31 | 32 | [TestMethod] 33 | public void RouteTest() 34 | { 35 | var route = _flow.ToRoute(); 36 | Assert.IsTrue(route != null); 37 | } 38 | 39 | 40 | private static readonly OrderPayPipeline payLine = new OrderPayPipeline(); 41 | 42 | [TestMethod] 43 | public async Task TestOrder() 44 | { 45 | var payRes =await payLine.PayOrder(new OrderPayReq() {OrderId = 111, PayMoney = 1000.00m}); 46 | 47 | await Task.Delay(100); 48 | Assert.IsTrue(payRes); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /OSS.PipeLine/Gateway/Default/SimpleBranchGateway.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2021 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.PipeLine - 简单分支网关实现 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2021-7-5 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.Pipeline.Interface; 15 | using System; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 简单分支 21 | /// 22 | /// 23 | public class SimpleBranchGateway : BaseBranchGateway 24 | { 25 | private readonly Func _conditionFilter; 26 | 27 | /// 28 | /// 简单分支 29 | /// 30 | /// 31 | /// 32 | public SimpleBranchGateway(Func branchConditionfilter = null,string pipeCode = null) : 33 | base(pipeCode) 34 | { 35 | _conditionFilter = branchConditionfilter; 36 | } 37 | 38 | /// 39 | protected override bool FilterBranchCondition(TContext branchContext, IPipeMeta branch) 40 | { 41 | return _conditionFilter?.Invoke(branchContext, branch) ?? true; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Interface/IPipeInPart.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 流体基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-28 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | using System.Threading.Tasks; 16 | using OSS.DataFlow.Event; 17 | 18 | namespace OSS.Pipeline.Interface 19 | { 20 | public interface IPipeInitiator : IPipeMeta 21 | { 22 | #region 容器和路由信息处理 23 | 24 | /// 25 | /// 内部处理流的路由信息 26 | /// 27 | /// 28 | internal void InterFormatLink(string prePipeCode, bool isSelf); 29 | 30 | /// 31 | /// 内部处理流容器初始化赋值 32 | /// 33 | /// 34 | internal abstract void InterInitialContainer(IPipeLine containerFlow); 35 | 36 | 37 | #endregion 38 | 39 | 40 | } 41 | 42 | /// 43 | /// 管道入口 44 | /// 45 | /// 46 | public interface IPipeInPart : IPipeInitiator 47 | { 48 | /// 49 | /// 内部管道 -- 唤起 50 | /// 51 | /// 52 | /// 53 | internal Task InterWatchPreCall(TIn context); 54 | 55 | } 56 | 57 | 58 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/BaseMsgConverter.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 连接基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | using System.Threading.Tasks; 16 | using OSS.Pipeline.Base; 17 | 18 | namespace OSS.Pipeline 19 | { 20 | /// 21 | /// 消息转化基类 22 | /// 23 | /// 24 | /// 25 | public abstract class BaseMsgConverter : BaseThreeWayPipe 26 | { 27 | /// 28 | /// 消息转化基类 29 | /// 30 | protected BaseMsgConverter(string pipeCode = null) : base(pipeCode, PipeType.MsgConverter) 31 | { 32 | } 33 | 34 | /// 35 | /// 连接消息体的转换功能 36 | /// 37 | /// 38 | /// 39 | protected abstract TOutMsg Convert(TInMsg inContextData); 40 | 41 | /// 42 | internal override Task> InterProcessing(TInMsg context) 43 | { 44 | var outContext = Convert(context); 45 | return Task.FromResult(new TrafficSignal( outContext,outContext)); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Base/InterImpls/PipeRetryEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using OSS.DataFlow.Event; 4 | 5 | namespace OSS.PipeLine.Base.Base.InterImpls 6 | { 7 | /// 8 | /// 重试处理器 9 | /// 10 | /// 11 | /// 12 | internal class PipeRetryEventProcessor 13 | : FlowEventProcessor, TRes> 14 | { 15 | public PipeRetryEventProcessor(Func, Task> eventFunc, FlowEventOption option) : base( 16 | new PipeRetryEvent(eventFunc), option) 17 | { 18 | } 19 | } 20 | 21 | internal class PipeRetryEvent : IFlowEvent, TRes> 22 | { 23 | private readonly Func, Task> _eventFunc; 24 | 25 | public PipeRetryEvent(Func, Task> eventFunc) 26 | { 27 | _eventFunc = eventFunc; 28 | } 29 | 30 | public Task Execute(RetryEventMsg input) 31 | { 32 | return _eventFunc(input); 33 | } 34 | 35 | public Task Failed(RetryEventMsg input) 36 | { 37 | return Task.CompletedTask; 38 | } 39 | } 40 | 41 | 42 | internal readonly struct RetryEventMsg 43 | { 44 | public RetryEventMsg(TPara para) 45 | { 46 | //pre_pipe_code = prePipeCode; 47 | this.para = para; 48 | } 49 | 50 | //public string pre_pipe_code { get; } 51 | 52 | public TPara para { get; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/BaseThreeWayPipe.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 外部动作活动 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | using System.Threading.Tasks; 16 | 17 | namespace OSS.Pipeline.Base 18 | { 19 | /// 20 | /// 管道执行基类(主动三向类型 ) 21 | /// 输入:上游传递的上下文 22 | /// 输出:主动结果输出, 下游上下文参数输出 23 | /// 24 | /// 25 | /// 26 | /// 27 | public abstract class BaseThreeWayPipe : BaseFourWayPipe 28 | { 29 | /// 30 | protected BaseThreeWayPipe(string pipeCode, PipeType pipeType) : base(pipeCode, pipeType) 31 | { 32 | } 33 | 34 | #region 流体外部扩展 35 | 36 | /// 37 | /// 外部执行方法 - 启动入口 38 | /// 39 | /// 40 | /// 41 | public async Task Execute(TIn para) 42 | { 43 | return (await InterProcess(para)).result; 44 | } 45 | 46 | #endregion 47 | 48 | 49 | #region 流体内部业务处理 50 | 51 | /// 52 | internal override async Task InterPreCall(TIn context) 53 | { 54 | return await InterProcess(context); 55 | } 56 | 57 | #endregion 58 | } 59 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Activity/Default/SimpleEffectActivity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace OSS.Pipeline 5 | { 6 | 7 | 8 | /// 9 | public class SimpleEffectActivity : BaseEffectActivity 10 | { 11 | private readonly Func>> _exeFunc; 12 | 13 | /// 14 | public SimpleEffectActivity( Func>> exeFunc,string pipeCode=null) :base(pipeCode) 15 | { 16 | _exeFunc = exeFunc ?? throw new ArgumentNullException(nameof(exeFunc), "执行方法不能为空!"); 17 | } 18 | 19 | /// 20 | protected override Task> Executing() 21 | { 22 | return _exeFunc(); 23 | } 24 | } 25 | 26 | 27 | /// 28 | public class SimpleEffectActivity: BaseEffectActivity// : BaseStraightPipe 29 | { 30 | private readonly Func>> _exeFunc; 31 | 32 | /// 33 | public SimpleEffectActivity(Func>> exeFunc, string pipeCode = null) :base(pipeCode) 34 | { 35 | if (!string.IsNullOrEmpty(pipeCode)) 36 | { 37 | PipeCode = pipeCode; 38 | } 39 | _exeFunc = exeFunc ?? throw new ArgumentNullException(nameof(exeFunc), "执行方法不能为空!"); 40 | } 41 | 42 | /// 43 | protected override Task> Executing(TPassivePara para) 44 | { 45 | return _exeFunc(para); 46 | } 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/Default/SimpleMsgPublisher.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 默认消息发布者实现 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using OSS.DataFlow; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 消息发布者 21 | /// 22 | /// 23 | public class SimpleMsgPublisher : BaseMsgPublisher 24 | { 25 | private readonly Func _pushKeyGenerator; 26 | 27 | /// 28 | public SimpleMsgPublisher(Func pushKeyCreator, DataPublisherOption option = null, string pipeCode = null) : this(string.Empty, option, pipeCode) 29 | { 30 | _pushKeyGenerator = pushKeyCreator; 31 | } 32 | 33 | /// 34 | public SimpleMsgPublisher(string msgKey, DataPublisherOption option = null, string pipeCode = null) : base(msgKey, option, pipeCode) 35 | { 36 | } 37 | 38 | /// 39 | protected override string GeneratePushKey(TMsg msg) 40 | { 41 | return _pushKeyGenerator!=null ? _pushKeyGenerator?.Invoke(msg) : base.GeneratePushKey(msg); 42 | } 43 | 44 | /// 45 | protected override IDataPublisher CreatePublisher(DataPublisherOption option) 46 | { 47 | return DataFlowFactory.CreatePublisher(option); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/BaseThreeWayPassivePipe.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 外部动作活动 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.Pipeline.InterImpls; 15 | using System.Threading.Tasks; 16 | 17 | namespace OSS.Pipeline.Base 18 | { 19 | /// 20 | /// 管道基类(被动三向类型 ) 21 | /// 输入:被动入参 (隐形忽略上游传参 22 | /// 输出:被动结果输出, 下游上下文参数输出 23 | /// 24 | /// 25 | /// 26 | /// 27 | public abstract class BaseThreeWayPassivePipe : 28 | BaseFourWayPipe //,IPipeExecutor 29 | { 30 | /// 31 | /// 外部Action活动基类 32 | /// 33 | protected BaseThreeWayPassivePipe(string pipeCode,PipeType pipeType) : base(pipeCode,pipeType) 34 | { 35 | } 36 | 37 | /// 38 | /// 直接执行 39 | /// 40 | /// 41 | /// 42 | public async Task Execute(TPara para) 43 | { 44 | var trafficRes = await InterProcess(para); 45 | return trafficRes.result; 46 | } 47 | 48 | #region 内部的业务处理 49 | 50 | /// 51 | internal override Task InterPreCall(Empty context) 52 | { 53 | return InterUtil.GreenTrafficSignalTask; 54 | } 55 | 56 | #endregion 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Mos/PipeType.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道类型 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | 16 | namespace OSS.Pipeline 17 | { 18 | /// 19 | /// 管道类型 20 | /// 21 | [Flags] 22 | public enum PipeType 23 | { 24 | /// 25 | /// 活动 26 | /// 27 | Activity = 1, 28 | /// 29 | /// 受控活动 30 | /// 31 | EffectActivity = 2, 32 | 33 | /// 34 | /// 被动活动 35 | /// 36 | PassiveActivity = 4, 37 | 38 | /// 39 | /// 聚合网关 40 | /// 41 | AggregateGateway = 8, 42 | 43 | /// 44 | /// 分支网关 45 | /// 46 | BranchGateway = 16, 47 | 48 | /// 49 | /// 消息流 50 | /// 51 | MsgFlow = 32, 52 | 53 | /// 54 | /// 消息发布者 55 | /// 56 | MsgPublisher = 64, 57 | 58 | /// 59 | /// 消息订阅者 60 | /// 61 | MsgSubscriber = 128, 62 | 63 | /// 64 | /// 消息订阅者 65 | /// 66 | MsgConverter = 256, 67 | 68 | /// 69 | /// 消息枚举器(循环处理 70 | /// 71 | MsgEnumerator = 512, 72 | 73 | /// 74 | /// 组合管道线 75 | /// 76 | Pipeline = 1024 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/Flow/BuyFlow.cs: -------------------------------------------------------------------------------- 1 | using OSS.Pipeline.Tests.Flow; 2 | using OSS.Pipeline.Tests.FlowItems; 3 | 4 | namespace OSS.Pipeline.Tests 5 | { 6 | public class BuyFlow : Pipeline 7 | { 8 | 9 | private static readonly ApplyActivity _startNode = new ApplyActivity(); 10 | private static readonly EmptyActivity _endNode = new EmptyActivity(); 11 | 12 | public ApplyActivity ApplyActivity => _startNode; 13 | 14 | public AutoAuditActivity AuditActivity { get; } = new AutoAuditActivity(); 15 | 16 | public PayActivity PayActivity { get; } = new PayActivity(); 17 | public PayGateway PayGateway { get; } = new PayGateway(); 18 | 19 | public StockConnector StockConnector { get; } = new StockConnector(); 20 | public StockActivity StockActivity { get; } = new StockActivity(); 21 | 22 | public PayEmailConnector EmailConnector { get; } = new PayEmailConnector(); 23 | public SendEmailActivity EmailActivity { get; } = new SendEmailActivity(); 24 | 25 | // 构造函数内定义流体关联 26 | public BuyFlow() : base( _startNode, _endNode, new PipeLineOption() {Watcher = new FlowWatcher()}) 27 | { 28 | } 29 | 30 | protected override void InitialPipes() 31 | { 32 | ApplyActivity 33 | .Append(AuditActivity) 34 | 35 | .Append(PayActivity) 36 | .Append(PayGateway); 37 | 38 | // 网关分支 - 发送邮件分支 39 | PayGateway 40 | .Append(EmailConnector) 41 | .Append(EmailActivity) 42 | .Append(_endNode); 43 | 44 | // 网关分支- 入库分支 45 | PayGateway 46 | .Append(StockConnector) 47 | .Append(StockActivity) 48 | .Append(_endNode); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /OSS.PipeLine.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32616.157 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9A134B11-1BBA-4CBB-A70C-3C9D412C342A}" 7 | ProjectSection(SolutionItems) = preProject 8 | README.md = README.md 9 | EndProjectSection 10 | EndProject 11 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OSS.Pipeline", "OSS.PipeLine\OSS.Pipeline.csproj", "{530100A4-E305-4834-A21A-3BA19834F67D}" 12 | EndProject 13 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OSS.Pipeline.Tests", "OSS.PipeLine.Tests\OSS.Pipeline.Tests.csproj", "{AAED04FB-ABD1-485E-9481-47B4A8605155}" 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {530100A4-E305-4834-A21A-3BA19834F67D}.Debug|Any CPU.ActiveCfg = Release|Any CPU 22 | {530100A4-E305-4834-A21A-3BA19834F67D}.Debug|Any CPU.Build.0 = Release|Any CPU 23 | {530100A4-E305-4834-A21A-3BA19834F67D}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {530100A4-E305-4834-A21A-3BA19834F67D}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {AAED04FB-ABD1-485E-9481-47B4A8605155}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {AAED04FB-ABD1-485E-9481-47B4A8605155}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {AAED04FB-ABD1-485E-9481-47B4A8605155}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {AAED04FB-ABD1-485E-9481-47B4A8605155}.Release|Any CPU.Build.0 = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(SolutionProperties) = preSolution 31 | HideSolutionNode = FALSE 32 | EndGlobalSection 33 | GlobalSection(ExtensibilityGlobals) = postSolution 34 | SolutionGuid = {F5D7627E-6294-458A-88F8-15FBBEF5D080} 35 | EndGlobalSection 36 | EndGlobal 37 | -------------------------------------------------------------------------------- /OSS.PipeLine/Activity/BasePassiveEffectActivity.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 外部动作活动 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.Pipeline.Base; 15 | using System.Threading.Tasks; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 被动触发执行活动组件基类 21 | /// 传入TPassivePara类型参数,自身返回处理结果,且结果作为上下文传递给下一个节点 22 | /// 23 | /// 24 | /// 25 | public abstract class BasePassiveEffectActivity : BaseThreeWayPassivePipe //, IPassiveEffectActivity 26 | { 27 | /// 28 | /// 外部Action活动基类 29 | /// 30 | protected BasePassiveEffectActivity(string pipeCode = null) : base(pipeCode, PipeType.EffectActivity | PipeType.EffectActivity) 31 | { 32 | } 33 | 34 | 35 | /// 36 | /// 具体执行扩展方法 37 | /// 38 | /// 当前活动上下文信息 39 | /// 40 | /// -(活动是否处理成功,业务结果) 41 | /// traffic_signal: 42 | /// traffic_signal: 43 | /// Green_Pass - 流体自动流入后续管道 44 | /// Yellow_Wait - 管道流动暂停等待(仅当前处理业务),既不向后流动,也不触发Block。 45 | /// Red_Block - 触发Block,业务流不再向后续管道传递。 46 | /// 47 | protected abstract Task> Executing(TPara para); 48 | 49 | 50 | 51 | internal override async Task> InterProcessing(TPara req) 52 | { 53 | var tSignal = await Executing(req); 54 | return new TrafficSignal(tSignal.signal,tSignal.result, tSignal.result, tSignal.msg); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/BaseMsgSubcriber.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 默认消息订阅者基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using System.Threading.Tasks; 16 | using OSS.DataFlow; 17 | using OSS.Pipeline.Base; 18 | 19 | namespace OSS.Pipeline 20 | { 21 | /// 22 | /// 消息订阅器 23 | /// 24 | /// 25 | public abstract class BaseMsgSubscriber : BaseThreeWayPassivePipe, IDataSubscriber 26 | { 27 | /// 28 | /// 消息订阅器 29 | /// 30 | /// 31 | /// 缓冲DataFlow 对应的Key 默认对应的flow是异步线程池 32 | protected BaseMsgSubscriber(string msgKey, string pipeCode=null) : base(pipeCode, PipeType.MsgSubscriber) 33 | { 34 | if (string.IsNullOrEmpty(msgKey)) 35 | { 36 | throw new ArgumentNullException(nameof(msgKey), "消息类型PipeCode不能为空!"); 37 | } 38 | RegisterSubscriber(msgKey, this); 39 | } 40 | 41 | /// 42 | /// 接收消息订阅器 43 | /// 44 | /// 消息订阅器(引用句柄) 45 | /// 订阅消息key 46 | /// 47 | protected abstract void RegisterSubscriber(string msgKey, IDataSubscriber subscribeHandler); 48 | 49 | /// 50 | /// 订阅消息的动作实现 51 | /// 52 | /// 53 | /// 54 | public async Task Subscribe(TMsg data) 55 | { 56 | return (await InterProcess(data)).signal==SignalFlag.Green_Pass; 57 | } 58 | 59 | internal override Task> InterProcessing(TMsg context) 60 | { 61 | return Task.FromResult(new TrafficSignal(Empty.Default, context)); 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Extension/PipeExtension.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道扩展 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.DataFlow.Event; 15 | using OSS.Pipeline.Interface; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 管道扩展类 21 | /// 22 | public static partial class PipeExtension 23 | { 24 | /// 25 | /// 追加普通管道 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | public static IPipe Append(this IPipeAppender pipe, IPipe nextPipe) 33 | { 34 | pipe.InterAppend(nextPipe); 35 | return nextPipe; 36 | } 37 | 38 | /// 39 | /// 追加普通管道 40 | /// 41 | /// 42 | /// 43 | /// 44 | /// 45 | public static IPipe Append(this IPipeAppender pipe, 46 | IPipe nextPipe) 47 | { 48 | pipe.InterAppend(nextPipe); 49 | return nextPipe; 50 | } 51 | 52 | 53 | /// 54 | /// 绑定异常错误重试 55 | /// 56 | /// 57 | /// 58 | /// 59 | /// 60 | /// 61 | public static IPipe SetErrorRetry(this IPipe pipe, FlowEventOption option) 62 | { 63 | pipe.SetErrorRetry(option); 64 | return pipe; 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/MsgEnumerator.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 连接基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | using System; 16 | using System.Collections.Generic; 17 | using System.Linq; 18 | using System.Threading.Tasks; 19 | using OSS.Pipeline.Base; 20 | 21 | namespace OSS.Pipeline; 22 | 23 | /// 24 | /// 消息转化基类 25 | /// 26 | /// 消息具体类型 27 | public class MsgEnumerator : BaseThreeWayPipe, Empty, TMsg> 28 | { 29 | private readonly Func, IEnumerable> _msgFilter = null; 30 | 31 | /// 32 | /// 消息转化基类 33 | /// 34 | public MsgEnumerator(Func, IEnumerable> msgFilter = null, string pipeCode = null) : base( 35 | pipeCode, PipeType.MsgEnumerator) 36 | { 37 | _msgFilter = msgFilter; 38 | } 39 | 40 | /// 41 | /// 过滤处理消息 42 | /// 43 | /// 44 | /// 45 | protected virtual IEnumerable Filter(IEnumerable msgList) 46 | { 47 | return _msgFilter != null ? _msgFilter(msgList) : msgList; 48 | } 49 | 50 | #region 管道内部业务处理 51 | 52 | /// 53 | internal override async Task> InterProcessingAndDistribute(IEnumerable msgList) 54 | { 55 | var filterMsgList = Filter(msgList); 56 | if (filterMsgList == null || !filterMsgList.Any()) 57 | throw new ArgumentNullException(nameof(msgList), "无消息可以枚举!"); 58 | 59 | var trafficRes = await InterWatchProcessing(filterMsgList); 60 | 61 | if (trafficRes.signal == SignalFlag.Red_Block) 62 | await InterWatchBlock(filterMsgList, trafficRes); 63 | 64 | return trafficRes; 65 | } 66 | 67 | /// 68 | internal override async Task> InterProcessing(IEnumerable msgs) 69 | { 70 | var parallelTasks = msgs.Select(ToNextThrough); 71 | 72 | return (await Task.WhenAll(parallelTasks)).Any(r => r.signal == SignalFlag.Green_Pass) 73 | ? new TrafficSignal(SignalFlag.Green_Pass, Empty.Default, default) 74 | : new TrafficSignal(SignalFlag.Red_Block, Empty.Default, default, "所有分支运行失败!"); 75 | } 76 | 77 | 78 | #endregion 79 | } 80 | 81 | -------------------------------------------------------------------------------- /OSS.PipeLine/Gateway/InterImpls/BranchNodeWrap.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using OSS.Pipeline.Interface; 3 | 4 | namespace OSS.Pipeline.Gateway.InterImpls 5 | { 6 | /// 7 | /// 分支子节点管道 8 | /// 9 | internal interface IBranchWrap //: IPipe 10 | { 11 | internal Task InterPreCall(object context); 12 | 13 | /// 14 | /// 管道基础信息 15 | /// 16 | public IPipeMeta Pipe { get; } 17 | 18 | /// 19 | /// 内部处理流容器初始化赋值 20 | /// 21 | /// 22 | internal abstract void InterInitialContainer(IPipeLine containerFlow); 23 | 24 | /// 25 | /// 内部处理流的路由信息 26 | /// 27 | /// 28 | internal abstract void InterFormatLink(string prePipeCode, bool isSelf ); 29 | } 30 | 31 | internal class BranchNodeWrap: IBranchWrap 32 | { 33 | 34 | public IPipeMeta Pipe 35 | { 36 | get => _pipePart; 37 | } 38 | 39 | 40 | public IPipeInPart _pipePart; 41 | 42 | public BranchNodeWrap(IPipeInPart pipePart) 43 | { 44 | _pipePart = pipePart; 45 | } 46 | 47 | Task IBranchWrap.InterPreCall(object context) 48 | { 49 | return _pipePart.InterWatchPreCall((TContext) context); 50 | } 51 | 52 | void IBranchWrap.InterInitialContainer(IPipeLine containerFlow) 53 | { 54 | _pipePart.InterInitialContainer(containerFlow); 55 | } 56 | 57 | void IBranchWrap.InterFormatLink(string prePipeCode, bool isSelf ) 58 | { 59 | _pipePart.InterFormatLink(prePipeCode,isSelf); 60 | } 61 | } 62 | 63 | internal class BranchNodeWrap : IBranchWrap 64 | { 65 | public IPipeMeta Pipe 66 | { 67 | get => _pipePart; 68 | } 69 | 70 | public IPipeInPart _pipePart; 71 | 72 | public BranchNodeWrap(IPipeInPart pipePart) 73 | { 74 | _pipePart = pipePart; 75 | } 76 | 77 | Task IBranchWrap.InterPreCall(object context) 78 | { 79 | return _pipePart.InterWatchPreCall(Empty.Default); 80 | } 81 | 82 | void IBranchWrap.InterInitialContainer(IPipeLine containerFlow) 83 | { 84 | _pipePart.InterInitialContainer(containerFlow); 85 | } 86 | 87 | void IBranchWrap.InterFormatLink(string prePipeCode, bool isSelf) 88 | { 89 | _pipePart.InterFormatLink(prePipeCode, isSelf); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/BaseMsgPublisher.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 消息发布者基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using System.Threading.Tasks; 16 | using OSS.DataFlow; 17 | using OSS.Pipeline.Base; 18 | 19 | namespace OSS.Pipeline 20 | { 21 | /// 22 | /// 消息发布者基类 23 | /// 24 | /// 25 | public abstract class BaseMsgPublisher : BaseThreeWayPipe 26 | { 27 | // 内部异步处理入口 28 | private readonly IDataPublisher _pusher; 29 | private readonly string _msgKey; 30 | 31 | /// 32 | /// 消息发布者 33 | /// 34 | /// 缓冲DataFlow 对应的消息Key 默认对应的flow实现是异步线程池 35 | /// 36 | /// 37 | protected BaseMsgPublisher(string msgKey, DataPublisherOption option = null, string pipeCode = null) : base(pipeCode, PipeType.MsgPublisher) 38 | { 39 | if (string.IsNullOrEmpty(msgKey)) 40 | { 41 | throw new ArgumentNullException(nameof(msgKey), "消息类型 msgKey 不能为空!"); 42 | } 43 | 44 | _msgKey = msgKey; 45 | _pusher = CreatePublisher(option); 46 | } 47 | 48 | #region 扩展 49 | 50 | /// 51 | /// 生成推送消息对应的key值,默认为 PipeCode(即构造函数中传入的 defaultPushMsgKey) 52 | /// 返回空,则 对应消息跳过发布,不做处理 53 | /// 54 | /// 55 | /// 默认返回PipeCode 56 | protected virtual string GeneratePushKey(TMsg msg) 57 | { 58 | return _msgKey; 59 | } 60 | 61 | /// 62 | /// 创建消息流 63 | /// 64 | /// 65 | /// 66 | protected abstract IDataPublisher CreatePublisher(DataPublisherOption option); 67 | 68 | #endregion 69 | 70 | #region 管道业务处理 71 | 72 | internal override async Task> InterProcessing(TMsg context) 73 | { 74 | var msgKey = GeneratePushKey(context); 75 | if (string.IsNullOrEmpty(msgKey)) 76 | { 77 | return new TrafficSignal(Empty.Default, context); 78 | } 79 | return (await _pusher.Publish(msgKey, context)) 80 | ? new TrafficSignal( Empty.Default, context) 81 | : new TrafficSignal(SignalFlag.Red_Block, Empty.Default, context, $"{this.GetType().Name}发布消息失败!"); 82 | } 83 | 84 | #endregion 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /OSS.PipeLine/Pipeline/InterImpls/Watcher/PipeWatcherProxy.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道监视器代理 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | using System.Threading.Tasks; 16 | using System.Threading.Tasks.Dataflow; 17 | using OSS.DataFlow; 18 | using OSS.Pipeline.Interface; 19 | 20 | namespace OSS.Pipeline.InterImpls.Watcher 21 | { 22 | internal class PipeWatcherProxy 23 | { 24 | private readonly string _dataFlowKey; 25 | private readonly IPipeLineWatcher _watcher; 26 | private readonly IDataPublisher _publisher; 27 | 28 | private readonly ActionBlock _watchDataQueue; 29 | 30 | public PipeWatcherProxy(IPipeLineWatcher watcher, string dataFlowKey, DataFlowOption option) 31 | { 32 | if (!string.IsNullOrEmpty(dataFlowKey)) 33 | { 34 | _dataFlowKey = dataFlowKey; 35 | _publisher = DataFlowFactory.RegisterFlow(dataFlowKey, WatchCallBack, option); 36 | } 37 | else 38 | { 39 | _watchDataQueue = new ActionBlock(WatchCallBack, 40 | new ExecutionDataflowBlockOptions() 41 | { 42 | MaxDegreeOfParallelism = 4 43 | }); 44 | } 45 | 46 | _watcher = watcher; 47 | } 48 | 49 | async Task WatchCallBack(WatchDataItem data) 50 | { 51 | try 52 | { 53 | // await 保证如果出现异常能在当前线程拦截 54 | // 避免造成触发队列 Complete 55 | switch (data.ActionType) 56 | { 57 | case WatchActionType.PreCall: 58 | await _watcher.PreCall(data.PipeCode, data.PipeType, data.Para).ConfigureAwait(false); 59 | break; 60 | case WatchActionType.Executed: 61 | await _watcher.Executed(data.PipeCode, data.PipeType, data.Para, data.Result) 62 | .ConfigureAwait(false); 63 | break; 64 | case WatchActionType.Blocked: 65 | await _watcher.Blocked(data.PipeCode, data.PipeType, data.Para, data.Result) 66 | .ConfigureAwait(false); 67 | break; 68 | } 69 | } 70 | catch 71 | { 72 | } 73 | 74 | return true; 75 | } 76 | 77 | 78 | public Task Watch(WatchDataItem data) 79 | { 80 | if (_publisher != null) 81 | { 82 | return _publisher.Publish(_dataFlowKey, data); 83 | } 84 | 85 | _watchDataQueue.Post(data); 86 | return Task.CompletedTask; 87 | } 88 | 89 | } 90 | 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Mos/TrafficSignal.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 通行信号 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | namespace OSS.Pipeline 16 | { 17 | /// 18 | public class TrafficSignal : TrafficSignal 19 | { 20 | /// 21 | /// 输出对象( 下节管道的输入 ) 22 | /// 23 | public TOut output { get; } 24 | 25 | /// 26 | public TrafficSignal(TRes res, TOut output) : base(res) 27 | { 28 | this.output = output; 29 | } 30 | 31 | /// 32 | public TrafficSignal(SignalFlag signalFlag, TRes res, string trafficMsg = null) : this(signalFlag, res,default, trafficMsg) 33 | { 34 | } 35 | 36 | /// 37 | public TrafficSignal(SignalFlag signalFlag, TRes res,TOut output, string trafficMsg = null) : base(signalFlag,res, trafficMsg) 38 | { 39 | this.output = output; 40 | } 41 | } 42 | 43 | /// 44 | /// 流动信号 45 | /// 46 | public class TrafficSignal: TrafficSignal 47 | { 48 | /// 49 | /// 流动通行信号(绿色通行)- 附带结果 50 | /// 51 | /// 返回结果 52 | public TrafficSignal(TRes res) : this(SignalFlag.Green_Pass, res, string.Empty) 53 | { 54 | } 55 | 56 | /// 57 | /// 流动信号 58 | /// 59 | /// 60 | /// 61 | /// 62 | public TrafficSignal(SignalFlag signalFlag, TRes res, string trafficMsg = null):base(signalFlag, trafficMsg) 63 | { 64 | result = res; 65 | } 66 | 67 | /// 68 | ///结果 69 | /// 70 | public TRes result { get; } 71 | } 72 | 73 | /// 74 | /// 流动信号 75 | /// 76 | public class TrafficSignal 77 | { 78 | /// 79 | /// 默认绿灯信号 80 | /// 81 | public static TrafficSignal GreenSignal { get; } = 82 | new TrafficSignal(SignalFlag.Green_Pass, string.Empty); 83 | 84 | /// 85 | /// 流动信号 86 | /// 87 | /// 88 | /// 89 | public TrafficSignal(SignalFlag signalFlag, string trafficMsg) 90 | { 91 | signal = signalFlag; 92 | msg = trafficMsg; 93 | } 94 | 95 | /// 96 | /// 信号 97 | /// 98 | public SignalFlag signal { get; } 99 | 100 | /// 101 | /// 消息 102 | /// 103 | public string msg { get; } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /OSS.PipeLine/Msg/BaseMsgFlow.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 消息流体基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using System.Threading.Tasks; 16 | using OSS.DataFlow; 17 | using OSS.Pipeline.Base; 18 | 19 | namespace OSS.Pipeline 20 | { 21 | /// 22 | /// 消息流基类 23 | /// 24 | /// 25 | public abstract class BaseMsgFlow : BaseThreeWayPipe,IDataSubscriber 26 | { 27 | // 内部异步处理入口 28 | private readonly IDataPublisher _pusher; 29 | private readonly string _msgKey; 30 | 31 | /// 32 | /// 异步缓冲连接器 33 | /// 34 | /// 作为缓冲DataFlow 对应的Key 默认对应的flow是异步线程池 35 | /// 36 | protected BaseMsgFlow(string msgKey,string pipeCode = null) : this(msgKey, null, pipeCode) 37 | { 38 | } 39 | 40 | 41 | /// 42 | /// 异步缓冲连接器 43 | /// 44 | /// 45 | /// 缓冲DataFlow 对应的Key 默认对应的flow是异步线程池 46 | /// 47 | protected BaseMsgFlow(string msgKey, DataFlowOption option, string pipeCode = null) : base(pipeCode, PipeType.MsgFlow) 48 | { 49 | if (string.IsNullOrEmpty(msgKey)) 50 | { 51 | throw new ArgumentNullException(nameof(msgKey), "消息类型 msgKey 不能为空!"); 52 | } 53 | 54 | _msgKey = msgKey; 55 | _pusher = CreateFlow(msgKey, this, option); 56 | } 57 | 58 | /// 59 | /// 创建消息流 60 | /// 61 | /// 62 | /// 63 | /// 64 | /// 65 | protected abstract IDataPublisher CreateFlow(string msgKey, IDataSubscriber subscriber, DataFlowOption option); 66 | 67 | #region 流体内部业务处理 68 | 69 | /// 70 | internal override async Task InterPreCall(TMsg context) 71 | { 72 | var pushRes = await _pusher.Publish(_msgKey, context); 73 | return pushRes 74 | ? TrafficSignal.GreenSignal 75 | : new TrafficSignal(SignalFlag.Red_Block, $"({this.GetType().Name})推送消息失败!"); 76 | } 77 | 78 | /// 79 | internal override Task> InterProcessing(TMsg context) 80 | { 81 | return Task.FromResult(new TrafficSignal(SignalFlag.Green_Pass, Empty.Default, context)); 82 | } 83 | 84 | #endregion 85 | 86 | /// 87 | /// 订阅唤起操作 88 | /// 89 | /// 90 | /// 91 | public async Task Subscribe(TMsg data) 92 | { 93 | return (await InterProcess(data)).signal==SignalFlag.Green_Pass; 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /OSS.PipeLine/Activity/BaseEffectActivity.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 外部动作活动 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.Pipeline.Base; 15 | using System.Threading.Tasks; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 主动触发执行活动组件基类 21 | /// 不接收上下文,自身返回处理结果,且结果作为上下文传递给下一个节点 22 | /// 23 | /// 24 | public abstract class BaseEffectActivity : BaseThreeWayPipe //, IEffectActivity 25 | { 26 | /// 27 | /// 外部Action活动基类 28 | /// 29 | protected BaseEffectActivity( string pipeCode = null) : base(pipeCode,PipeType.EffectActivity) 30 | { 31 | } 32 | 33 | #region 流体业务-启动 34 | 35 | /// 36 | /// 启动 37 | /// 38 | /// 39 | public Task Execute() 40 | { 41 | return Execute(Empty.Default); 42 | } 43 | 44 | #endregion 45 | 46 | #region 业务扩展方法 47 | 48 | /// 49 | /// 具体执行扩展方法 50 | /// 51 | /// 52 | /// -(活动是否处理成功,业务结果) 53 | /// traffic_signal: 54 | /// traffic_signal: 55 | /// Green_Pass - 流体自动流入后续管道 56 | /// Yellow_Wait - 管道流动暂停等待(仅当前处理业务),既不向后流动,也不触发Block。 57 | /// Red_Block - 触发Block,业务流不再向后续管道传递。 58 | /// 59 | protected abstract Task> Executing(); 60 | 61 | #endregion 62 | 63 | #region 流体内部业务处理 64 | 65 | /// 66 | internal override async Task> InterProcessing(Empty context) 67 | { 68 | var trafficRes = await Executing(); 69 | return new TrafficSignal(trafficRes.signal, trafficRes.result, trafficRes.result,trafficRes.msg); 70 | } 71 | 72 | #endregion 73 | } 74 | 75 | /// 76 | /// 主动触发执行活动组件基类 77 | /// 接收上下文,自身返回处理结果,且结果作为上下文传递给下一个节点 78 | /// 79 | /// 80 | /// 81 | public abstract class BaseEffectActivity : BaseThreeWayPipe//, IEffectActivity 82 | { 83 | /// 84 | /// 外部Action活动基类 85 | /// 86 | protected BaseEffectActivity(string pipeCode = null) : base(pipeCode,PipeType.EffectActivity) 87 | { 88 | } 89 | 90 | /// 91 | /// 具体执行扩展方法 92 | /// 93 | /// 当前活动上下文(会继续传递给下一个节点) 94 | /// 95 | protected abstract Task> Executing(TIn para); 96 | 97 | 98 | 99 | #region 流体内部业务处理 100 | 101 | /// 102 | internal override async Task> InterProcessing(TIn req) 103 | { 104 | var trafficRes = await Executing(req); 105 | return new TrafficSignal(trafficRes.signal ,trafficRes.result,trafficRes.result,trafficRes.msg); 106 | } 107 | 108 | #endregion 109 | } 110 | 111 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Base/BasePipePart.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道部分组成基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System.Threading.Tasks; 15 | using OSS.Pipeline.Interface; 16 | using OSS.Pipeline.InterImpls.Watcher; 17 | 18 | namespace OSS.Pipeline.Base 19 | { 20 | /// 21 | /// 管道组成基类 22 | /// 23 | public abstract class BasePipePart : IPipeInitiator 24 | { 25 | /// 26 | /// 构造函数 27 | /// 28 | /// 29 | /// 30 | protected BasePipePart(string pipeCode, PipeType pipeType) 31 | { 32 | PipeType = pipeType; 33 | PipeCode = string.IsNullOrEmpty(pipeCode) ? GetType().Name : pipeCode; 34 | } 35 | 36 | /// 37 | /// 管道类型 38 | /// 39 | public PipeType PipeType { get; internal set; } 40 | 41 | /// 42 | /// 管道编码 43 | /// 默认等于 this.GetType().Name 44 | /// 45 | public string PipeCode { get; set; } 46 | 47 | /// 48 | /// 流容器 49 | /// 50 | internal IPipeLine LineContainer { get; set; } 51 | 52 | 53 | 54 | #region 管道监控 55 | 56 | internal PipeWatcherProxy WatchProxy { get; set; } 57 | 58 | internal Task Watch(string pipeCode, PipeType pipeType, WatchActionType actionType, object para, 59 | WatchResult res) 60 | { 61 | if (WatchProxy != null) 62 | { 63 | return WatchProxy.Watch(new WatchDataItem() 64 | { 65 | PipeCode = pipeCode, 66 | PipeType = pipeType, 67 | ActionType = actionType, 68 | 69 | Para = para, 70 | Result = res 71 | }); 72 | } 73 | 74 | return Task.CompletedTask; 75 | } 76 | 77 | internal Task Watch(string pipeCode, PipeType pipeType, WatchActionType actionType, object para) 78 | { 79 | return Watch(pipeCode, pipeType, actionType, para, default); 80 | } 81 | 82 | #endregion 83 | 84 | #region 内部初始化(容器和路由) 85 | 86 | /// 87 | /// 内部处理流容器初始化赋值 88 | /// 89 | /// 90 | internal abstract void InterInitialContainer(IPipeLine containerFlow); 91 | 92 | void IPipeInitiator.InterInitialContainer(IPipeLine containerFlow) 93 | { 94 | InterInitialContainer(containerFlow); 95 | } 96 | 97 | /// 98 | /// 内部处理流的路由信息 99 | /// 100 | /// 101 | internal abstract void InterFormatLink(string prePipeCode, bool isSelf = false); 102 | 103 | void IPipeInitiator.InterFormatLink(string prePipeCode, bool isSelf) 104 | { 105 | InterFormatLink(prePipeCode, isSelf); 106 | } 107 | 108 | #endregion 109 | } 110 | 111 | /// 112 | /// 管道进口基类 113 | /// 114 | /// 115 | public abstract class BaseInPipePart : BasePipePart , IPipeInPart 116 | { 117 | /// 118 | protected BaseInPipePart(string pipeCode, PipeType pipeType) : base(pipeCode, pipeType) 119 | { 120 | } 121 | 122 | #region 管道的业务处理 123 | 124 | /// 125 | /// 内部管道 -- 唤起 126 | /// 127 | internal abstract Task InterPreCall(TIn context); 128 | 129 | async Task IPipeInPart.InterWatchPreCall(TIn context) 130 | { 131 | await Watch(PipeCode, PipeType, WatchActionType.PreCall, context).ConfigureAwait(false); 132 | return await InterPreCall(context); 133 | } 134 | #endregion 135 | 136 | 137 | } 138 | 139 | 140 | 141 | 142 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Activity/Default/SimpleActivity.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 活动基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using System.Threading.Tasks; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 主动触发执行活动组件基类(不接收上下文) 21 | /// 22 | public class SimpleActivity: BaseActivity 23 | { 24 | private readonly Func> _exeFunc; 25 | 26 | /// 27 | public SimpleActivity( Func> exeFunc, string pipeCode = null) :base(pipeCode) 28 | { 29 | _exeFunc = exeFunc ?? throw new ArgumentNullException(nameof(exeFunc), "执行方法不能为空!"); 30 | } 31 | 32 | /// 33 | /// 具体执行扩展方法 34 | /// 35 | /// 36 | /// 处理结果 37 | /// False - 触发Block,业务流不再向后续管道传递。 38 | /// True - 流体自动流入后续管道 39 | /// 40 | protected override Task Executing() 41 | { 42 | return _exeFunc(); 43 | } 44 | 45 | } 46 | 47 | /// 48 | /// 主动触发执行活动组件基类 49 | /// 接收输入上下文,且此上下文继续传递下一个节点 50 | /// 51 | /// 输入输出上下文 52 | public class SimpleActivity : BaseActivity 53 | { 54 | private readonly Func> _exeFunc; 55 | 56 | 57 | /// 58 | public SimpleActivity( Func> exeFunc, string pipeCode = null) :base(pipeCode) 59 | { 60 | if (!string.IsNullOrEmpty(pipeCode)) 61 | { 62 | PipeCode = pipeCode; 63 | } 64 | _exeFunc = exeFunc ?? throw new ArgumentNullException(nameof(exeFunc), "执行方法不能为空!"); 65 | } 66 | 67 | /// 68 | protected override Task Executing(TIn contextData) 69 | { 70 | return _exeFunc(contextData); 71 | } 72 | } 73 | 74 | 75 | /// 76 | /// 主动触发执行活动组件基类 77 | /// 接收输入上下文,且此上下文继续传递下一个节点 78 | /// 79 | /// 输入输出类型 80 | /// 81 | public class SimpleActivity : BaseActivity 82 | { 83 | private readonly Func>> _exeFunc; 84 | 85 | /// 86 | public SimpleActivity(Func>> exeFunc, string pipeCode = null) :base(pipeCode) 87 | { 88 | if (!string.IsNullOrEmpty(pipeCode)) 89 | { 90 | PipeCode = pipeCode; 91 | } 92 | _exeFunc = exeFunc ?? throw new ArgumentNullException(nameof(exeFunc), "执行方法不能为空!"); 93 | } 94 | 95 | /// 96 | protected override Task> Executing(TIn para) 97 | { 98 | return _exeFunc(para); 99 | } 100 | } 101 | 102 | 103 | /// 104 | /// 主动触发执行活动组件基类 105 | /// 接收输入上下文,且此上下文继续传递下一个节点 106 | /// 107 | /// 输入类型 108 | /// 返回结果类型 109 | /// 输出类型 110 | public class SimpleActivity : BaseActivity 111 | { 112 | private readonly Func>> _exeFunc; 113 | 114 | /// 115 | public SimpleActivity(Func>> exeFunc, string pipeCode=null) : base(pipeCode) 116 | { 117 | if (!string.IsNullOrEmpty(pipeCode)) 118 | { 119 | PipeCode = pipeCode; 120 | } 121 | _exeFunc = exeFunc ?? throw new ArgumentNullException(nameof(exeFunc), "执行方法不能为空!"); 122 | } 123 | 124 | /// 125 | protected override Task> Executing(TIn para) 126 | { 127 | return _exeFunc(para); 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Base/BasePipe.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2016 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 流体基础管道部分 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System.Threading.Tasks; 15 | using OSS.DataFlow.Event; 16 | using OSS.PipeLine.Base.Base.InterImpls; 17 | using OSS.Pipeline.Interface; 18 | 19 | namespace OSS.Pipeline.Base.Base 20 | { 21 | /// 22 | /// 管道基类 (双入双出类型) 23 | /// 24 | /// 25 | /// 26 | /// 27 | /// 28 | public abstract class BasePipe 29 | : BaseInPipePart, IPipeRetry 30 | { 31 | /// 32 | /// 构造函数 33 | /// 34 | /// 35 | /// 36 | protected BasePipe(string pipeCode, PipeType pipeType) : base(pipeCode, pipeType) 37 | { 38 | } 39 | 40 | #region 业务重试实现 41 | 42 | private PipeRetryEventProcessor> _retryProcessor; 43 | void IPipeRetry.SetErrorRetry(FlowEventOption option) 44 | { 45 | _retryProcessor = new PipeRetryEventProcessor>( 46 | InterRetryProcessHandling, option); 47 | } 48 | private Task> InterRetryProcessHandling(RetryEventMsg eMsg) 49 | { 50 | return InterProcessingAndDistribute(eMsg.para); 51 | } 52 | 53 | #endregion 54 | 55 | #region 管道内部业务流转处理 56 | 57 | /// 58 | /// 内部管道 -- (1)执行 59 | /// 60 | /// 61 | /// 62 | internal Task> InterProcess(TPara req) 63 | { 64 | if (_retryProcessor!=null) 65 | { 66 | return _retryProcessor.Process(new RetryEventMsg(req)); 67 | } 68 | return InterProcessingAndDistribute(req); 69 | } 70 | 71 | /// 72 | /// 内部管道 -- (2)执行 - 调用监控执行 + 分发 73 | /// 74 | /// 75 | /// 76 | internal abstract Task> InterProcessingAndDistribute(TPara req); 77 | 78 | /// 79 | /// 内部管道 -- (3)执行 - 监控执行 80 | /// 81 | /// 82 | /// 83 | internal async Task> InterWatchProcessing(TPara req) 84 | { 85 | var trafficRes = await InterProcessing(req); 86 | await Watch(PipeCode, PipeType, WatchActionType.Executed, req, trafficRes.ToWatchResult()).ConfigureAwait(false); 87 | 88 | return trafficRes; 89 | } 90 | 91 | /// 92 | /// 具体执行实现 93 | /// 94 | internal abstract Task> InterProcessing(TPara req); 95 | 96 | /// 97 | /// 管道堵塞 -- (4) 执行 - 阻塞实现 98 | /// 99 | /// 100 | /// 101 | /// 102 | internal async Task InterWatchBlock(TPara req, TrafficSignal tRes) 103 | { 104 | await Watch(PipeCode, PipeType, WatchActionType.Blocked, req, tRes.ToWatchResult()) 105 | .ConfigureAwait(false); 106 | await Block(req, tRes); 107 | } 108 | 109 | #endregion 110 | 111 | #region 管道外部扩展 112 | 113 | /// 114 | /// 管道堵塞(堵塞可能来自本管道,也可能是通知下游管道返回堵塞 115 | /// 116 | /// 117 | /// 118 | /// 119 | protected virtual Task Block(TPara req, TrafficSignal tRes) 120 | { 121 | return Task.CompletedTask; 122 | } 123 | 124 | #endregion 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /OSS.PipeLine/Activity/BasePassiveActivity.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 外部动作活动 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | using OSS.Pipeline.Base; 16 | using System.Threading.Tasks; 17 | 18 | namespace OSS.Pipeline 19 | { 20 | /// 21 | /// 被动触发执行活动组件基类 22 | /// 传入TPassivePara类型参数,且此参数作为后续上下文传递给下一个节点,自身返回处理结果但无影响 23 | /// 24 | /// 25 | public abstract class BasePassiveActivity : BaseThreeWayPassivePipe 26 | { 27 | /// 28 | /// 外部Action活动基类 29 | /// 30 | protected BasePassiveActivity(string pipeCode = null) : base(pipeCode, PipeType.PassiveActivity) 31 | { 32 | } 33 | 34 | /// 35 | /// 具体执行扩展方法 36 | /// 37 | /// 当前活动上下文信息 38 | /// 39 | /// -(活动是否处理成功,业务结果) 40 | /// traffic_signal: 41 | /// traffic_signal: 42 | /// Green_Pass - 流体自动流入后续管道 43 | /// Yellow_Wait - 管道流动暂停等待(仅当前处理业务),既不向后流动,也不触发Block。 44 | /// Red_Block - 触发Block,业务流不再向后续管道传递。 45 | /// 46 | protected abstract Task Executing(TPara para); 47 | 48 | /// 49 | /// 对外直接执行 50 | /// 51 | /// 52 | /// 53 | public new Task Execute(TPara para) 54 | { 55 | return base.Execute(para); 56 | } 57 | 58 | 59 | /// 60 | internal override async Task> InterProcessing(TPara req) 61 | { 62 | var tSignal = await Executing(req); 63 | return new TrafficSignal(tSignal.signal,Empty.Default, req, tSignal.msg); 64 | } 65 | } 66 | 67 | /// 68 | /// 被动触发执行活动组件基类 69 | /// 传入TPassivePara类型参数,且此参数作为后续上下文传递给下一个节点,自身返回处理结果但无影响 70 | /// 71 | /// 72 | /// 73 | public abstract class BasePassiveActivity : BaseThreeWayPassivePipe 74 | { 75 | /// 76 | /// 外部Action活动基类 77 | /// 78 | protected BasePassiveActivity(string pipeCode = null) : base(pipeCode,PipeType.PassiveActivity) 79 | { 80 | } 81 | 82 | /// 83 | /// 具体执行扩展方法 84 | /// 85 | /// 当前活动上下文信息 86 | /// 87 | /// -(活动是否处理成功,业务结果) 88 | /// traffic_signal: 89 | /// traffic_signal: 90 | /// Green_Pass - 流体自动流入后续管道 91 | /// Yellow_Wait - 管道流动暂停等待(仅当前处理业务),既不向后流动,也不触发Block。 92 | /// Red_Block - 触发Block,业务流不再向后续管道传递。 93 | /// 94 | protected abstract Task> Executing(TPara para); 95 | 96 | /// 97 | internal override async Task> InterProcessing(TPara req) 98 | { 99 | var tSignal = await Executing(req); 100 | return new TrafficSignal(tSignal.signal, tSignal.result, req, tSignal.msg); 101 | } 102 | } 103 | 104 | 105 | /// 106 | /// 被动触发执行活动组件基类 107 | /// 传入TPassivePara类型参数,且此参数作为后续上下文传递给下一个节点,自身返回处理结果但无影响 108 | /// 109 | /// 110 | /// 111 | public abstract class BasePassiveActivity : BaseThreeWayPassivePipe 112 | { 113 | /// 114 | /// 外部Action活动基类 115 | /// 116 | protected BasePassiveActivity(string pipeCode = null) : base(pipeCode, PipeType.PassiveActivity) 117 | { 118 | } 119 | 120 | /// 121 | /// 具体执行扩展方法 122 | /// 123 | /// 当前活动上下文信息 124 | /// 125 | /// -(活动是否处理成功,业务结果) 126 | /// traffic_signal: 127 | /// traffic_signal: 128 | /// Green_Pass - 流体自动流入后续管道 129 | /// Yellow_Wait - 管道流动暂停等待(仅当前处理业务),既不向后流动,也不触发Block。 130 | /// Red_Block - 触发Block,业务流不再向后续管道传递。 131 | /// 132 | protected abstract Task> Executing(TPara para); 133 | 134 | /// 135 | internal override async Task> InterProcessing(TPara req) 136 | { 137 | var tSignal = await Executing(req); 138 | return new TrafficSignal(tSignal.signal, tSignal.result, tSignal.output, tSignal.msg); 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /OSS.PipeLine/Pipeline/Extension/PipeLineExtension.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2016 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - Pipeline 扩展 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | 15 | using OSS.Pipeline.Base; 16 | using OSS.Pipeline.Interface; 17 | 18 | namespace OSS.Pipeline 19 | { 20 | /// 21 | /// EventFlow 创建工厂 22 | /// 23 | public static partial class PipelineExtension 24 | { 25 | ///// 26 | ///// 追加下一个节点 27 | ///// 28 | ///// 29 | ///// 30 | ///// 31 | ///// 32 | ///// 33 | ///// 34 | ///// 35 | ///// 36 | //public static IPipelineConnector Then(this IPipelineConnector pipe, 37 | // BaseFourWayPipe nextPipe) 38 | //{ 39 | // return pipe.Set(nextPipe); 40 | //} 41 | 42 | ///// 43 | ///// 追加下一个节点 44 | ///// 45 | ///// 46 | ///// 47 | ///// 48 | ///// 49 | ///// 50 | ///// 51 | ///// 52 | ///// 53 | //public static IPipelineConnector Then(this IPipelineConnector pipe, 54 | // BaseFourWayPipe nextPipe) 55 | //{ 56 | // return pipe.Set(nextPipe); 57 | //} 58 | 59 | #region 生成Pipeline 60 | 61 | /// 62 | /// 根据首位两个管道建立流体 63 | /// 64 | /// 65 | /// 66 | /// 67 | /// 68 | /// 69 | public static Pipeline AsPipeline(this IPipeInPart startPipe, 70 | BaseFourWayPipe endPipe, PipeLineOption option = null, string flowPipeCode=null) 71 | { 72 | return new Pipeline( startPipe, endPipe, option, flowPipeCode); 73 | } 74 | 75 | /// 76 | /// 根据首位两个管道建立流体 77 | /// 78 | /// 79 | /// 80 | /// 81 | /// 82 | /// 83 | public static EmptyEntryPipeline AsPipeline(this IPipeInPart startPipe, 84 | BaseFourWayPipe endPipe, 85 | PipeLineOption option = null, string flowPipeCode = null) 86 | { 87 | return new EmptyEntryPipeline( startPipe, endPipe, option, flowPipeCode); 88 | } 89 | 90 | ///// 91 | ///// 根据当前连接信息创建Pipeline 92 | ///// 93 | ///// 94 | ///// 95 | ///// 96 | ///// 97 | ///// 98 | ///// 99 | //public static Pipeline AsPipeline(this IPipelineConnector pipe, 100 | // string pipeCode, PipeLineOption option = null) 101 | //{ 102 | // var newPipe = new Pipeline(pipeCode, pipe.StartPipe, pipe.EndAppender, option); 103 | // pipe.StartPipe = null; 104 | // pipe.EndAppender = null; 105 | // return newPipe; 106 | //} 107 | 108 | ///// 109 | ///// 根据当前连接信息创建Pipeline 110 | ///// 111 | ///// 112 | ///// 113 | ///// 114 | ///// 115 | ///// 116 | //public static EmptyEntryPipeline AsPipeline< TOut>(this IPipelineConnector pipe, string pipeCode, PipeLineOption option = null) 117 | //{ 118 | // var newPipe = new EmptyEntryPipeline(pipeCode, pipe.StartPipe, pipe.EndAppender, option); 119 | // pipe.StartPipe = null; 120 | // pipe.EndAppender = null; 121 | // return newPipe; 122 | //} 123 | 124 | #endregion 125 | 126 | } 127 | } -------------------------------------------------------------------------------- /OSS.PipeLine.Tests/Order/Activities.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using OSS.Tools.Log; 3 | using System.Threading.Tasks; 4 | using OSS.Pipeline.Interface; 5 | 6 | namespace OSS.Pipeline.Tests.Order 7 | { 8 | public class OrderPayReq 9 | { 10 | public long OrderId { get; set; } 11 | public decimal PayMoney { get; set; } 12 | } 13 | 14 | /// 15 | /// 订单支付管道 16 | /// OrderPayReq - 业务输入参数, bool - 业务输出执行成功失败, long - 逻辑输出订单Id 17 | /// 18 | internal class OrderPay : BaseActivity 19 | { 20 | protected override async Task> Executing(OrderPayReq para) 21 | { 22 | LogHelper.Info($"支付订单({para.OrderId})金额:{para.PayMoney} 成功"); 23 | 24 | await Task.Delay(10); 25 | 26 | // 返回执行成功,并告诉下级管道 订单Id 27 | return new TrafficSignal(true, para.OrderId); 28 | } 29 | } 30 | 31 | /// 32 | /// 支付Hook 33 | /// long-是上级管道传入的订单Id, bool - 业务输出执行成功失败, List 需要发送的消息列表 34 | /// 35 | internal class PayHook : BaseActivity> 36 | { 37 | protected override async Task>> Executing(long para) 38 | { 39 | LogHelper.Info($"执行订单({para})Hook"); 40 | await Task.Delay(10); 41 | 42 | var msgs = new List 43 | { 44 | new NotifyMsg() {target = "管理员", content = $"订单({para})支付成功,请注意发货"}, 45 | new NotifyMsg() {target = "用户", content = $"订单({para})支付成功,已经入服务流程", is_sms = true} 46 | }; 47 | 48 | return new TrafficSignal>(true, msgs); 49 | } 50 | } 51 | 52 | 53 | public class NotifyMsg 54 | { 55 | public string target { get; set; } 56 | public string content { get; set; } 57 | public bool is_sms { get; set; } // 假设不是短信就是邮件 58 | } 59 | 60 | /// 61 | /// 发送短信服务 62 | /// NotifyMsg - 上级管道传递的业务输入参数, bool - 当前业务执行成功失败 63 | /// 64 | internal class NotifySMS : BaseActivity 65 | { 66 | protected override async Task> Executing(NotifyMsg para) 67 | { 68 | LogHelper.Info($"发送用户短信消息 :{para.target}:{para.content}"); 69 | 70 | await Task.Delay(10); 71 | 72 | return new TrafficSignal(true); 73 | } 74 | } 75 | 76 | /// 77 | /// 发送邮件服务 78 | /// NotifyMsg - 上级管道传递的业务输入参数, bool - 当前业务执行成功失败 79 | /// 80 | internal class NotifyEmail : BaseActivity 81 | { 82 | protected override async Task> Executing(NotifyMsg para) 83 | { 84 | LogHelper.Info($"发送管理员邮件消息 :{para.target}:{para.content}"); 85 | 86 | await Task.Delay(10); 87 | 88 | return new TrafficSignal(true); 89 | } 90 | } 91 | 92 | internal class OrderPayPipeline 93 | { 94 | private static readonly OrderPay _pay = new OrderPay(); 95 | private static readonly PayHook _payHook = new PayHook(); 96 | 97 | private static readonly SimpleBranchGateway _notifyGateway = new SimpleBranchGateway(); 98 | 99 | private static readonly NotifySMS _notifySms = new NotifySMS(); 100 | private static readonly NotifyEmail _notifyEmail = new NotifyEmail(); 101 | 102 | private static readonly EmptyActivity _end = new EmptyActivity(); 103 | 104 | static OrderPayPipeline() 105 | { 106 | _pay 107 | .AppendMsgFlow("order_pay_event") // 添加默认实现的异步消息队列中 108 | .Append(_payHook) // 消息队列数据流向hook管道 109 | .AppendMsgEnumerator() // Hook处理后有多条消息,添加消息枚举器 110 | .Append(_notifyGateway); // 枚举后的单个消息体流入发送分支网关 111 | 112 | _notifyGateway.Append(m => m.is_sms, _notifySms).Append(_end); 113 | _notifyGateway.Append(m => !m.is_sms, _notifyEmail).Append(_end); 114 | 115 | 116 | // 添加日志,通过初始化流水线,给流水线添加Watcher,会自动给下边的所有Pipe添加Watcher 117 | _pay.AsPipeline(_end, new PipeLineOption() { Watcher = new FlowWatcher() },"OrderPayPipeline"); 118 | } 119 | 120 | // 作为对外暴露接口 121 | public Task PayOrder(OrderPayReq req) 122 | { 123 | return _pay.Execute(req); 124 | } 125 | } 126 | 127 | public class FlowWatcher : IPipeLineWatcher 128 | { 129 | public Task PreCall(string pipeCode, PipeType pipeType, object input) 130 | { 131 | LogHelper.Info($"进入 {pipeCode} 管道", "PipePreCall", "PipelineWatcher"); 132 | return Task.CompletedTask; 133 | } 134 | 135 | public Task Executed(string pipeCode, PipeType pipeType, object input, WatchResult watchResult) 136 | { 137 | LogHelper.Info($"管道 {pipeCode} 执行结束,结束信号:{watchResult.signal}", "PipeExecuted", "PipelineWatcher"); 138 | return Task.CompletedTask; 139 | } 140 | 141 | public Task Blocked(string pipeCode, PipeType pipeType, object input, WatchResult watchResult) 142 | { 143 | LogHelper.Info($"管道 {pipeCode} 阻塞", "PipeBlocked", "PipelineWatcher"); 144 | return Task.CompletedTask; 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /OSS.PipeLine/Gateway/Extension/BranchExtension.Msg.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道扩展-消息类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.DataFlow; 15 | using System; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 管道扩展类 21 | /// 22 | public static partial class BranchExtension 23 | { 24 | /// 25 | /// 追加默认消息发布者管道 26 | /// 27 | /// 28 | /// 29 | /// 分支条件判断 30 | /// 消息pipeDataKey,默认消息实现对应的flow是异步线程池 31 | /// 32 | /// 33 | /// 34 | public static SimpleMsgPublisher AppendMsgPublisher( 35 | this IBranchGateway pipe, Func branchCondition, string msgDataKey, 36 | DataPublisherOption option = null, string pipeCode = null) 37 | { 38 | var nextPipe = new SimpleMsgPublisher(msgDataKey, option, pipeCode); 39 | 40 | pipe.SetCondition(nextPipe, branchCondition); 41 | pipe.InterAppend(nextPipe); 42 | 43 | return nextPipe; 44 | } 45 | 46 | /// 47 | /// 追加默认消息发布者管道 48 | /// 49 | /// 50 | /// 51 | /// 分支条件判断 52 | /// 消息key生成器,为空则使用pipeCode作为发布消息key 53 | /// 54 | /// 55 | /// 56 | public static SimpleMsgPublisher AppendMsgPublisher( 57 | this IBranchGateway pipe, Func branchCondition, Func pushKeyGenerator, 58 | DataPublisherOption option = null, string pipeCode = null) 59 | { 60 | var nextPipe = new SimpleMsgPublisher(pushKeyGenerator, option, pipeCode); 61 | 62 | pipe.SetCondition(nextPipe, branchCondition); 63 | pipe.InterAppend(nextPipe); 64 | 65 | return nextPipe; 66 | } 67 | 68 | /// 69 | /// 追加默认消息订阅者管道 70 | /// 71 | /// 72 | /// 73 | /// 分支条件判断 74 | /// 消息pipeDataKey,默认对应的flow是异步线程池 75 | /// 76 | /// 77 | public static BaseMsgSubscriber AppendMsgSubscriber( 78 | this IBranchGateway pipe, Func branchCondition, string msgDataKey, 79 | string pipeCode = null) 80 | { 81 | var nextPipe = new SimpleMsgSubscriber(msgDataKey, pipeCode); 82 | 83 | pipe.SetCondition(nextPipe, branchCondition); 84 | pipe.InterAppend(nextPipe); 85 | 86 | return nextPipe; 87 | } 88 | 89 | /// 90 | /// 追加默认消息流管道 91 | /// 92 | /// 93 | /// 94 | /// 分支条件判断 95 | /// 消息pipeDataKey,默认对应的flow是异步线程池 96 | /// 97 | /// 98 | /// 99 | public static BaseMsgFlow AppendMsgFlow( 100 | this IBranchGateway pipe, Func branchCondition, string msgDataKey, 101 | DataFlowOption option = null, string pipeCode = null) 102 | { 103 | var nextPipe = new SimpleMsgFlow(msgDataKey, option, pipeCode); 104 | 105 | pipe.SetCondition(nextPipe, branchCondition); 106 | pipe.InterAppend(nextPipe); 107 | 108 | return nextPipe; 109 | } 110 | 111 | /// 112 | /// 追加默认消息转换管道 113 | /// 114 | /// 115 | /// 116 | /// 117 | /// 分支条件判断 118 | /// 119 | /// 120 | /// 121 | public static BaseMsgConverter AppendMsgConverter( 122 | this IBranchGateway pipe, Func branchCondition, Func convertFunc, 123 | string pipeCode = null) 124 | { 125 | var nextPipe = new SimpleMsgConvertor(convertFunc, pipeCode); 126 | 127 | pipe.SetCondition(nextPipe, branchCondition); 128 | pipe.InterAppend(nextPipe); 129 | 130 | return nextPipe; 131 | } 132 | 133 | } 134 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Extension/PipeExtension.Activity.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道扩展 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using System.Threading.Tasks; 16 | using OSS.Pipeline.Interface; 17 | 18 | namespace OSS.Pipeline 19 | { 20 | /// 21 | /// 管道扩展类 22 | /// 23 | public static partial class PipeExtension 24 | { 25 | /// 26 | /// 追加活动管道 27 | /// 28 | /// 29 | /// 30 | /// 执行委托 31 | /// 32 | /// 33 | public static SimpleActivity AppendActivity(this IPipeAppender pipe, 34 | Func> exeFunc, string pipeCode = null) 35 | { 36 | var nextPipe = new SimpleActivity(exeFunc, pipeCode); 37 | pipe.InterAppend(nextPipe); 38 | return nextPipe; 39 | } 40 | 41 | 42 | /// 43 | /// 追加活动管道 44 | /// 45 | /// 46 | /// 47 | /// 执行委托 48 | /// 49 | /// 50 | public static SimpleActivity AppendActivity(this IPipeAppender pipe, 51 | Func> exeFunc, 52 | string pipeCode = null) 53 | { 54 | var nextPipe = new SimpleActivity(exeFunc, pipeCode); 55 | pipe.InterAppend(nextPipe); 56 | return nextPipe; 57 | } 58 | 59 | 60 | /// 61 | /// 追加活动管道 62 | /// 63 | /// 64 | /// 65 | /// 66 | /// 执行委托 67 | /// 68 | /// 69 | public static SimpleActivity AppendActivity(this IPipeAppender pipe, 70 | Func>> exeFunc, string pipeCode = null) 71 | { 72 | var nextPipe = new SimpleActivity(exeFunc, pipeCode); 73 | pipe.InterAppend(nextPipe); 74 | return nextPipe; 75 | } 76 | 77 | 78 | /// 79 | /// 追加活动管道 80 | /// 81 | /// 82 | /// 83 | /// 84 | /// 85 | /// 执行委托 86 | /// 87 | /// 88 | public static SimpleActivity AppendActivity(this IPipeAppender pipe, 89 | Func>> exeFunc, string pipeCode = null) 90 | { 91 | var nextPipe = new SimpleActivity(exeFunc, pipeCode); 92 | pipe.InterAppend(nextPipe); 93 | return nextPipe; 94 | } 95 | 96 | 97 | 98 | 99 | 100 | /// 101 | /// 追加活动管道 102 | /// 103 | /// 104 | /// 105 | /// 106 | /// 执行委托 107 | /// 108 | /// 109 | public static SimpleEffectActivity AppendEffectActivity( 110 | this IPipeAppender pipe, 111 | Func>> exeFunc, string pipeCode = null) 112 | { 113 | var nextPipe = new SimpleEffectActivity(exeFunc, pipeCode); 114 | pipe.InterAppend(nextPipe); 115 | return nextPipe; 116 | } 117 | 118 | 119 | 120 | /// 121 | /// 追加活动管道 122 | /// 123 | /// 124 | /// 125 | /// 126 | /// 执行委托 127 | /// 128 | /// 129 | public static SimpleEffectActivity AppendEffectActivity( 130 | this IPipeAppender pipe, 131 | Func>> exeFunc, string pipeCode = null) 132 | { 133 | var nextPipe = new SimpleEffectActivity(exeFunc, pipeCode); 134 | pipe.InterAppend(nextPipe); 135 | return nextPipe; 136 | } 137 | } 138 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | #Connection Development File 26 | appsettings.Development.json 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # DNX 47 | project.lock.json 48 | artifacts/ 49 | 50 | *_i.c 51 | *_p.c 52 | *_i.h 53 | *.ilk 54 | *.meta 55 | *.obj 56 | *.pch 57 | *.pdb 58 | *.pgc 59 | *.pgd 60 | *.rsp 61 | *.sbr 62 | *.tlb 63 | *.tli 64 | *.tlh 65 | *.tmp 66 | *.tmp_proj 67 | *.log 68 | *.vspscc 69 | *.vssscc 70 | .builds 71 | *.pidb 72 | *.svclog 73 | *.scc 74 | 75 | # Chutzpah Test files 76 | _Chutzpah* 77 | 78 | # Visual C++ cache files 79 | ipch/ 80 | *.aps 81 | *.ncb 82 | *.opendb 83 | *.opensdf 84 | *.sdf 85 | *.cachefile 86 | *.VC.db 87 | *.VC.VC.opendb 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | *.sap 94 | 95 | # TFS 2012 Local Workspace 96 | $tf/ 97 | 98 | # Guidance Automation Toolkit 99 | *.gpState 100 | 101 | # ReSharper is a .NET coding add-in 102 | _ReSharper*/ 103 | *.[Rr]e[Ss]harper 104 | *.DotSettings.user 105 | 106 | # JustCode is a .NET coding add-in 107 | .JustCode 108 | 109 | # TeamCity is a build add-in 110 | _TeamCity* 111 | 112 | # DotCover is a Code Coverage Tool 113 | *.dotCover 114 | 115 | # NCrunch 116 | _NCrunch_* 117 | .*crunch*.local.xml 118 | nCrunchTemp_* 119 | 120 | # MightyMoose 121 | *.mm.* 122 | AutoTest.Net/ 123 | 124 | # Web workbench (sass) 125 | .sass-cache/ 126 | 127 | # Installshield output folder 128 | [Ee]xpress/ 129 | 130 | # DocProject is a documentation generator add-in 131 | DocProject/buildhelp/ 132 | DocProject/Help/*.HxT 133 | DocProject/Help/*.HxC 134 | DocProject/Help/*.hhc 135 | DocProject/Help/*.hhk 136 | DocProject/Help/*.hhp 137 | DocProject/Help/Html2 138 | DocProject/Help/html 139 | 140 | # Click-Once directory 141 | publish/ 142 | 143 | # Publish Web Output 144 | *.[Pp]ublish.xml 145 | *.azurePubxml 146 | # TODO: Comment the next line if you want to checkin your web deploy settings 147 | # but database connection strings (with potential passwords) will be unencrypted 148 | *.pubxml 149 | *.publishproj 150 | 151 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 152 | # checkin your Azure Web App publish settings, but sensitive information contained 153 | # in these scripts will be unencrypted 154 | PublishScripts/ 155 | 156 | # NuGet Packages 157 | *.nupkg 158 | # The packages folder can be ignored because of Package Restore 159 | **/packages/* 160 | # except build/, which is used as an MSBuild target. 161 | !**/packages/build/ 162 | # Uncomment if necessary however generally it will be regenerated when needed 163 | #!**/packages/repositories.config 164 | # NuGet v3's project.json files produces more ignoreable files 165 | *.nuget.props 166 | *.nuget.targets 167 | 168 | # Microsoft Azure Build Output 169 | csx/ 170 | *.build.csdef 171 | 172 | # Microsoft Azure Emulator 173 | ecf/ 174 | rcf/ 175 | 176 | # Windows Store app package directories and files 177 | AppPackages/ 178 | BundleArtifacts/ 179 | Package.StoreAssociation.xml 180 | _pkginfo.txt 181 | 182 | # Visual Studio cache files 183 | # files ending in .cache can be ignored 184 | *.[Cc]ache 185 | # but keep track of directories ending in .cache 186 | !*.[Cc]ache/ 187 | 188 | # Others 189 | ClientBin/ 190 | ~$* 191 | *~ 192 | *.dbmdl 193 | *.dbproj.schemaview 194 | *.pfx 195 | *.publishsettings 196 | node_modules/ 197 | orleans.codegen.cs 198 | 199 | # Since there are multiple workflows, uncomment next line to ignore bower_components 200 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 201 | #bower_components/ 202 | 203 | # RIA/Silverlight projects 204 | Generated_Code/ 205 | 206 | # Backup & report files from converting an old project file 207 | # to a newer Visual Studio version. Backup files are not needed, 208 | # because we have git ;-) 209 | _UpgradeReport_Files/ 210 | Backup*/ 211 | UpgradeLog*.XML 212 | UpgradeLog*.htm 213 | 214 | # SQL Server files 215 | *.mdf 216 | *.ldf 217 | 218 | # Business Intelligence projects 219 | *.rdl.data 220 | *.bim.layout 221 | *.bim_*.settings 222 | 223 | # Microsoft Fakes 224 | FakesAssemblies/ 225 | 226 | # GhostDoc plugin setting file 227 | *.GhostDoc.xml 228 | 229 | # Node.js Tools for Visual Studio 230 | .ntvs_analysis.dat 231 | 232 | # Visual Studio 6 build log 233 | *.plg 234 | 235 | # Visual Studio 6 workspace options file 236 | *.opt 237 | 238 | # Visual Studio LightSwitch build output 239 | **/*.HTMLClient/GeneratedArtifacts 240 | **/*.DesktopClient/GeneratedArtifacts 241 | **/*.DesktopClient/ModelManifest.xml 242 | **/*.Server/GeneratedArtifacts 243 | **/*.Server/ModelManifest.xml 244 | _Pvt_Extensions 245 | 246 | # Paket dependency manager 247 | .paket/paket.exe 248 | paket-files/ 249 | 250 | # FAKE - F# Make 251 | .fake/ 252 | 253 | # JetBrains Rider 254 | .idea/ 255 | *.sln.iml 256 | 257 | appsettings.Development.json 258 | /Visual Studio 2019 259 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/Extension/PipeExtension.Msg.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道扩展-消息类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using System.Collections.Generic; 16 | using OSS.DataFlow; 17 | using OSS.Pipeline.Interface; 18 | 19 | namespace OSS.Pipeline 20 | { 21 | /// 22 | /// 管道扩展类 23 | /// 24 | public static partial class PipeExtension 25 | { 26 | /// 27 | /// 追加默认消息发布者管道 28 | /// 29 | /// 30 | /// 31 | /// 消息pipeDataKey,默认消息实现对应的flow是异步线程池 32 | /// 33 | /// 34 | public static SimpleMsgPublisher AppendMsgPublisher(this IPipeAppender pipe, string msgDataKey, 35 | DataPublisherOption option = null, string pipeCode = null) 36 | { 37 | var nextPipe = new SimpleMsgPublisher(msgDataKey, option, pipeCode); 38 | pipe.InterAppend(nextPipe); 39 | 40 | return nextPipe; 41 | } 42 | 43 | /// 44 | /// 追加默认消息发布者管道 45 | /// 46 | /// 47 | /// 48 | /// 消息key生成器,为空则使用pipeCode作为发布消息key 49 | /// 50 | /// 51 | public static SimpleMsgPublisher AppendMsgPublisher(this IPipeAppender pipe, Func pushKeyGenerator, 52 | DataPublisherOption option = null, string pipeCode = null) 53 | { 54 | var nextPipe = new SimpleMsgPublisher(pushKeyGenerator, option, pipeCode); 55 | pipe.InterAppend(nextPipe); 56 | return nextPipe; 57 | } 58 | 59 | /// 60 | /// 追加默认消息订阅者管道 61 | /// 62 | /// 63 | /// 64 | /// 消息pipeDataKey,默认对应的flow是异步线程池 65 | /// 66 | /// 67 | public static BaseMsgSubscriber AppendMsgSubscriber(this IPipeAppender pipe, 68 | string msgDataKey, string pipeCode = null) 69 | { 70 | var nextPipe = new SimpleMsgSubscriber(msgDataKey, pipeCode); 71 | 72 | pipe.InterAppend(nextPipe); 73 | return nextPipe; 74 | } 75 | 76 | /// 77 | /// 追加默认消息流管道 78 | /// 79 | /// 80 | /// 81 | /// 消息pipeDataKey,默认对应的flow是异步线程池 82 | /// 83 | /// 84 | /// 85 | public static BaseMsgFlow AppendMsgFlow(this IPipeAppender pipe, string msgDataKey, 86 | DataFlowOption option = null, string pipeCode = null) 87 | { 88 | var nextPipe = new SimpleMsgFlow(msgDataKey, option, pipeCode); 89 | 90 | pipe.InterAppend(nextPipe); 91 | return nextPipe; 92 | } 93 | 94 | /// 95 | /// 追加默认消息转换管道 96 | /// 97 | /// 98 | /// 99 | /// 100 | /// 101 | /// 102 | /// 103 | public static BaseMsgConverter AppendMsgConverter( 104 | this IPipeAppender pipe, Func convertFunc, string pipeCode = null) 105 | { 106 | var nextPipe = new SimpleMsgConvertor(convertFunc, pipeCode); 107 | 108 | pipe.InterAppend(nextPipe); 109 | return nextPipe; 110 | } 111 | 112 | /// 113 | /// 追加消息迭代器 114 | /// 115 | /// 消息具体类型 116 | /// 117 | /// 118 | /// 消息过滤器 119 | /// 120 | public static MsgEnumerator AppendMsgEnumerator( 121 | this IPipeAppender> pipe, 122 | Func, IEnumerable> 123 | msgFilter = null, string pipeCode = null) 124 | { 125 | var nextPipe = new MsgEnumerator(msgFilter, pipeCode); 126 | pipe.InterAppend(nextPipe); 127 | return nextPipe; 128 | } 129 | } 130 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Activity/BaseActivity.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 活动基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.Pipeline.Base; 15 | using System.Threading.Tasks; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 主动触发执行活动组件基类(不接收上下文) 21 | /// 22 | public abstract class BaseActivity : BaseThreeWayPipe //, IActivity 23 | { 24 | /// 25 | /// 外部Action活动基类 26 | /// 27 | protected BaseActivity(string pipeCode=null) : base(pipeCode, PipeType.Activity) 28 | { 29 | } 30 | 31 | #region 部具体执行扩展 32 | 33 | /// 34 | /// 具体执行扩展方法 35 | /// 36 | /// 37 | protected abstract Task Executing(); 38 | 39 | #endregion 40 | 41 | 42 | #region 流体业务-启动 43 | 44 | /// 45 | /// 启动方法 46 | /// 47 | /// 48 | public Task Execute() 49 | { 50 | return Execute(Empty.Default); 51 | } 52 | 53 | #endregion 54 | 55 | #region 流体内部业务处理 56 | 57 | /// 58 | internal override async Task> InterProcessing(Empty context) 59 | { 60 | var trafficRes = await Executing(); 61 | return new TrafficSignal(trafficRes.signal, context, context); 62 | } 63 | 64 | #endregion 65 | } 66 | 67 | /// 68 | /// 主动触发执行活动组件基类 69 | /// 接收输入上下文,且此上下文继续传递下一个节点 70 | /// 71 | /// 输入输出上下文 72 | public abstract class BaseActivity : BaseThreeWayPipe //, IActivity 73 | { 74 | /// 75 | /// 外部Action活动基类 76 | /// 77 | protected BaseActivity(string pipeCode = null) : base(pipeCode,PipeType.Activity) 78 | { 79 | } 80 | 81 | /// 82 | /// 具体执行扩展方法 83 | /// 84 | /// 当前活动上下文(会继续传递给下一个节点) 85 | /// 86 | protected abstract Task Executing(TIn para); 87 | 88 | /// 89 | /// 启动入口 90 | /// 91 | /// 92 | /// 93 | public new Task Execute(TIn para) 94 | { 95 | return base.Execute(para); 96 | } 97 | 98 | #region 流体内部业务处理 99 | 100 | /// 101 | internal override async Task> InterProcessing(TIn req) 102 | { 103 | var trafficRes = await Executing(req); 104 | return new TrafficSignal(trafficRes.signal, Empty.Default, req); 105 | } 106 | 107 | #endregion 108 | } 109 | 110 | /// 111 | /// 主动触发执行活动组件基类 112 | /// 接收输入上下文,且此上下文继续传递下一个节点 113 | /// 114 | /// 输入输出上下文 115 | /// 116 | public abstract class BaseActivity : BaseThreeWayPipe 117 | { 118 | /// 119 | /// 外部Action活动基类 120 | /// 121 | protected BaseActivity(string pipeCode = null) : base(pipeCode,PipeType.Activity) 122 | { 123 | } 124 | 125 | /// 126 | /// 具体执行扩展方法 127 | /// 128 | /// 当前活动上下文(会继续传递给下一个节点) 129 | /// 130 | protected abstract Task> Executing(TIn para); 131 | 132 | 133 | #region 流体内部业务处理 134 | 135 | /// 136 | internal override async Task> InterProcessing(TIn req) 137 | { 138 | var trafficRes = await Executing(req); 139 | return new TrafficSignal(trafficRes.signal,trafficRes.result, req, trafficRes.msg); 140 | } 141 | 142 | #endregion 143 | } 144 | 145 | 146 | /// 147 | /// 主动触发执行活动组件基类 148 | /// 接收输入上下文,且此上下文继续传递下一个节点 149 | /// 150 | /// 输入输出上下文 151 | /// 152 | /// 153 | public abstract class BaseActivity : BaseThreeWayPipe 154 | { 155 | /// 156 | /// 外部Action活动基类 157 | /// 158 | protected BaseActivity(string pipeCode = null) : base(pipeCode, PipeType.Activity) 159 | { 160 | } 161 | 162 | /// 163 | /// 具体执行扩展方法 164 | /// 165 | /// 当前活动上下文(会继续传递给下一个节点) 166 | /// 167 | protected abstract Task> Executing(TIn para); 168 | 169 | 170 | #region 流体内部业务处理 171 | 172 | /// 173 | internal override async Task> InterProcessing(TIn req) 174 | { 175 | var trafficRes = await Executing(req); 176 | return new TrafficSignal(trafficRes.signal, trafficRes.result, trafficRes.output, trafficRes.msg); 177 | } 178 | 179 | #endregion 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /OSS.PipeLine/Base/BaseFourWayPipe.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2016 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 流体基础管道部分 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.Pipeline.Interface; 15 | using OSS.Pipeline.Base.Base; 16 | using System; 17 | using System.Threading.Tasks; 18 | using OSS.Pipeline.InterImpls; 19 | 20 | namespace OSS.Pipeline.Base 21 | { 22 | 23 | /// 24 | /// 管道基类 (双入双出类型) 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | public abstract class BaseFourWayPipe 31 | : BasePipe 32 | , IPipe 33 | { 34 | /// 35 | /// 构造函数 36 | /// 37 | /// 38 | /// 39 | protected BaseFourWayPipe(string pipeCode, PipeType pipeType) : base(pipeCode, pipeType) 40 | { 41 | } 42 | 43 | #region 管道内部业务流转处理 44 | 45 | /// 46 | internal override async Task> InterProcessingAndDistribute(TPara req) 47 | { 48 | var trafficRes = await InterWatchProcessing(req); 49 | 50 | switch (trafficRes.signal) 51 | { 52 | case SignalFlag.Green_Pass: 53 | { 54 | // 下一级执行 55 | await ToNextThrough(trafficRes.output); 56 | break; 57 | } 58 | case SignalFlag.Red_Block: 59 | await InterWatchBlock(req, trafficRes); 60 | break; 61 | } 62 | 63 | return trafficRes; 64 | } 65 | 66 | #endregion 67 | 68 | #region 管道连接处理 69 | 70 | internal IPipeInitiator NextPipe { get; set; } 71 | internal virtual Task ToNextThrough(TOut nextInContext) 72 | { 73 | if (NextPipe != null) 74 | { 75 | return _nextPipe != null 76 | ? _nextPipe.InterWatchPreCall(nextInContext) 77 | : _nextEmptyPipe.InterWatchPreCall(Empty.Default); 78 | } 79 | // 说明已经是最后一个管道 80 | return InterUtil.GreenTrafficSignalTask; 81 | } 82 | 83 | 84 | /// 85 | /// 链接流体内部尾部管道和流体外下一截管道 86 | /// 87 | /// 88 | internal virtual void InterAppend(IPipeInPart nextPipe) 89 | { 90 | if (NextPipe != null) 91 | { 92 | throw new ArgumentException($"当前节点{PipeCode}已经关联下游节点!"); 93 | } 94 | NextPipe = _nextPipe = nextPipe; 95 | } 96 | private IPipeInPart _nextPipe { get; set; } 97 | void IPipeAppender.InterAppend(IPipeInPart nextPipe) 98 | { 99 | InterAppend(nextPipe); 100 | } 101 | 102 | 103 | /// 104 | /// 链接流体内部尾部管道和流体外下一截管道 ( 接收空上下文 105 | /// 106 | /// 107 | internal virtual void InterAppend(IPipeInPart nextPipe) 108 | { 109 | if (NextPipe != null) 110 | { 111 | throw new ArgumentException("当前节点已经关联下游节点!"); 112 | } 113 | NextPipe = _nextEmptyPipe = nextPipe; 114 | } 115 | private IPipeInPart _nextEmptyPipe { get; set; } 116 | void IPipeAppender.InterAppend(IPipeInPart nextPipe) 117 | { 118 | InterAppend(nextPipe); 119 | } 120 | 121 | #endregion 122 | 123 | #region 管道初始化 124 | 125 | /// 126 | internal override void InterInitialContainer(IPipeLine flowContainer) 127 | { 128 | LineContainer = flowContainer; 129 | WatchProxy=flowContainer.GetWatchProxy(); 130 | 131 | if (this.Equals(flowContainer.EndPipe)) 132 | return; 133 | 134 | if (NextPipe == null) 135 | throw new ArgumentNullException(nameof(NextPipe), 136 | $"Flow({flowContainer.PipeCode})需要有明确的EndPipe,且所有的分支路径最终需到达此EndPipe"); 137 | 138 | NextPipe.InterInitialContainer(flowContainer); 139 | } 140 | 141 | #endregion 142 | 143 | #region 管道路由 144 | 145 | 146 | internal override void InterFormatLink(string prePipeCode, bool isSelf = false) 147 | { 148 | if (!string.IsNullOrEmpty(prePipeCode)) 149 | { 150 | var links = LineContainer.GetLinkDics(); 151 | var linkKey = string.Concat(prePipeCode, "_", PipeCode); 152 | 153 | if (links.ContainsKey(linkKey)) 154 | { 155 | return; 156 | } 157 | links.Add(linkKey,new PipeLink() 158 | { 159 | pre_pipe_code = prePipeCode, 160 | pipe_code = PipeCode 161 | }); 162 | } 163 | 164 | if (NextPipe == null || Equals(LineContainer.EndPipe)) 165 | return ; 166 | 167 | NextPipe.InterFormatLink(PipeCode,false); 168 | } 169 | 170 | 171 | #endregion 172 | 173 | } 174 | 175 | } 176 | -------------------------------------------------------------------------------- /OSS.PipeLine/Pipeline/Pipeline.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2016 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 流体基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-28 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using System.Collections.Generic; 16 | using System.Linq; 17 | using System.Threading.Tasks; 18 | using OSS.Pipeline.Base; 19 | using OSS.Pipeline.Interface; 20 | using OSS.Pipeline.InterImpls.Watcher; 21 | 22 | namespace OSS.Pipeline 23 | { 24 | /// 25 | /// 基础流体 26 | /// 27 | /// 28 | /// 29 | public class Pipeline : 30 | BaseFourWayPipe, IPipeLine 31 | { 32 | #region 首尾节点定义 33 | 34 | private readonly IPipeInPart _startPipe; 35 | private readonly IPipeAppender _endPipe; 36 | 37 | /// 38 | /// 开始管道 39 | /// 40 | public IPipeMeta StartPipe => _startPipe; 41 | 42 | /// 43 | /// 结束管道 44 | /// 45 | public IPipeMeta EndPipe => _endPipe; 46 | 47 | #endregion 48 | 49 | #region 构造函数 50 | 51 | /// 52 | /// 基础流体 53 | /// 54 | public Pipeline( IPipeInPart startPipe, 55 | IPipeAppender endPipeAppender, string pipeCode=null) : this(startPipe, endPipeAppender, null,pipeCode) 56 | { 57 | } 58 | 59 | /// 60 | /// 基础流体 61 | /// 62 | public Pipeline(IPipeInPart startPipe, 63 | IPipeAppender endPipeAppender, PipeLineOption option, string pipeCode = null) : base(pipeCode, PipeType.Pipeline) 64 | { 65 | if (startPipe == null || endPipeAppender == null ) 66 | { 67 | throw new ArgumentNullException("未发现流体的起始截止管道!"); 68 | } 69 | 70 | _startPipe = startPipe; 71 | _endPipe = endPipeAppender; 72 | 73 | InitialPipes(); 74 | 75 | if (option?.Watcher != null) 76 | { 77 | WatchProxy = new PipeWatcherProxy(option.Watcher, option.WatcherDataFlowKey, 78 | option.WatcherDataFlowOption); 79 | } 80 | 81 | startPipe.InterInitialContainer(this); 82 | } 83 | 84 | /// 85 | /// 初始化节点关系 86 | /// (构造函数中会调用 87 | /// 88 | protected virtual void InitialPipes() 89 | { 90 | 91 | } 92 | 93 | #endregion 94 | 95 | #region 管道的业务处理 96 | 97 | 98 | #region 管道业务启动 99 | 100 | /// 101 | public Task Execute(TIn context) 102 | { 103 | return ((IPipeInPart)this).InterWatchPreCall(context); 104 | } 105 | 106 | #endregion 107 | 108 | /// 109 | internal override Task InterPreCall(TIn context) 110 | { 111 | return _startPipe.InterWatchPreCall(context); 112 | } 113 | 114 | /// 115 | internal override Task> InterProcessing(TIn context) 116 | { 117 | throw new Exception("不应该执行到此方法!"); 118 | } 119 | 120 | #endregion 121 | 122 | #region 管道连接重写处理 123 | 124 | /// 125 | /// 链接流体内部尾部管道和流体外下一截管道 126 | /// 127 | /// 128 | internal override void InterAppend(IPipeInPart nextPipe) 129 | { 130 | base.InterAppend(nextPipe); // 保证路由初始化,本身next节点不会被执行 131 | _endPipe.InterAppend(nextPipe); // 保证业务执行 132 | } 133 | 134 | internal override void InterAppend(IPipeInPart nextPipe) 135 | { 136 | base.InterAppend(nextPipe); // 保证路由初始化,本身next节点不会被执行 137 | _endPipe.InterAppend(nextPipe); // 保证业务执行 138 | } 139 | 140 | #endregion 141 | 142 | #region Pipeline 路由 管理 143 | 144 | private Dictionary _linkDics; 145 | Dictionary IPipeLine.GetLinkDics() 146 | { 147 | if (_linkDics==null) 148 | { 149 | _linkDics = new Dictionary(); 150 | } 151 | return _linkDics; 152 | } 153 | 154 | /// 155 | /// 生成路径 156 | /// 157 | /// 158 | public List ToRoute() 159 | { 160 | if (_linkDics==null) 161 | { 162 | InterFormatLink(string.Empty,true); 163 | } 164 | return _linkDics.Select(x=>x.Value).ToList(); 165 | } 166 | 167 | internal override void InterFormatLink(string prePipeCode, bool isSelf = false) 168 | { 169 | if (isSelf) 170 | { 171 | _startPipe.InterFormatLink(string.Empty,false); 172 | } 173 | else 174 | { 175 | base.InterFormatLink(prePipeCode); 176 | } 177 | } 178 | 179 | #endregion 180 | 181 | #region 管道初始化 182 | 183 | /// 184 | internal override void InterInitialContainer(IPipeLine flowContainer) 185 | { 186 | base.InterInitialContainer(flowContainer); 187 | _startPipe.InterInitialContainer(this); 188 | } 189 | 190 | #endregion 191 | 192 | #region 管道 内部监控代理器 193 | 194 | /// 195 | PipeWatcherProxy IPipeLine.GetWatchProxy() => WatchProxy; 196 | 197 | #endregion 198 | 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /OSS.PipeLine/Gateway/Extension/BranchExtension.Activity.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 管道扩展 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-22 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using System; 15 | using System.Threading.Tasks; 16 | 17 | namespace OSS.Pipeline 18 | { 19 | /// 20 | /// 管道扩展类 21 | /// 22 | public static partial class BranchExtension 23 | { 24 | 25 | /// 26 | /// 追加活动管道 27 | /// 28 | /// 29 | /// 30 | /// 分支条件判断 31 | /// 执行委托 32 | /// 33 | /// 34 | public static SimpleActivity AppendActivity( 35 | this IBranchGateway pipe, Func branchCondition, 36 | Func> exeFunc, string pipeCode = null) 37 | { 38 | var nextPipe = new SimpleActivity(exeFunc, pipeCode); 39 | 40 | pipe.SetCondition(nextPipe, branchCondition); 41 | pipe.InterAppend(nextPipe); 42 | 43 | return nextPipe; 44 | } 45 | 46 | 47 | /// 48 | /// 追加活动管道 49 | /// 50 | /// 51 | /// 52 | /// 分支条件判断 53 | /// 执行委托 54 | /// 55 | /// 56 | public static SimpleActivity AppendActivity( 57 | this IBranchGateway pipe, Func branchCondition, 58 | Func> exeFunc, 59 | string pipeCode = null) 60 | { 61 | var nextPipe = new SimpleActivity(exeFunc, pipeCode); 62 | 63 | pipe.SetCondition(nextPipe, branchCondition); 64 | pipe.InterAppend(nextPipe); 65 | return nextPipe; 66 | } 67 | 68 | 69 | /// 70 | /// 追加活动管道 71 | /// 72 | /// 73 | /// 74 | /// 75 | /// 分支条件判断 76 | /// 执行委托 77 | /// 78 | /// 79 | public static SimpleActivity AppendActivity( 80 | this IBranchGateway pipe, Func branchCondition, 81 | Func>> exeFunc, string pipeCode = null) 82 | { 83 | var nextPipe = new SimpleActivity(exeFunc, pipeCode); 84 | 85 | pipe.SetCondition(nextPipe, branchCondition); 86 | pipe.InterAppend(nextPipe); 87 | return nextPipe; 88 | } 89 | 90 | 91 | /// 92 | /// 追加活动管道 93 | /// 94 | /// 95 | /// 96 | /// 97 | /// 98 | /// 分支条件判断 99 | /// 执行委托 100 | /// 101 | /// 102 | public static SimpleActivity AppendActivity( 103 | this IBranchGateway pipe, Func branchCondition, 104 | Func>> exeFunc, string pipeCode = null) 105 | { 106 | var nextPipe = new SimpleActivity(exeFunc, pipeCode); 107 | 108 | pipe.SetCondition(nextPipe, branchCondition); 109 | pipe.InterAppend(nextPipe); 110 | return nextPipe; 111 | } 112 | 113 | 114 | /// 115 | /// 追加活动管道 116 | /// 117 | /// 118 | /// 119 | /// 120 | /// 分支条件判断 121 | /// 执行委托 122 | /// 123 | /// 124 | public static SimpleEffectActivity AppendEffectActivity( 125 | this IBranchGateway pipe, Func branchCondition, 126 | Func>> exeFunc, string pipeCode = null) 127 | { 128 | var nextPipe = new SimpleEffectActivity(exeFunc, pipeCode); 129 | 130 | pipe.SetCondition(nextPipe, branchCondition); 131 | pipe.InterAppend(nextPipe); 132 | 133 | return nextPipe; 134 | } 135 | 136 | 137 | /// 138 | /// 追加活动管道 139 | /// 140 | /// 141 | /// 142 | /// 143 | ///分支条件判断 144 | /// 执行委托 145 | /// 146 | /// 147 | public static SimpleEffectActivity AppendEffectActivity( 148 | this IBranchGateway pipe, Func branchCondition, 149 | Func>> exeFunc, string pipeCode = null) 150 | { 151 | var nextPipe = new SimpleEffectActivity(exeFunc, pipeCode); 152 | 153 | pipe.SetCondition(nextPipe, branchCondition); 154 | pipe.InterAppend(nextPipe); 155 | return nextPipe; 156 | } 157 | } 158 | } -------------------------------------------------------------------------------- /OSS.PipeLine/Gateway/BaseBranchGateway.cs: -------------------------------------------------------------------------------- 1 | #region Copyright (C) 2020 Kevin (OSS开源系列) 公众号:OSSCore 2 | 3 | /*************************************************************************** 4 | *   文件功能描述:OSS.EventFlow - 流体的分支网关基类 5 | * 6 | *   创建人: Kevin 7 | * 创建人Email:1985088337@qq.com 8 | * 创建时间: 2020-11-27 9 | * 10 | *****************************************************************************/ 11 | 12 | #endregion 13 | 14 | using OSS.Pipeline.Interface; 15 | using System; 16 | using System.Collections.Generic; 17 | using System.Data; 18 | using System.Linq; 19 | using System.Threading.Tasks; 20 | using OSS.Pipeline.Base; 21 | using OSS.Pipeline.Gateway.InterImpls; 22 | using OSS.Pipeline.InterImpls; 23 | 24 | namespace OSS.Pipeline 25 | { 26 | 27 | public interface IBranchGateway : IPipeAppender 28 | { 29 | internal void SetCondition(IPipeMeta pipe, Func condition); 30 | } 31 | 32 | /// 33 | /// 流体的分支网关基类 34 | /// 35 | /// 36 | public abstract class BaseBranchGateway : BaseThreeWayPipe, IBranchGateway 37 | { 38 | /// 39 | /// 流体的分支网关基类 40 | /// 所有分支都失败会触发block 41 | /// 42 | protected BaseBranchGateway(string pipeCode = null) : base(pipeCode, PipeType.BranchGateway) 43 | { 44 | } 45 | 46 | /// 47 | /// 所有分支管道 48 | /// 49 | protected IReadOnlyList BranchPipes => _branchItems.Select(bw => bw.Pipe).ToList(); 50 | 51 | /// 52 | /// 条件分支过滤处理 53 | /// 54 | /// 当前传入分支网关的上下文 55 | /// 等待过滤的分支 56 | /// True-执行当前分支, False-不执行当前分支 57 | protected virtual bool FilterBranchCondition(TContext branchContext, IPipeMeta branch) 58 | { 59 | return true; 60 | } 61 | 62 | 63 | #region 条件追加处理 64 | 65 | internal Dictionary> interConditions; 66 | 67 | void IBranchGateway.SetCondition(IPipeMeta pipe, Func condition) 68 | { 69 | if (condition == null ) 70 | throw new ArgumentNullException(nameof(condition), $"指向 {pipe.PipeCode} 的条件判断不能为空!"); 71 | 72 | interConditions ??= new Dictionary>(); 73 | 74 | if (interConditions .ContainsKey(pipe)) 75 | throw new DuplicateNameException(string.Concat(PipeCode, "分支网关 存在不同条件但相同指向的分支!")); 76 | 77 | interConditions[pipe] = condition; 78 | } 79 | 80 | #endregion 81 | 82 | 83 | #region 管道内部业务处理 84 | 85 | /// 86 | internal override async Task> InterProcessing(TContext context) 87 | { 88 | var nextPipes = FilterUseableBranches(context); 89 | if (nextPipes == null || !nextPipes.Any()) 90 | { 91 | return new TrafficSignal(SignalFlag.Yellow_Wait, context, 92 | context, "未能找到可执行的后续节点!"); 93 | } 94 | 95 | var parallelPipes = nextPipes.Select(p => p.InterPreCall(context)); 96 | 97 | var res = (await Task.WhenAll(parallelPipes)).All(r => r.signal == SignalFlag.Green_Pass) 98 | ? new TrafficSignal(SignalFlag.Green_Pass, context, context) 99 | : new TrafficSignal(SignalFlag.Yellow_Wait, context, context, "分支子节点并未全部成功!"); 100 | 101 | return res; 102 | } 103 | 104 | private IList FilterUseableBranches(TContext context) 105 | { 106 | if (_branchItems == null) 107 | return null; 108 | 109 | var nextPipes =new List(); 110 | 111 | foreach (var branchItem in _branchItems) 112 | { 113 | if (!FilterBranchCondition(context, branchItem.Pipe)) 114 | continue; 115 | 116 | if (interConditions!=null 117 | && interConditions.ContainsKey(branchItem.Pipe) 118 | && !interConditions[branchItem.Pipe].Invoke(context)) 119 | continue; 120 | 121 | nextPipes.Add(branchItem); 122 | } 123 | return nextPipes; 124 | } 125 | 126 | #endregion 127 | 128 | 129 | #region 管道连接 130 | 131 | // 分支网关的下级处理由自己控制 132 | internal override Task ToNextThrough(TContext nextInContext) 133 | { 134 | return InterUtil.GreenTrafficSignalTask; 135 | } 136 | 137 | internal override void InterAppend(IPipeInPart nextPipe) 138 | { 139 | Add(nextPipe); 140 | } 141 | 142 | internal override void InterAppend(IPipeInPart nextPipe) 143 | { 144 | Add(nextPipe); 145 | } 146 | 147 | private List _branchItems; 148 | 149 | internal void Add(IPipeInPart pipe) 150 | { 151 | if (pipe == null) 152 | { 153 | throw new ArgumentNullException(nameof(pipe), " 不能为空!"); 154 | } 155 | 156 | _branchItems ??= new List(); 157 | _branchItems.Add(new BranchNodeWrap(pipe)); 158 | } 159 | 160 | 161 | internal void Add(IPipeInPart pipe) 162 | { 163 | if (pipe == null) 164 | { 165 | throw new ArgumentNullException(nameof(pipe), " 不能为空!"); 166 | } 167 | 168 | _branchItems ??= new List(); 169 | _branchItems.Add(new BranchNodeWrap(pipe)); 170 | } 171 | 172 | #endregion 173 | 174 | #region 内部初始化 175 | 176 | internal override void InterInitialContainer(IPipeLine flowContainer) 177 | { 178 | LineContainer = flowContainer; 179 | WatchProxy = flowContainer.GetWatchProxy(); 180 | 181 | if (_branchItems == null || !_branchItems.Any()) 182 | { 183 | throw new ArgumentNullException($"分支网关({PipeCode})并没有可用下游管道"); 184 | } 185 | 186 | _branchItems.ForEach(b => b.InterInitialContainer(flowContainer)); 187 | } 188 | 189 | #endregion 190 | 191 | #region 内部路由处理 192 | 193 | internal override void InterFormatLink(string prePipeCode, bool isSelf = false) 194 | { 195 | base.InterFormatLink(prePipeCode, isSelf); 196 | _branchItems.ForEach(b => b.InterFormatLink(prePipeCode, isSelf)); 197 | } 198 | 199 | #endregion 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## OSS事件流(OSS.Pipeline) 2 | 3 | 以 BPM 流程管理为思路,设计的轻量级业务生命周期流程引擎基础框架, 4 | 将业务领域对象的流程管控和事件功能抽象剥离,切断事件功能方法内的链式调用,提权至流程引擎统一协调管控, 5 | 事件功能作为独立处理单元嵌入业务流程之中,由流程引擎处理事件的触发与消息传递,达成事件处理单元的有效隔离。 6 | 由此流程的衔接变成可独立编程的部分,同时向上层提供业务动作的独立扩展,保证业务单元的绝对独立和可复用性, 7 | 目的是可以像搭积木一样来完成不同功能代码的集成,系统向真正的低代码平台过渡。 8 | 9 | 如果将整个业务流当做一个流程管道,结合流程流转的特性,此引擎抽象了三个核心管道组件: 10 | 11 | 12 | ### 1. 事件活动组件 13 | 这个组件主要是处理任务的具体内容,如发送短信,执行下单,扣减库存等实际业务操作 14 | 15 | ### 2. 网关组件 16 | 这个组件主要负责业务流程方向性的逻辑规则处理,如分支,合并流程 17 | 18 | ### 3. 消息流组件 19 | 这个组件主要负责其他组件之间的消息传递与转化。 20 | 21 | ## 一. 事件活动组件 22 | 这个组件用来实现具体的业务功能逻辑,如关联自动执行活动,中断触发(像用户触发,或消息队列)等活动。 23 | 根据 主动/被动 两种情形,同时根据当前活动的业务返回值和下游节点上下文的关系,提供了四类(共七个)基础活动类: 24 | 25 | ### 1. BaseActivity,BaseActivity,BaseActivity,BaseActivity - 主动触发活动组件 26 | 常见如自动审核功能,或者支付成功后自动触发邮件发送等,最简单也是最基本的一种跟随动作处理。 27 | 继承此基类,重写Executing方法实现活动内容,同一个流体下实现自动关联执行,执行完毕后自动触发下级节点(传入当前上下文)。 28 | 29 | ```csharp 30 | /// 31 | /// 具体执行扩展方法 32 | /// 33 | /// 34 | /// 处理结果 35 | /// traffic_signal: 36 | /// Green_Pass - 流体自动流入后续管道 37 | /// Yellow_Wait - 管道流动暂停等待(仅当前处理业务),既不向后流动,也不触发Block。 38 | /// Red_Block - 触发Block,业务流不再向后续管道传递。 39 | /// 40 | protected abstract Task Executing(); 41 | ``` 42 | ### 2. BaseEffectActivity ,BaseEffectActivity - 主动触发(受影响上下文)活动组件 43 | 44 | 默认情况下,当前活动处理结束后当前活动的上下文默认传递给下一个管道节点,实际中可能会出现下游业务活动仅仅需要获取上游的业务活动的执行结果即可,场景如: 下单成功 ==》 发送确认短信,发送短信需要知道订单id。 45 | 这种下一个节点受上一个节点结果影响情况,使用此(含Effect)基类,其Executing重写方法的结果将作为下一个活动的上下文信息,如下: 46 | 47 | ```csharp 48 | /// 49 | /// 具体执行扩展方法 50 | /// 51 | /// 52 | /// -(活动是否处理成功,业务结果) 53 | /// traffic_signal: 54 | /// traffic_signal: 55 | /// Green_Pass - 流体自动流入后续管道 56 | /// Yellow_Wait - 管道流动暂停等待(仅当前处理业务),既不向后流动,也不触发Block。 57 | /// Red_Block - 触发Block,业务流不再向后续管道传递。 58 | /// 59 | protected abstract Task> Executing(); 60 | ``` 61 | 62 | 63 | ### 3. BasePassiveActivity, BasePassiveActivity - 被动触发执行活动组件(如需用户参与) 64 | 65 | 当业务流流入当前组件,业务流动停止,被动等待调用节点的 Execute 方法,外部调用后流程继续向后流动执行(Execute传入的参数作为后续的上下文)。 66 | 继承此基类(含Passive),重写Executing方法实现具体业务逻辑内容。 67 | 68 | ```csharp 69 | /// 70 | /// 具体执行扩展方法 71 | /// 72 | /// 当前活动上下文信息 73 | /// 74 | /// -(活动是否处理成功,业务结果) 75 | /// traffic_signal: 76 | /// traffic_signal: 77 | /// Green_Pass - 流体自动流入后续管道 78 | /// Yellow_Wait - 管道流动暂停等待(仅当前处理业务),既不向后流动,也不触发Block。 79 | /// Red_Block - 触发Block,业务流不再向后续管道传递。 80 | /// 81 | protected abstract Task> Executing(TPara para); 82 | ``` 83 | 84 | ### 4. BasePassiveEffectActivity - 被动触发(受影响上下文)执行活动组件 85 | 86 | 同主动触发活动组件一样,当前活动处理业务结果作为下游节点的上下文。 87 | 继承此基类(含Passive和Effect),重写Executing方法实现具体业务逻辑内容。 88 | 89 | ```csharp 90 | /// 91 | /// 具体执行扩展方法 92 | /// 93 | /// 当前活动上下文信息 94 | /// 95 | /// -(活动是否处理成功,业务结果) 96 | /// traffic_signal: 97 | /// traffic_signal: 98 | /// Green_Pass - 流体自动流入后续管道 99 | /// Yellow_Wait - 管道流动暂停等待(仅当前处理业务),既不向后流动,也不触发Block。 100 | /// Red_Block - 触发Block,业务流不再向后续管道传递。 101 | /// 102 | protected abstract Task> Executing(TPara para); 103 | ``` 104 | 以上四类基类都包含 Execute 方法,可供流体从任意节点直接启动向下执行。 105 | 106 | 107 | ## 二. 网关组件 108 | 此组件主要负责逻辑的规则处理,业务的走向逻辑无非分与合,这里给出两个基类: 109 | 110 | ### 1. BaseAggregateGateway - 聚合业务分支流程活动组件 111 | 将多条业务分支聚合到当前网关组件下,由当前网关统一控制是否将业务流程向后传递,只需要继承此基类重写IfMatchCondition 方法即可 112 | 113 | ### 2. BaseBranchGateway - 分支网关组件 114 | 此组件将业务分流处理,定义流体时通过AddBranchPipe添加多个分支,至于如何分流,只需要继承此基类重写FilterNextPipes方法即可,你也可以在此之上实现BPMN中的几种网关类型(并行,排他,和包含)。 115 | 116 | ## 三. 消息流组件 117 | 此组件主要负责消息的传递和转化处理,根据是否需要转化,或者异步定义四个基类如下: 118 | 119 | ### 1. BaseMsgConverter - 转化连接组件 120 | 业务流经过此组件,直接执行Convert方法(自定义实现),转化成对应的下个组件执行参数,自动进入下个组件。 121 | 122 | ### 2. BaseMsgFlow - 异步缓冲数据连接组件(提供默认实现:MsgFlow) 123 | 此前组件的流动以【发布/订阅】的方式异步执行,触发来源可以方便的修改为队列或数据库,详情【OSS.DataFlow】[https://github.com/KevinWG/OSS.DataFlow]) 124 | 125 | ### 3. BaseMsgPublisher 消息发布者组件 - (提供默认实现:MsgPublisher) 126 | 此前组件提供数据的【发布】方式,触发来源可以方便的修改为队列或数据库,详情【OSS.DataFlow】[https://github.com/KevinWG/OSS.DataFlow]) 127 | 128 | ### 4. BaseMsgSubscriber - 消息订阅者组件(提供默认实现:MsgSubscriber) 129 | 此前组件提供数据的【订阅】方式,触发来源可以方便的修改为队列或数据库,详情【OSS.DataFlow】[https://github.com/KevinWG/OSS.DataFlow]) 130 | 131 | 132 | 以上是三个核心的组件部分,以上三个组件任意组合可以组成PipeLine(流体),PipeLine本身又可以作为一个组件加入到一个更大的流体之中,通过流体的 ToRoute() 方法,可以获取对应的内部组件关联路由信息。 133 | 134 | ## 四. 简单示例场景 135 | 136 | 首先我们假设当前有一个进货管理的场景,需经历 进货申请,申请审批,购买支付,入库(同时邮件通知申请人) 几个环节,每个环节表示一个事件活动,比如申请活动我们定义如下: 137 | ```csharp 138 | public class ApplyActivity : BaseEffectActivity 139 | { 140 | public ApplyActivity() 141 | { 142 | PipeCode = "ApplyActivity"; 143 | } 144 | 145 | protected override Task> Executing(ApplyContext para) 146 | { 147 | LogHelper.Info($"发起 [{para.name}] 采购申请"); 148 | return Task.FromResult(new TrafficSignal(100000001L)); 149 | } 150 | } 151 | ``` 152 | 153 | 我们设定申请后审核自动执行,审核成功等待支付(被动类型)。 相同的处理方式我们定义剩下几个环节事件,列表如下: 154 | ```csharp 155 | ApplyActivity - 申请事件 (参数:ApplyContext) 156 | AutoAuditActivity - 审核事件 (参数:long) 157 | PayActivity - 购买事件 (参数:PayContext) 158 | StockActivity - 入库事件 (参数:StockContext) 159 | EmailActivity - 发送邮件事件 (参数:SendEmailContext) 160 | ``` 161 | 以上五个事件活动,其具体实现和参数完全独立,同时因为购买支付后邮件和入库是相互独立的事件,定义分支网关做分流(规则)处理,代码如下: 162 | ```csharp 163 | public class PayGateway : BaseBranchGateway 164 | { 165 | public PayGateway() 166 | { 167 | PipeCode = "PayGateway"; 168 | } 169 | 170 | protected override bool FilterBranchCondition(PayContext branchContext, IPipe branch, string prePipeCode) 171 | { 172 | LogHelper.Info($"通过{PipeCode} 判断分支 {branch.PipeCode} 是否满足分流条件!"); 173 | return base.FilterBranchCondition(branchContext, branch, prePipeCode); 174 | } 175 | } 176 | ``` 177 | 这里的意思相对简单,即传入的所有的分支不用过滤,直接全部分发。 178 | 179 | 同样因为五个事件的方法参数不尽相同,中间的我们添加消息连接器,作为消息的中转和转化处理(也可以在创建流体时表达式处理),以支付参数到邮件的参数转化示例: 180 | ```csharp 181 | public class PayEmailConnector : BaseMsgConverter 182 | { 183 | public PayEmailConnector() 184 | { 185 | PipeCode = "PayEmailConnector"; 186 | } 187 | protected override SendEmailContext Convert(PayContext inContextData) 188 | { 189 | // ...... 190 | return new SendEmailContext() { body = $" 您成功支付了订单,总额:{inContextData.money}" }; 191 | } 192 | } 193 | ``` 194 | 195 | 通过以上,申购流程的组件定义完毕,串联使用如下(这里是单元测试类,实际业务我们可以创建一个Service处理): 196 | 197 | ```csharp 198 | [TestClass] 199 | public class BuyFlowTests 200 | { 201 | public readonly ApplyActivity ApplyActivity = new ApplyActivity(); 202 | public readonly AutoAuditActivity AuditActivity = new AutoAuditActivity(); 203 | 204 | public readonly PayActivity PayActivity = new PayActivity(); 205 | 206 | public readonly PayGateway PayGateway = new PayGateway(); 207 | 208 | public readonly StockConnector StockConnector = new StockConnector(); 209 | public readonly StockActivity StockActivity = new StockActivity(); 210 | 211 | public readonly PayEmailConnector EmailConnector = new PayEmailConnector(); 212 | public readonly SendEmailActivity EmailActivity = new SendEmailActivity(); 213 | 214 | 215 | 216 | private EndGateway _endNode = new EndGateway(); 217 | 218 | // 构造函数内定义流体关联 219 | public BuyFlowTests() 220 | { 221 | 222 | 223 | ApplyActivity 224 | .Append(AuditActivity) 225 | 226 | .Append(PayActivity) 227 | .Append(PayGateway); 228 | 229 | // 网关分支 - 发送邮件分支 230 | PayGateway 231 | .Append(EmailConnector) 232 | .Append(EmailActivity) 233 | .Append(_endNode); 234 | 235 | // 网关分支- 入库分支 236 | PayGateway 237 | .Append(StockConnector) 238 | .Append(StockActivity) 239 | .Append(_endNode); 240 | 241 | 242 | } 243 | 244 | [TestMethod] 245 | public async Task FlowTest() 246 | { 247 | await ApplyActivity.Execute(new ApplyContext() 248 | { 249 | name = "冰箱" 250 | }); 251 | 252 | // 延后一秒,假装有支付操作 253 | await Task.Delay(1000); 254 | 255 | await PayActivity.Execute(new PayContext() 256 | { 257 | count = 10, 258 | money = 10000 259 | }); 260 | await Task.Delay(1000);// 等待异步日志执行完成 261 | } 262 | 263 | [TestMethod] 264 | public void RouteTest() 265 | { 266 | var TestPipeline = new Pipeline("test-flow", ApplyActivity, _endNode); 267 | 268 | var route = TestPipeline.ToRoute(); 269 | Assert.IsTrue(route != null); 270 | } 271 | } 272 | ``` 273 | 运行单元测试,结果如下: 274 | 275 | ``` 276 | xxxxxx 17:46:15 Detail: 通过ApplyActivity发起 [冰箱] 采购申请 277 | 278 | xxxxxx 17:46:15 Detail:通过AuditActivity 自动审核通过申请(编号:100000001) 279 | 280 | xxxxxx 17:46:16 Detail:通过PayActivity 支付动作执行,数量:10,金额:10000) 281 | 282 | xxxxxx 17:46:16 Detail:通过PayGateway 判断分支 PayEmailConnector 是否满足分流条件! 283 | 284 | xxxxxx 17:46:16 Detail:通过PayGateway 判断分支 StockConnector 是否满足分流条件! 285 | 286 | xxxxxx 17:46:16 Detail:分流-1(SendEmailActivity)邮件发送,内容: 您成功支付了订单,总额:10000 287 | 288 | xxxxxx 17:46:17 Detail: 通过 SendEmailActivity 管道进入结束网关! 289 | 290 | xxxxxx 17:46:17 Detail:分流-2(StockActivity)增加库存,数量:10 291 | 292 | xxxxxx 17:46:17 Detail: 通过 StockActivity 管道进入结束网关! 293 | 294 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------