├── 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 | ///