├── .editorconfig
├── .gitattributes
├── .github
└── workflows
│ └── dotnet.yml
├── .gitignore
├── .vscode
├── launch.json
├── solution-explorer
│ ├── class.cs-template
│ ├── class.ts-template
│ ├── class.vb-template
│ ├── default.ts-template
│ ├── enum.cs-template
│ ├── interface.cs-template
│ ├── interface.ts-template
│ ├── template-list.json
│ └── template-parameters.js
└── tasks.json
├── DotBPE.sln
├── LICENSE
├── RELEASE_NOTES.md
├── build
├── releasenotes.props
└── version.props
├── docs
├── .$dotbpe.drawio.bkp
├── amp协议.md
├── dotbpe.drawio
└── protobuf
│ ├── any.proto
│ ├── api.proto
│ ├── compiler
│ └── plugin.proto
│ ├── descriptor.proto
│ ├── duration.proto
│ ├── empty.proto
│ ├── field_mask.proto
│ ├── source_context.proto
│ ├── struct.proto
│ ├── timestamp.proto
│ ├── type.proto
│ └── wrappers.proto
├── icon.png
├── readme.md
├── samples
├── GreeterHttpService
│ ├── GreeterHttpService.csproj
│ ├── IGreeterService.cs
│ ├── ISwaggeSampleService.cs
│ ├── Program.cs
│ └── Startup.cs
├── MathClient
│ ├── MathClient.csproj
│ └── Program.cs
├── MathHttpClient
│ ├── MathHttpClient.csproj
│ ├── Program.cs
│ └── Startup.cs
├── MathService.Definition
│ ├── Entities.cs
│ ├── IMathService.cs
│ └── MathService.Definition.csproj
└── MathService
│ ├── MathService.cs
│ ├── MathService.csproj
│ └── Program.cs
├── scripts
├── build.sh
├── package_all.sh
├── publish_baseline.sh
├── publish_bestpractice.sh
├── publish_castle.sh
├── publish_consul.sh
├── publish_gateway.sh
├── publish_json.sh
├── publish_jsonnet.sh
├── publish_messagepack.sh
├── publish_pipeline.sh
├── publish_protobuf.sh
└── publish_rpc.sh
├── src
├── DotBPE.Baseline
│ ├── Collections
│ │ ├── ObservableDictionary.cs
│ │ ├── SettingsDictionary.cs
│ │ └── TagSet.cs
│ ├── DotBPE.Baseline.csproj
│ ├── Extensions
│ │ ├── AddressExtensions.cs
│ │ ├── ByteArrayExtensions.cs
│ │ ├── CollectionExtensions.cs
│ │ ├── ConcurrentQueueExtensions.cs
│ │ ├── DateTimeExtensions.cs
│ │ ├── EnumHelper.cs
│ │ ├── EnumerableExtensions.cs
│ │ ├── ExceptionExtensions.cs
│ │ ├── FileExtensions.cs
│ │ ├── HashExtensions.cs
│ │ ├── MimeExtensions.cs
│ │ ├── NameValueCollectionExtensions.cs
│ │ ├── NumericExtensions.cs
│ │ ├── StringExtensions.cs
│ │ ├── TaskCompletionSourceExtensions.cs
│ │ ├── TaskExtensions.cs
│ │ └── TaskFactoryExtensions.cs
│ └── Utility
│ │ ├── AssemblyDetail.cs
│ │ ├── CryptographyManager.cs
│ │ ├── IConnectionMapping.cs
│ │ ├── ObjectId.cs
│ │ └── SingletonBase.cs
├── DotBPE.BestPractice
│ ├── AuditLog
│ │ ├── AuditJsonFormatter.cs
│ │ ├── AuditLogFormatter.cs
│ │ └── AuditLogWriter.cs
│ ├── Constants
│ │ ├── BizErrorCodes.cs
│ │ └── ProtocolsConstants.cs
│ ├── DotBPE.BestPractice.csproj
│ ├── Exceptions
│ │ └── BizException.cs
│ ├── Extensions
│ │ └── ProtobufExtensions.cs
│ ├── HostBuilderExtensions.cs
│ ├── TaskResult.cs
│ └── Utility.cs
├── DotBPE.Extra.Castle
│ ├── CallContextServiceActorInterceptor.cs
│ ├── ClientInterceptor.cs
│ ├── DotBPE.Extra.Castle.csproj
│ ├── DynamicClientProxy.cs
│ ├── DynamicServiceActorLocator.cs
│ ├── Extensions
│ │ ├── ClientProxyFactoryExtensions.cs
│ │ ├── HostBuilderExtensions.cs
│ │ └── ServiceCollectionExtensions.cs
│ ├── IRpcServiceInterceptor.cs
│ ├── Interceptor.cs
│ ├── InvocationContext.cs
│ ├── InvokeMeta.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ReflectionHelper.cs
│ ├── RemoteInvokeInterceptor.cs
│ ├── ServiceAuditLogInterceptor.cs
│ └── ServiceMethod.cs
├── DotBPE.Extra.Json
│ ├── ClientProxyFactoryExtensions.cs
│ ├── DotBPE.Extra.Json.csproj
│ ├── HostBuilderExtensions.cs
│ ├── JsonParser.cs
│ ├── JsonSerializer.cs
│ └── ServiceCollectionExtensions.cs
├── DotBPE.Extra.JsonNet
│ ├── ClientProxyFactoryExtensions.cs
│ ├── DotBPE.Extra.JsonNet.csproj
│ ├── HostBuilderExtensions.cs
│ ├── JsonParser.cs
│ ├── JsonSerializer.cs
│ └── ServiceCollectionExtensions.cs
├── DotBPE.Extra.MessagePack
│ ├── ClientProxyFactoryExtensions.cs
│ ├── DotBPE.Extra.MessagePack.csproj
│ ├── HostBuilderExtensions.cs
│ ├── MessagePackSerializer.cs
│ └── ServiceCollectionExtensions.cs
├── DotBPE.Extra.Protobuf
│ ├── ClientProxyFactoryExtensions.cs
│ ├── DotBPE.Extra.Protobuf.csproj
│ ├── HostBuilderExtensions.cs
│ ├── JsonParser.cs
│ ├── ProtobufSerializer.cs
│ └── ServiceCollectionExtensions.cs
├── DotBPE.Gateway
│ ├── Attributes
│ │ └── HttpRouteAttribute.cs
│ ├── Contracts
│ │ ├── IHttpApiErrorProcess.cs
│ │ ├── IHttpApiOutputProcess.cs
│ │ ├── IHttpOutputProcessPlugin.cs
│ │ ├── IHttpPlugin.cs
│ │ ├── IHttpProcessPlugin.cs
│ │ ├── IHttpRequestParsePlugin.cs
│ │ └── IHttpRequestParsePostPlugin.cs
│ ├── DotBPE.Gateway.csproj
│ ├── Extensions
│ │ ├── ApplicationBuilderExtensions.cs
│ │ ├── EndpointRouteBuilderExtensions.cs
│ │ ├── HttpRequestExtensions.cs
│ │ └── ServiceCollectionExtensions.cs
│ ├── HttpApiOption.cs
│ ├── HttpVerb.cs
│ ├── Internal
│ │ ├── ApiEndpointConventionBuilder.cs
│ │ ├── ApiMethod.cs
│ │ ├── ApiMethodInvoker.cs
│ │ ├── ApiMethodModel.cs
│ │ ├── ApiMethodProviderContext.cs
│ │ ├── ApiProviderServiceBinder.cs
│ │ ├── ApiRouteBuilder.cs
│ │ ├── DefaultApiMethodProvider.cs
│ │ ├── HttpApiCallHandler.cs
│ │ ├── HttpApiMetadata.cs
│ │ ├── IApiMethodProvider.cs
│ │ ├── RequestEncoding.cs
│ │ └── ResponseEncoding.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── RpcGatewayOption.cs
│ └── Swagger
│ │ ├── ApiModelMetadata.cs
│ │ ├── DefaultSwaggerProvider.cs
│ │ ├── HttpApiDescriptionProvider.cs
│ │ ├── ISwaggerProvider.cs
│ │ ├── Models
│ │ ├── SwaggerApiContactInfo.cs
│ │ ├── SwaggerApiInfo.cs
│ │ ├── SwaggerApiParameters.cs
│ │ ├── SwaggerApiResponse.cs
│ │ ├── SwaggerDefinition.cs
│ │ ├── SwaggerInfo.cs
│ │ ├── SwaggerItemSchema.cs
│ │ ├── SwaggerMethod.cs
│ │ └── SwaggerPropertyDefinition.cs
│ │ ├── SwaggerMiddleware.cs
│ │ ├── SwaggerOptions.cs
│ │ ├── SwaggerUIMiddleware.cs
│ │ ├── SwaggerUIOptions.cs
│ │ ├── UI
│ │ ├── DebugContent.3b78e7fd.js
│ │ ├── DebugContent.a773311c.css
│ │ ├── favicon.7cc1a2af.svg
│ │ ├── index.57a718f9.js
│ │ ├── index.6d96fa03.css
│ │ ├── index.html
│ │ ├── react-venders.a651e260.js
│ │ └── v2
│ │ │ └── swagger.json
│ │ └── XmlComments
│ │ ├── XmlCommentResolver.cs
│ │ ├── XmlCommentsMemberNameHelper.cs
│ │ └── XmlCommentsTextHelper.cs
└── DotBPE.Rpc
│ ├── Attributes
│ ├── RpcMethodAttribute.cs
│ └── RpcServiceAttribute.cs
│ ├── AuditLog
│ ├── AuditLogger.cs
│ ├── IAuditLogFormatter.cs
│ ├── IAuditLogInfo.cs
│ ├── IAuditLogWriter.cs
│ ├── IAuditLogger.cs
│ └── IAuditLoggerFactory.cs
│ ├── Client
│ ├── ClientProxyFactory.cs
│ ├── ICallInvoker.cs
│ ├── IClientMessageHandler.cs
│ ├── IClientProxy.cs
│ ├── IClientProxyFactory.cs
│ ├── IMessageSubscriber.cs
│ ├── IMessageSubscriberContainer.cs
│ ├── IRouterPoint.cs
│ ├── IRoutingPolicy.cs
│ ├── IRpcClient.cs
│ ├── IServiceRouter.cs
│ ├── ITransport.cs
│ ├── ITransportFactory.cs
│ ├── Impl
│ │ ├── DefaultCallInvoker.cs
│ │ ├── DefaultClientMessageHandler.cs
│ │ ├── DefaultMessageSubscriberContainer.cs
│ │ ├── DefaultRpcClient.cs
│ │ ├── DefaultServiceRouter.cs
│ │ ├── DefaultTransport.cs
│ │ ├── DefaultTransportFactory.cs
│ │ └── RpcSocketClient.cs
│ └── RoutingPolicies
│ │ ├── RandomRoutingPolicy.cs
│ │ ├── RoundrobinRoutingPolicy.cs
│ │ └── WeightedRoundRobinRoutingPolicy.cs
│ ├── Codec
│ ├── CodecType.cs
│ └── ISerializer.cs
│ ├── DotBPE.Rpc.csproj
│ ├── Exceptions
│ ├── RpcCodecException.cs
│ ├── RpcCommunicationException.cs
│ └── RpcException.cs
│ ├── Extensions
│ ├── ClientProxyFactoryExtensions.cs
│ ├── HostBuilderExtensions.cs
│ └── ServiceCollectionExtensions.cs
│ ├── Hosting
│ ├── AmpPeachSocketService.cs
│ ├── PeachServerBootstrap.cs
│ ├── PeachServerHost.cs
│ ├── RpcServerOptions.cs
│ └── RpcServiceHostedService.cs
│ ├── IJsonParser.cs
│ ├── IMethod.cs
│ ├── IRpcContext.cs
│ ├── Internal
│ ├── HeartBeatServiceActor.cs
│ ├── HeartBeatServiceActorHandler.cs
│ ├── NotFoundServiceActor.cs
│ └── NotFoundServiceActorHandler.cs
│ ├── Method.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── Protocols
│ ├── AmpChannelHandlerPipeline.cs
│ ├── AmpDecodeHandler.cs
│ ├── AmpEncodeHandler.cs
│ ├── AmpMessage.cs
│ ├── AmpProtocol.cs
│ ├── IRpcMessage.cs
│ └── RpcStatusCodes.cs
│ ├── RouterPointOptions.cs
│ ├── RpcClientOptions.cs
│ ├── RpcResult.cs
│ ├── Server
│ ├── ActorInvokerModel.cs
│ ├── ICallContext.cs
│ ├── IContextAccessor.cs
│ ├── IMessageHandler.cs
│ ├── IServerHost.cs
│ ├── IServiceActor.cs
│ ├── IServiceActorBuilder.cs
│ ├── IServiceActorHandler.cs
│ ├── IServiceActorHandlerFactory.cs
│ ├── IServiceActorLocator.cs
│ ├── IServiceActorProvider.cs
│ ├── Impl
│ │ ├── ActorCallHandler.cs
│ │ ├── BaseService.cs
│ │ ├── DefaultMessageHandler.cs
│ │ ├── DefaultServiceActorHandlerFactory.cs
│ │ ├── DefaultServiceActorLocator.cs
│ │ ├── MethodInvoker.cs
│ │ ├── RpcContext.cs
│ │ ├── ServerMethod.cs
│ │ └── ServiceActorHandler.cs
│ ├── RequestDelegate.cs
│ ├── ServiceActorBinder.cs
│ ├── ServiceActorProvider.cs
│ └── ServiceActorProviderContext.cs
│ ├── ServiceModel.cs
│ └── Utils
│ └── EndPointParser.cs
└── tests
├── DotBPE.Extra.Castle.Tests
├── ClientInterceptorTest.cs
├── DotBPE.Extra.Castle.Tests.csproj
├── DynamicClientProxyTests.cs
├── ServiceActorInterceptorTests.cs
└── TestObjects
│ └── LogInterceptor.cs
├── DotBPE.Gateway.Tests
├── DefaultApiMethodProviderTests.cs
├── DotBPE.Gateway.Tests.csproj
├── HttpApiCallHandlerTests.cs
├── ServiceExtensionsTests.cs
└── TestObjects
│ ├── DefaultJsonSerializer.cs
│ ├── IInvalidPatternTestService.cs
│ └── TestGreetService.cs
├── DotBPE.Rpc.Tests
├── Client
│ ├── ClientProxyFactoryTests.cs
│ ├── DefaultCallInvokerTests.cs
│ ├── DefaultClientMessageHandlerTests.cs
│ ├── DefaultMessageSubscriberContainerTests.cs
│ ├── DefaultRpcClientTests.cs
│ └── DefaultTransportFactoryTests.cs
├── DotBPE.Rpc.Tests.csproj
├── Hosting
│ └── PeachServerHostTest.cs
├── Protocols
│ └── AmpProtocolTests.cs
└── Server
│ ├── DefaultMessageHandlerTests.cs
│ ├── DefaultServiceActorHandlerFactoryTests.cs
│ └── DefaultServiceActorLocatorTests.cs
└── DotBPE.TestBase
├── DotBPE.TestBase.csproj
├── Services
├── FooService.cs
└── IFooService.cs
└── TextJsonSerializer.cs
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.doc diff=astextplain
2 | *.DOC diff=astextplain
3 | *.docx diff=astextplain
4 | *.DOCX diff=astextplain
5 | *.dot diff=astextplain
6 | *.DOT diff=astextplain
7 | *.pdf diff=astextplain
8 | *.PDF diff=astextplain
9 | *.rtf diff=astextplain
10 | *.RTF diff=astextplain
11 | *.jpg binary
12 | *.png binary
13 | *.gif binary
14 | *.cs text=auto diff=csharp
15 | *.vb text=auto
16 | *.resx text=auto
17 | *.c text=auto
18 | *.cpp text=auto
19 | *.cxx text=auto
20 | *.h text=auto
21 | *.hxx text=auto
22 | *.py text=auto
23 | *.rb text=auto
24 | *.java text=auto
25 | *.html text=auto
26 | *.htm text=auto
27 | *.css text=auto
28 | *.scss text=auto
29 | *.sass text=auto
30 | *.less text=auto
31 | *.js text=auto
32 | *.lisp text=auto
33 | *.clj text=auto
34 | *.sql text=auto
35 | *.php text=auto
36 | *.lua text=auto
37 | *.m text=auto
38 | *.asm text=auto
39 | *.erl text=auto
40 | *.fs text=auto
41 | *.fsx text=auto
42 | *.hs text=auto
43 | *.csproj text=auto
44 | *.vbproj text=auto
45 | *.fsproj text=auto
46 | *.dbproj text=auto
47 | *.sln text=auto eol=crlf
--------------------------------------------------------------------------------
/.github/workflows/dotnet.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a .NET project
2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3 |
4 | name: .NET
5 |
6 | on:
7 | push:
8 | branches: [ "master" ]
9 | pull_request:
10 | branches: [ "master" ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v4
19 | - name: Setup .NET
20 | uses: actions/setup-dotnet@v4
21 | with:
22 | dotnet-version: 8.0.x
23 | - name: Restore dependencies
24 | run: dotnet restore
25 | - name: Build
26 | run: dotnet build --no-restore
27 | - name: Test
28 | run: dotnet test --no-build --verbosity normal
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Oo]bj/
2 | [Bb]in/
3 | TestResults/
4 | .nuget/
5 | _ReSharper.*/
6 | packages/
7 | artifacts/
8 | PublishProfiles/
9 | *.user
10 | *.suo
11 | *.cache
12 | *.docstates
13 | _ReSharper.*
14 | nuget.exe
15 | *net45.csproj
16 | *net451.csproj
17 | *k10.csproj
18 | *.psess
19 | *.vsp
20 | *.pidb
21 | *.userprefs
22 | *DS_Store
23 | *.ncrunchsolution
24 | *.*sdf
25 | *.ipch
26 | *.sln.ide
27 | *.sublime-workspace
28 | node_modules/
29 | node_modules1/
30 | node_modules2/
31 | .build/
32 | logs/
33 | typings/
34 | project.lock.json
35 | classes
36 | data
37 | temp
38 | doc/site
39 | dist
40 | # Logs
41 | logs
42 | *.log
43 | npm-debug.log*
44 | # Runtime data
45 | pids
46 | *.pid
47 | *.seed
48 | # Directory for instrumented libs generated by jscoverage/JSCover
49 | lib-cov
50 | # Coverage directory used by tools like istanbul
51 | coverage
52 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
53 | .grunt
54 | # node-waf configuration
55 | .lock-wscript
56 | # Compiled binary addons (http://nodejs.org/api/addons.html)
57 | build/Release
58 | # Dependency directory
59 | node_modules
60 | # Optional npm cache directory
61 | .npm
62 | # Optional REPL history
63 | .node_repl_history
64 | cache/
65 | .vs/
66 | *.lnk
67 | *.Production.json
68 | .idea/
69 | .vscode/
70 | workspace.xml
71 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to find out which attributes exist for C# debugging
3 | // Use hover for the description of the existing attributes
4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": ".NET Core Launch (console)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/src/sample/06-gateway-aspnet/GatewayForAspNet/bin/Debug/netcoreapp2.0/GatewayForAspNet.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}/src/sample/06-gateway-aspnet/GatewayForAspNet",
16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
17 | "console": "internalConsole",
18 | "stopAtEntry": false,
19 | "internalConsoleOptions": "openOnSessionStart"
20 | },
21 | {
22 | "name": ".NET Core Attach",
23 | "type": "coreclr",
24 | "request": "attach",
25 | "processId": "${command:pickProcess}"
26 | }
27 | ]
28 | }
--------------------------------------------------------------------------------
/.vscode/solution-explorer/class.cs-template:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace {{namespace}}
4 | {
5 | public class {{name}}
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/.vscode/solution-explorer/class.ts-template:
--------------------------------------------------------------------------------
1 | export class {{name}} {
2 |
3 | }
--------------------------------------------------------------------------------
/.vscode/solution-explorer/class.vb-template:
--------------------------------------------------------------------------------
1 | Imports System
2 |
3 | Namespace {{namespace}}
4 |
5 | Public Class {{name}}
6 |
7 | End Class
8 |
9 | End Namespace
10 |
--------------------------------------------------------------------------------
/.vscode/solution-explorer/default.ts-template:
--------------------------------------------------------------------------------
1 | export default {{name}} {
2 |
3 | }
--------------------------------------------------------------------------------
/.vscode/solution-explorer/enum.cs-template:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace {{namespace}}
4 | {
5 | public enum {{name}}
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/.vscode/solution-explorer/interface.cs-template:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace {{namespace}}
4 | {
5 | public interface {{name}}
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/.vscode/solution-explorer/interface.ts-template:
--------------------------------------------------------------------------------
1 | export interface {{name}} {
2 |
3 | }
--------------------------------------------------------------------------------
/.vscode/solution-explorer/template-list.json:
--------------------------------------------------------------------------------
1 | {
2 | "templates": [
3 | {
4 | "name": "Class",
5 | "extension": "cs",
6 | "file": "./class.cs-template",
7 | "parameters": "./template-parameters.js"
8 | },
9 | {
10 | "name": "Interface",
11 | "extension": "cs",
12 | "file": "./interface.cs-template",
13 | "parameters": "./template-parameters.js"
14 | },
15 | {
16 | "name": "Enum",
17 | "extension": "cs",
18 | "file": "./enum.cs-template",
19 | "parameters": "./template-parameters.js"
20 | },
21 | {
22 | "name": "Class",
23 | "extension": "ts",
24 | "file": "./class.ts-template",
25 | "parameters": "./template-parameters.js"
26 | },
27 | {
28 | "name": "Interface",
29 | "extension": "ts",
30 | "file": "./interface.ts-template",
31 | "parameters": "./template-parameters.js"
32 | },
33 | {
34 | "name": "Default",
35 | "extension": "ts",
36 | "file": "./default.ts-template",
37 | "parameters": "./template-parameters.js"
38 | },
39 | {
40 | "name": "Class",
41 | "extension": "vb",
42 | "file": "./class.vb-template",
43 | "parameters": "./template-parameters.js"
44 | }
45 | ]
46 | }
--------------------------------------------------------------------------------
/.vscode/solution-explorer/template-parameters.js:
--------------------------------------------------------------------------------
1 | var path = require("path");
2 |
3 | module.exports = function(filename, projectPath, folderPath) {
4 | var namespace = "Unknown";
5 | if (projectPath) {
6 | namespace = path.basename(projectPath, path.extname(projectPath));
7 | if (folderPath) {
8 | namespace += "." + folderPath.replace(path.dirname(projectPath), "").substring(1).replace(/[\\\/]/g, ".");
9 | }
10 | }
11 |
12 | return {
13 | namespace: namespace,
14 | name: path.basename(filename, path.extname(filename))
15 | }
16 | };
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "taskName": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/src/sample/06-gateway-aspnet/GatewayForAspNet/GatewayForAspNet.csproj"
11 | ],
12 | "problemMatcher": "$msCompile"
13 | }
14 | ]
15 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 xuanye wang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/RELEASE_NOTES.md:
--------------------------------------------------------------------------------
1 |
2 | #### 2.0.5 Feb 21, 2019
3 | 1. 修复心跳包服务端没有正确返回的问题
4 | 2. 修复网关处理Post Json时,部分数据丢失的问题
5 | 3. 新增动态调用反射帮助类,支持动态调用,方便测试
6 | 4. 修复审计日志没有正确记录的问题
7 | 5. 修复其他已知的问题
8 |
9 |
10 | #### 2.0.0 Jan 30, 2019
11 | 1. 重构框架,分离通信相关的代码
12 | 2. 支持本地和远端服务自动调度
13 | 3. 服务注册和发现(可选)
14 | 4. 支持多种路由方式(可选)
15 | 5. 支持依赖注入和AOP
16 | 6. 支持服务分组
17 | 7. 轻量级的Http网关
18 | 8. 支持多种服务声明方式,接口或者服务描述文件
19 | 9. 多种序列化方式:Protobuf、MessagePack、JSON
20 |
--------------------------------------------------------------------------------
/build/releasenotes.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 1. 添加时间格式化一般字符串表示法的扩展方法
7 |
8 |
9 | 1. 调整TargetFramework 为 netstandard2.0,去除不必要的升级
10 | 2. 扫描注入的接口新增了Host绑定的服务分组参数,用于区分注册服务
11 | 3. 修复心跳包时长问题导致的长连接一直断开的问题
12 | 4. 升级Peach到0.2.2,解决某些网络环境下,无法获取到内网IP,导致绑定地址错误
13 |
14 |
15 | 1. 优化代码逻辑
16 | 2. 添加客户端和服务器端拦截器的实现
17 |
18 |
19 |
20 | 1. 调整TargetFramework 为 netstandard2.0,去除不必要的升级
21 |
22 |
23 | 1. 实现System.Text.Json的编解码实现
24 |
25 |
26 | 1. 调整TargetFramework 为 netstandard2.0,去除不必要的升级
27 |
28 |
29 | 1. 调整TargetFramework 为 netstandard2.0,去除不必要的升级
30 |
31 |
32 | 1. 新增绑定到IWebHost的RPC服务,主要用于测试
33 | 2. 重构Gateway,参考gRPC的绑定方式
34 | 3. 合并Swagger相关的内容到Gateway项目中
35 | 4. 更新自定义SwaggerUI
36 |
37 |
38 | 1. 移除不必要的引用
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/build/version.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 3.0.2
4 | 1.0.2
5 | 3.0.3
6 | 1.0.1
7 | 3.0.0
8 | 3.0.0
9 | 3.0.0
10 | 3.0.1
11 | 3.0.2
12 |
13 |
14 |
--------------------------------------------------------------------------------
/docs/amp协议.md:
--------------------------------------------------------------------------------
1 | ### AMP协议说明 版本0
2 |
3 | ```
4 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14151617 -18
5 | +------------+----------+---------+------+-------+---------+---------+------------+
6 | | | | ||| | | |
7 | +------------+----------+---------+------+-------+---------+---------+------------+
8 | ```
9 |
10 | + ver/argc = 版本 固定填0
11 | + length = 为总包长
12 | + seq = 请求序列号
13 | + type = 消息类型
14 | * 1 = Request 请求消息
15 | * 2 = Response 响应消息
16 | * 3 = Notify 通知消息
17 | + serId = serviceId 服务号
18 | + msgId = msgId 消息ID
19 | + code = 当 type = 0 (请求时)固定传0 ,其他即为响应码,如果响应码不为0 则认为请求失败,具体错误码再定义
20 | + data = 实际的业务数据
21 |
22 |
23 | ### AMP协议说明 版本1
24 |
25 | ```
26 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 1415 16171819 20 -21
27 | +------------+----------+---------+------+-------------+---------+---------+--------+------------+
28 | | | | || | | | | |
29 | +------------+----------+---------+------+-------------+---------+---------+--------+------------+
30 | ```
31 |
32 | + ver/argc = 版本 固定填1
33 | + length = 为总包长
34 | + seq = 请求序列号
35 | + type = 消息类型
36 | * 1 = Request 请求消息
37 | * 2 = Response 响应消息
38 | * 3 = Notify 通知消息
39 | * 4 = InvokeWithoutResponse 调用不关心返回值
40 | + serId = serviceId 服务号
41 | + msgId = msgId 消息ID
42 | + code = 当 type = 0 (请求时)固定传0 ,其他即为响应码,如果响应码不为0 则认为请求失败,具体错误码再定义
43 | + codecType = 编码方式 0=默认 Protobuf 1=MessagePack 2=JSON
44 | + data = 实际的业务数据
45 |
--------------------------------------------------------------------------------
/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuanye/dotbpe/5f25603a96ac9f69e6e47461145cd81c10682d35/icon.png
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | dotbpe
2 | -------------
3 |
4 | dotbpe一套基于dotnet core平台的业务流程处理引擎,力求解决项目开发中,关于服务端开发的各种通用问题,如远程过程调用(Rpc),延迟队列(DelayTaskQueue),任务调度(TaskManage),网关(Gateway)等问题。
5 |
6 | dotbpe rpc 项目就是其中的Rpc部分的实现,底层的通讯部份基于[Peach](https://github.com/xuanye/peach)(基于DotNetty封装,支持自定义协议的Socket类库)。该组件的目标并不是只是解决Rpc的问题,同时考虑到开发调式的便利性,支持本地服务和远端无差别开发,在编码时不用考虑服务是如何部署的(分布式或者单机部署),可以在项目初期流量较少时,只部署单台或者做简单的负载均衡即可,当项目流量增加后可通过配置和部署方案,不需要修改任何代码来实现快速扩容。
7 |
8 | dotbpe rpc 支持两种开发模式,一种类似于Dubbo的定义接口的方式Rpc服务,另外一种支持像gRpc方式,预先定义服务描述文件(.proto)来定义Rpc服务.
9 | > Note: 在同一个项目中应规范只使用一种,如无特殊情况,应避免交叉使用
10 |
11 |
12 | ## Features
13 |
14 | - 高性能,易于使用的分布式远程调用框架
15 | - 支持本地和远端服务自动调度
16 | - 服务治理功能
17 | - 注册中心(可选)
18 | - 失败重试方式(可选)
19 | - 支持多种路由方式(可选)
20 | - 支持依赖注入和AOP
21 | - 支持服务分组
22 | - 轻量级的Http网关
23 | - 快速测试工具
24 | - 支持服务声明方式
25 | - 使用C#代码定义接口方式,类似Dubbo
26 | - 使用proto文件定义,类似gRpc (使用该方式则序列化只能使用Protobuf)
27 | - 多种序列化方式(不能混合使用)
28 | - Protobuf
29 | - MessagePack
30 | - JSON
31 | - 支持多个扩展点
32 |
33 |
34 | ## 二进制协议说明
35 |
36 | ```
37 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 1415 16171819 20 -21
38 | +------------+----------+---------+------+-------------+---------+---------+--------+------------+
39 | | | | || | | | | |
40 | +------------+----------+---------+------+-------------+---------+---------+--------+------------+
41 | ```
42 |
43 | + ver/argc = 版本 固定填1
44 | + length = 为总包长
45 | + seq = 请求序列号
46 | + type = 消息类型
47 | * 1 = Request 请求消息
48 | * 2 = Response 响应消息
49 | * 3 = Notify 通知消息
50 | * 4 = InvokeWithoutResponse 调用不关心返回值
51 | + serId = serviceId 服务号
52 | + msgId = msgId 消息ID
53 | + code = 当 type = 0 (请求时)固定传0 ,其他即为响应码,如果响应码不为0 则认为请求失败,具体错误码再定义
54 | + codecType = 编码方式 0=默认 Protobuf 1=MessagePack 2=JSON
55 | + data = 实际的业务数据
56 |
--------------------------------------------------------------------------------
/samples/GreeterHttpService/GreeterHttpService.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | true
7 | $(NoWarn);1591
8 | win10-x64;centos.7-x64
9 | 100
10 | 100
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/samples/GreeterHttpService/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore;
2 | using Microsoft.AspNetCore.Hosting;
3 | using Microsoft.Extensions.Logging;
4 | using System.Threading;
5 |
6 | namespace GreeterHttpService
7 | {
8 | static class Program
9 | {
10 | static void Main(string[] args)
11 | {
12 | ThreadPool.SetMinThreads(100, 100);
13 | BuildWebHost(args).Run();
14 | }
15 |
16 | static IWebHost BuildWebHost(string[] args) =>
17 | WebHost.CreateDefaultBuilder(args)
18 | .UseUrls("http://*:5560") //HTTP绑定在5560端口
19 | .UseStartup()
20 | .ConfigureLogging(builder => { builder.SetMinimumLevel(LogLevel.Warning); })
21 | .Build();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/samples/MathClient/MathClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/samples/MathHttpClient/MathHttpClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0
6 | true
7 | $(NoWarn);1591
8 | win10-x64;centos.7-x64
9 | 100
10 | 100
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/samples/MathHttpClient/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using Microsoft.AspNetCore;
4 | using Microsoft.AspNetCore.Hosting;
5 | using Microsoft.Extensions.Logging;
6 |
7 | namespace MathHttpClient
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | ThreadPool.SetMinThreads(100, 100);
14 | BuildWebHost(args).Run();
15 | }
16 |
17 | static IWebHost BuildWebHost(string[] args) =>
18 | WebHost.CreateDefaultBuilder(args)
19 | .UseUrls("http://*:5561") //HTTP绑定在6200端口
20 | .UseStartup()
21 | .ConfigureLogging(builder => { builder.SetMinimumLevel(LogLevel.Debug); })
22 | .Build();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/samples/MathHttpClient/Startup.cs:
--------------------------------------------------------------------------------
1 | using DotBPE.Extra;
2 | using DotBPE.Gateway;
3 | using DotBPE.Rpc.Config;
4 | using MathService.Definition;
5 | using Microsoft.AspNetCore.Builder;
6 | using Microsoft.AspNetCore.Http;
7 | using Microsoft.AspNetCore.Routing;
8 | using Microsoft.Extensions.DependencyInjection;
9 | using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
10 |
11 | namespace MathHttpClient
12 | {
13 | public class Startup
14 | {
15 | public Startup(IConfiguration config)
16 | {
17 | this.Configuration = config;
18 | }
19 |
20 | IConfiguration Configuration { get; }
21 |
22 | // This method gets called by the runtime. Use this method to add services to the container.
23 | public void ConfigureServices(IServiceCollection services)
24 | {
25 | services.Configure(router =>
26 | {
27 | router.Categories.Add(new GroupIdentifierOption
28 | {
29 | GroupName = "default",
30 | RemoteAddress = Peach.Infrastructure.IPUtility.GetLocalIntranetIP()+":5566"
31 | });
32 | });
33 |
34 |
35 | services.AddMessagePackSerializer(); //message pack serializer
36 | services.AddJsonNetParser(); // http result json parser
37 | services.AddDynamicClientProxy(); // aop client
38 | services.AddDynamicServiceProxy(); // aop service
39 |
40 | services.AddDotBPEHttpApi();
41 |
42 | }
43 |
44 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
45 | public void Configure(IApplicationBuilder app)
46 | {
47 | app.UseRouting();
48 | app.UseEndpoints(endpoints => {
49 |
50 | endpoints.MapService();
51 |
52 | endpoints.MapGet("/", async context =>
53 | {
54 | await context.Response.WriteAsync("Welcome to DotBPE RPC Service.");
55 | });
56 | });
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/samples/MathService.Definition/Entities.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using System.Runtime.Serialization;
5 |
6 | namespace MathService.Definition
7 | {
8 | ///
9 | /// 加法返回值
10 | ///
11 | [DataContract]
12 | public class SumRes
13 | {
14 | ///
15 | /// 总记录
16 | ///
17 | [DataMember(Order = 1, Name = "total")]
18 | public int Total { get; set; }
19 |
20 | }
21 |
22 | ///
23 | /// 加法请求
24 | ///
25 | [DataContract]
26 | public class SumReq
27 | {
28 | ///
29 | /// 字段A
30 | ///
31 | [DataMember(Order = 1, Name = "a")]
32 | public int A { get; set; }
33 |
34 | ///
35 | /// 字段B
36 | ///
37 | [DataMember(Order = 2, Name = "b")]
38 | public int B { get; set; }
39 | }
40 |
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/samples/MathService.Definition/IMathService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Rpc;
5 | using System.Threading.Tasks;
6 |
7 | namespace MathService.Definition
8 | {
9 | ///
10 | /// 数学服务
11 | ///
12 | [RpcService(100)]
13 | public interface IMathService
14 | {
15 | ///
16 | /// 加法服务
17 | ///
18 | /// 请求参数req
19 | /// 返回值Res
20 | [RpcMethod(1)]
21 | Task> SumAsync(SumReq req);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/samples/MathService.Definition/MathService.Definition.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | true
6 | $(NoWarn);1591
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/samples/MathService/MathService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Rpc;
5 | using DotBPE.Rpc.Server;
6 | using MathService.Definition;
7 | using Microsoft.Extensions.Logging;
8 | using System.Threading.Tasks;
9 |
10 | namespace MathService
11 | {
12 | public class MathService : BaseService, IMathService
13 | {
14 | private readonly ILogger _logger;
15 |
16 | public MathService(ILogger logger)
17 | {
18 | _logger = logger;
19 | }
20 | public Task> SumAsync(SumReq req)
21 | {
22 | var result = new RpcResult { Data = new SumRes() };
23 | result.Data.Total = req.A + req.B;
24 |
25 | _logger.LogInformation("A+B=C {A}+{B}={C}", req.A, req.B, result.Data.Total);
26 |
27 | return Task.FromResult(result);
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/samples/MathService/MathService.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | win10-x64;centos.7-x64
7 | 100
8 | 100
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/samples/MathService/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Extra;
5 | using Microsoft.Extensions.DependencyInjection;
6 | using Microsoft.Extensions.Hosting;
7 | using Microsoft.Extensions.Logging;
8 |
9 | namespace MathService
10 | {
11 | static class Program
12 | {
13 | static void Main(string[] args)
14 | {
15 | var builder = new HostBuilder()
16 | .UseRpcServer()
17 | .UseCastleDynamicProxy()
18 | .UseMessagePackSerializer()
19 | .BindService()
20 | .ConfigureLogging(
21 | logger =>
22 | {
23 | logger.SetMinimumLevel(LogLevel.Debug);
24 | logger.AddConsole();
25 | }
26 | );
27 |
28 | //启动
29 | builder.RunServerAsync().GetAwaiter().GetResult();
30 |
31 |
32 | /*
33 | * Consul Service Registration
34 | *
35 | var builder = new HostBuilder()
36 | .UseRpcServer()
37 | .UseCastleDynamicProxy()
38 | .UseMessagePack()
39 | .BindService()
40 | //.BindServices(services => { services.Add();})
41 | .UseConsulServiceRegistration((point, list) =>
42 | {
43 | var tcpCheck = new AgentServiceCheck
44 | {
45 | DeregisterCriticalServiceAfter = 1.Minutes(),
46 | Interval = 30.Seconds(),
47 | TCP = EndPointParser.ParseEndPointToString(point.RemoteAddress)
48 | };
49 | list.Add(tcpCheck);
50 | }) //添加服务注册的依赖
51 | .ConfigureLogging(
52 | logger =>
53 | {
54 | logger.AddConsole();
55 | }
56 | );
57 |
58 | //启动
59 | builder.RegisterAndRunConsoleAsync().Wait();
60 | */
61 |
62 |
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/scripts/build.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet restore ./DotBPE.sln
14 | dotnet build ./DotBPE.sln -c Release
15 |
--------------------------------------------------------------------------------
/scripts/package_all.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet restore ./DotBPE.sln
14 | dotnet build ./DotBPE.sln -c Release
15 |
16 | dotnet pack ./src/DotBPE.Baseline/DotBPE.Baseline.csproj -c Release -o $artifactsFolder
17 | dotnet pack ./src/DotBPE.Extra.Castle/DotBPE.Extra.Castle.csproj -c Release -o $artifactsFolder
18 | dotnet pack ./src/DotBPE.Extra.JsonNet/DotBPE.Extra.JsonNet.csproj -c Release -o $artifactsFolder
19 | dotnet pack ./src/DotBPE.Extra.MessagePack/DotBPE.Extra.MessagePack.csproj -c Release -o $artifactsFolder
20 | dotnet pack ./src/DotBPE.Extra.Protobuf/DotBPE.Extra.Protobuf.csproj -c Release -o $artifactsFolder
21 | dotnet pack ./src/DotBPE.Extra.Json/DotBPE.Extra.Json.csproj -c Release -o $artifactsFolder
22 | dotnet pack ./src/DotBPE.Gateway/DotBPE.Gateway.csproj -c Release -o $artifactsFolder
23 | dotnet pack ./src/DotBPE.Rpc/DotBPE.Rpc.csproj -c Release -o $artifactsFolder
24 | dotnet pack ./src/DotBPE.BestPractice/DotBPE.BestPractice.csproj -c Release -o $artifactsFolder
25 |
26 |
--------------------------------------------------------------------------------
/scripts/publish_baseline.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.Baseline/DotBPE.Baseline.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.Baseline/DotBPE.Baseline.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.Baseline.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/scripts/publish_bestpractice.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.BestPractice/DotBPE.BestPractice.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.BestPractice/DotBPE.BestPractice.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.BestPractice.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/scripts/publish_castle.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.Extra.Castle/DotBPE.Extra.Castle.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.Extra.Castle/DotBPE.Extra.Castle.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.Extra.Castle.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/scripts/publish_consul.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.Extra.Consul/DotBPE.Extra.Consul.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.Extra.Consul/DotBPE.Extra.Consul.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.Extra.Consul.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/scripts/publish_gateway.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 |
14 | dotnet build ./src/DotBPE.Gateway/DotBPE.Gateway.csproj -c Release
15 |
16 | dotnet pack ./src/DotBPE.Gateway/DotBPE.Gateway.csproj -c Release -o $artifactsFolder
17 |
18 | dotnet nuget push ./$artifactsFolder/DotBPE.Gateway.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
19 |
--------------------------------------------------------------------------------
/scripts/publish_json.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.Extra.Json/DotBPE.Extra.Json.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.Extra.Json/DotBPE.Extra.Json.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.Extra.Json.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/scripts/publish_jsonnet.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.Extra.JsonNet/DotBPE.Extra.JsonNet.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.Extra.JsonNet/DotBPE.Extra.JsonNet.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.Extra.JsonNet.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/scripts/publish_messagepack.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.Extra.MessagePack/DotBPE.Extra.MessagePack.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.Extra.MessagePack/DotBPE.Extra.MessagePack.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.Extra.MessagePack.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/scripts/publish_pipeline.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.Extra.Pipeline/DotBPE.Extra.Pipeline.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.Extra.Pipeline/DotBPE.Extra.Pipeline.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.Extra.Pipeline.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/scripts/publish_protobuf.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.Extra.Protobuf/DotBPE.Extra.Protobuf.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.Extra.Protobuf/DotBPE.Extra.Protobuf.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.Extra.Protobuf.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/scripts/publish_rpc.sh:
--------------------------------------------------------------------------------
1 | set -ex
2 |
3 | cd $(dirname $0)/../
4 |
5 | artifactsFolder="./artifacts"
6 |
7 | if [ -d $artifactsFolder ]; then
8 | rm -R $artifactsFolder
9 | fi
10 |
11 | mkdir -p $artifactsFolder
12 |
13 | dotnet build ./src/DotBPE.Rpc/DotBPE.Rpc.csproj -c Release
14 |
15 | dotnet pack ./src/DotBPE.Rpc/DotBPE.Rpc.csproj -c Release -o $artifactsFolder
16 |
17 | dotnet nuget push ./$artifactsFolder/DotBPE.Rpc.*.nupkg -k $NUGET_KEY -s https://www.nuget.org
18 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Collections/TagSet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace DotBPE.Baseline.Collections
5 | {
6 | public class TagSet : HashSet
7 | {
8 | public TagSet() : base(StringComparer.OrdinalIgnoreCase)
9 | {
10 | }
11 |
12 | public TagSet(IEnumerable values)
13 | : base(StringComparer.OrdinalIgnoreCase)
14 | {
15 | foreach (string value in values)
16 | Add(value);
17 | }
18 |
19 | public new IDisposable Add(string item)
20 | {
21 | base.Add(item);
22 | return new DisposableTag(this, item);
23 | }
24 |
25 | private class DisposableTag : IDisposable
26 | {
27 | private readonly TagSet _items;
28 |
29 | public DisposableTag(TagSet items, string value)
30 | {
31 | this._items = items;
32 | Value = value;
33 | }
34 |
35 | public string Value { get; private set; }
36 |
37 | public void Dispose()
38 | {
39 | if (this._items.Contains(Value)) this._items.Remove(Value);
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/DotBPE.Baseline.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | netstandard2.0
6 | $(BaselinePackageVersion)
7 | Xuanye Wong
8 | Xuanye Wong
9 | microservice,dotnet,peach,rpc,dotbpe,baseline
10 | icon.png
11 | dotbpe.rpc is a lightweight and high performance, easy to learn rpc framework
12 | dotbpe.rpc is a lightweight and high performance, easy to learn rpc framework
13 | https://github.com/dotbpe/dotbpe
14 | https://raw.githubusercontent.com/dotbpe/dotbpe/master/LICENSE
15 | https://github.com/dotbpe/dotbpe.git
16 | git
17 |
18 | $(BaselinePackageNotes)
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Extensions/AddressExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 |
3 | namespace DotBPE.Baseline.Extensions
4 | {
5 | public static class AddressExtensions
6 | {
7 |
8 | public static string ToIPV4(this IPAddress address)
9 | {
10 | if (address.IsIPv4MappedToIPv6)
11 | {
12 | return address.MapToIPv4().ToString();
13 | }
14 |
15 | return address.ToString();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Extensions/ByteArrayExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.IO.Compression;
4 |
5 | namespace DotBPE.Baseline.Extensions
6 | {
7 | public static class ByteArrayExtensions
8 | {
9 | public static byte[] Decompress(this byte[] data, string encoding)
10 | {
11 | byte[] decompressedData = null;
12 | using (var outputStream = new MemoryStream())
13 | {
14 | using (var inputStream = new MemoryStream(data))
15 | {
16 | if (encoding == "gzip")
17 | using (var zip = new GZipStream(inputStream, CompressionMode.Decompress))
18 | {
19 | zip.CopyTo(outputStream);
20 | }
21 | else if (encoding == "deflate")
22 | using (var zip = new DeflateStream(inputStream, CompressionMode.Decompress))
23 | {
24 | zip.CopyTo(outputStream);
25 | }
26 | else
27 | throw new ArgumentException(String.Format("Unsupported encoding type \"{0}\".", encoding), "encoding");
28 | }
29 |
30 | decompressedData = outputStream.ToArray();
31 | }
32 |
33 | return decompressedData;
34 | }
35 |
36 | public static byte[] Compress(this byte[] data)
37 | {
38 | byte[] compressesData;
39 | using (var outputStream = new MemoryStream())
40 | {
41 | using (var zip = new GZipStream(outputStream, CompressionMode.Compress))
42 | {
43 | zip.Write(data, 0, data.Length);
44 | }
45 |
46 | compressesData = outputStream.ToArray();
47 | }
48 |
49 | return compressesData;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Extensions/CollectionExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 |
5 |
6 | namespace DotBPE.Baseline.Extensions
7 | {
8 | public static class CollectionExtensions
9 | {
10 | public static void RemoveAll(this ICollection list, IEnumerable items)
11 | {
12 | foreach (var i in items.ToList())
13 | list.Remove(i);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Extensions/ConcurrentQueueExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Concurrent;
2 |
3 | namespace DotBPE.Baseline.Extensions
4 | {
5 | public static class ConcurrentQueueExtensions
6 | {
7 | public static void Clear(this ConcurrentQueue queue)
8 | {
9 | T item;
10 | while (queue.TryDequeue(out item)) { }
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Extensions/DateTimeExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DotBPE.Baseline.Extensions
4 | {
5 | public static class DateTimeExtensions
6 | {
7 | private const long UnixEpochTicks = 621355968000000000;
8 | private const long UnixEpochSeconds = 62135596800;
9 | private const long UnixEpochMilliseconds = 62135596800000;
10 |
11 | public static DateTimeOffset FromUnixTimeSeconds(this long seconds)
12 | {
13 | long ticks = seconds * TimeSpan.TicksPerSecond + UnixEpochTicks;
14 | return new DateTime(ticks, DateTimeKind.Utc);
15 | }
16 |
17 | public static DateTime FromUnixTimeMilliseconds(this long milliseconds)
18 | {
19 | long ticks = milliseconds * TimeSpan.TicksPerMillisecond + UnixEpochTicks;
20 | return new DateTime(ticks, DateTimeKind.Utc);
21 | }
22 |
23 | public static long ToUnixTimeSeconds(this DateTime dateTime)
24 | {
25 | long seconds = dateTime.ToUniversalTime().Ticks / TimeSpan.TicksPerSecond;
26 | return seconds - UnixEpochSeconds;
27 | }
28 |
29 | public static long ToUnixTimeMilliseconds(this DateTime dateTime)
30 | {
31 | long milliseconds = dateTime.ToUniversalTime().Ticks / TimeSpan.TicksPerMillisecond;
32 | return milliseconds - UnixEpochMilliseconds;
33 | }
34 |
35 | public static string ToNormalString(this DateTime dateTime)
36 | {
37 | return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Extensions/ExceptionExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 |
4 | namespace DotBPE.Baseline.Extensions
5 | {
6 | public static class ExceptionExtensions
7 | {
8 | public static Exception GetInnermostException(this Exception exception)
9 | {
10 | if (exception == null)
11 | return null;
12 |
13 | Exception current = exception;
14 | while (current.InnerException != null)
15 | current = current.InnerException;
16 |
17 | return current;
18 | }
19 |
20 | public static string GetMessage(this Exception exception)
21 | {
22 | if (exception == null)
23 | return String.Empty;
24 |
25 | var aggregateException = exception as AggregateException;
26 | if (aggregateException != null)
27 | return String.Join(Environment.NewLine, aggregateException.Flatten().InnerExceptions.Where(ex => !String.IsNullOrEmpty(ex.GetInnermostException().Message)).Select(ex => ex.GetInnermostException().Message));
28 |
29 | return exception.GetInnermostException().Message;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Extensions/FileExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DotBPE.Baseline.Extensions
4 | {
5 | public static class FileExtensions
6 | {
7 | public static string GetFileExtension(string fileName)
8 | {
9 | var extension = Path.GetExtension(fileName);
10 |
11 | if (string.IsNullOrEmpty(extension))
12 | extension = fileName.Substring(fileName.LastIndexOf('.'));
13 |
14 | return extension;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Extensions/NumericExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DotBPE.Baseline.Extensions
4 | {
5 | public static class NumericExtensions
6 | {
7 |
8 | public static TimeSpan Min(this TimeSpan source, TimeSpan other)
9 | {
10 | return source.Ticks > other.Ticks ? other : source;
11 | }
12 |
13 | public static TimeSpan Max(this TimeSpan source, TimeSpan other)
14 | {
15 | return source.Ticks < other.Ticks ? other : source;
16 | }
17 |
18 | public static TimeSpan Seconds(this int secondsValue)
19 | {
20 | return TimeSpan.FromSeconds(secondsValue);
21 | }
22 | public static TimeSpan Milliseconds(this int value)
23 | {
24 | return TimeSpan.FromMilliseconds(value);
25 | }
26 |
27 | public static TimeSpan Minutes(this int value)
28 | {
29 | return TimeSpan.FromMinutes(value);
30 | }
31 |
32 | public static TimeSpan Hours(this int value)
33 | {
34 | return TimeSpan.FromHours(value);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Extensions/TaskExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using System.Runtime.CompilerServices;
3 | using System.Threading.Tasks;
4 |
5 | namespace DotBPE.Baseline.Extensions
6 | {
7 | public static class TaskExtensions
8 | {
9 | [DebuggerStepThrough]
10 | public static ConfiguredTaskAwaitable AnyContext(this Task task)
11 | {
12 | return task.ConfigureAwait(false);
13 | }
14 |
15 | [DebuggerStepThrough]
16 | public static ConfiguredTaskAwaitable AnyContext(this Task task)
17 | {
18 | return task.ConfigureAwait(false);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Utility/IConnectionMapping.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 |
4 | namespace DotBPE.Baseline.Utility
5 | {
6 | public interface IConnectionMapping
7 | {
8 | Task AddAsync(string key, string connectionId);
9 |
10 | Task> GetConnectionsAsync(string key);
11 |
12 | Task RemoveAsync(string key, string connectionId);
13 | }
14 |
15 | public static class ConnectionMappingExtensions
16 | {
17 | public const string UserIdPrefix = "u-";
18 | public const string GroupPrefix = "g-";
19 |
20 | public static Task GroupAddAsync(this IConnectionMapping map, string group, string connectionId)
21 | {
22 | return map.AddAsync(GroupPrefix + group, connectionId);
23 | }
24 |
25 | public static Task GroupRemoveAsync(this IConnectionMapping map, string group, string connectionId)
26 | {
27 | return map.RemoveAsync(GroupPrefix + group, connectionId);
28 | }
29 |
30 | public static Task> GetGroupConnectionsAsync(this IConnectionMapping map, string group)
31 | {
32 | return map.GetConnectionsAsync(GroupPrefix + group);
33 | }
34 |
35 | public static Task UserIdAddAsync(this IConnectionMapping map, string userId, string connectionId)
36 | {
37 | return map.AddAsync(UserIdPrefix + userId, connectionId);
38 | }
39 |
40 | public static Task UserIdRemoveAsync(this IConnectionMapping map, string userId, string connectionId)
41 | {
42 | return map.RemoveAsync(UserIdPrefix + userId, connectionId);
43 | }
44 |
45 | public static Task> GetUserIdConnectionsAsync(this IConnectionMapping map, string userId)
46 | {
47 | return map.GetConnectionsAsync(UserIdPrefix + userId);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/DotBPE.Baseline/Utility/SingletonBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 |
4 | namespace DotBPE.Baseline.Utility
5 | {
6 | public abstract class SingletonBase where T : class
7 | {
8 | protected SingletonBase()
9 | {
10 | }
11 |
12 | private static readonly Lazy _instance = new Lazy(() =>
13 | {
14 | var instance = (T)Activator.CreateInstance(typeof(T), true);
15 | if (instance is IInitializable)
16 | ((IInitializable)instance).Initialize();
17 |
18 | return instance;
19 | });
20 |
21 | [DebuggerBrowsable(DebuggerBrowsableState.Never)]
22 | [DebuggerNonUserCode]
23 | public static T Current => _instance.Value;
24 | }
25 |
26 | public interface IInitializable
27 | {
28 | void Initialize();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/DotBPE.BestPractice/AuditLog/AuditLogWriter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Rpc.AuditLog;
5 | using Microsoft.Extensions.Logging;
6 | using System.Threading.Tasks;
7 |
8 | namespace DotBPE.BestPractice.AuditLog
9 | {
10 | public class AuditLogWriter : IAuditLogWriter
11 | {
12 | private readonly ILogger _clientLogger;
13 | private readonly ILogger _serverLogger;
14 | public AuditLogWriter(ILoggerFactory loggerFactory)
15 | {
16 | _clientLogger = loggerFactory.CreateLogger("DotBPE.AuditLog.Client");
17 | _serverLogger = loggerFactory.CreateLogger("DotBPE.AuditLog.Server");
18 | }
19 |
20 | public Task WriteAsync(string logTxt, AuditLogType auditLogType)
21 | {
22 | var logger = auditLogType == AuditLogType.Client ? _clientLogger : _serverLogger;
23 | logger.LogInformation(logTxt);
24 |
25 | return Task.CompletedTask;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/DotBPE.BestPractice/Constants/ProtocolsConstants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DotBPE.BestPractice
6 | {
7 | public static class ProtocolsConstants
8 | {
9 | public const int RETURN_MESSAGE_NUM = 1;
10 |
11 | public static HashSet FieldMaskList = new HashSet()
12 | {
13 | "password",
14 | "idcard"
15 | };
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DotBPE.BestPractice/DotBPE.BestPractice.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | netstandard2.0
7 | $(BestPracticePackageVersion)
8 | Xuanye @ 2017-2019
9 | Xuanye Wong
10 | Xuanye Wong
11 | microservice,dotnet,peach,rpc,dotbpe
12 | icon.png
13 | dotbpe.rpc is a lightweight and high performance, easy to learn rpc framework
14 | dotbpe.rpc is a lightweight and high performance, easy to learn rpc framework
15 | https://github.com/dotbpe/dotbpe
16 | https://raw.githubusercontent.com/dotbpe/dotbpe/master/LICENSE
17 | https://github.com/dotbpe/dotbpe.git
18 | git
19 |
20 | $(BestPracticePackageNotes)
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/DotBPE.BestPractice/Exceptions/BizException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DotBPE.BestPractice
6 | {
7 |
8 | ///
9 | /// 一般业务异常
10 | ///
11 | public class BizException : Exception
12 | {
13 | public BizException()
14 | {
15 |
16 | }
17 | public BizException(int errorCode, string errorMessage) : base(errorMessage)
18 | {
19 | this.ErrorCode = errorCode;
20 | }
21 |
22 | public BizException(string errorMessage) : base(errorMessage)
23 | {
24 |
25 | }
26 |
27 | public BizException(string errorMessage, Exception inner) : base(errorMessage, inner)
28 | {
29 |
30 | }
31 |
32 |
33 | public BizException(int errorCode, string errorMessage, Exception inner) : base(errorMessage, inner)
34 | {
35 | this.ErrorCode = errorCode;
36 | }
37 |
38 | public int ErrorCode { get; }
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/DotBPE.BestPractice/HostBuilderExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Extra;
5 | using Microsoft.Extensions.Configuration;
6 | using Microsoft.Extensions.Hosting;
7 |
8 | namespace DotBPE.BestPractice
9 | {
10 | public static class HostBuilderExtensions
11 | {
12 |
13 | ///
14 | /// 组装默认的DotBPE RPC服务端
15 | ///
16 | /// IHostBuilder 实例
17 | /// 服务绑定的端口
18 | /// 是否启用审计日志
19 | ///
20 | public static IHostBuilder UseDefaultRpc(this IHostBuilder @this, int port = 5566, bool auditLog = true)
21 | {
22 | /*
23 | @this.UseRpcServer(port: port)
24 | .UseCastleDynamicProxy() //使用Castle动态代理
25 | .UseProtobufSerializer(true); //消息使用Protobuf序列化RPC通讯,并序列化JSON
26 |
27 | if (auditLog)
28 | {
29 | @this.ConfigureServices(s =>
30 | {
31 | s.AddAuditLogService();//审计服务
32 | });
33 | }
34 |
35 | //加载默认的配置文件
36 | @this.ConfigureAppConfiguration((hostContext, config) =>
37 | {
38 | config.AddJsonFile("dotbpe.json", optional: true);
39 | config.AddJsonFile($"dotbpe.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true);
40 |
41 | config.AddJsonFile("serilog.json", optional: true);
42 | config.AddJsonFile($"serilog.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true);
43 | });
44 | */
45 |
46 | return @this;
47 | }
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/DotBPE.BestPractice/TaskResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DotBPE.BestPractice
6 | {
7 | public class TaskResult
8 | {
9 | public static TaskResult Success = new TaskResult();
10 | public int Code { get; set; }
11 |
12 | public string Message { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DotBPE.BestPractice/Utility.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | namespace DotBPE.BestPractice
5 | {
6 | public static class Utility
7 | {
8 | public static string ClearSQLInject(string input)
9 | {
10 | return !string.IsNullOrEmpty(input) ? input.Replace("--", "").Replace("'", "").Replace(";", ";") : "";
11 | }
12 |
13 | public static string Base64EnCode(string input)
14 | {
15 | if (string.IsNullOrEmpty(input))
16 | {
17 | return "";
18 | }
19 | byte[] b = Encoding.UTF8.GetBytes(input);
20 | return Convert.ToBase64String(b);
21 | }
22 |
23 | public static string Base64Decode(string input)
24 | {
25 | if (string.IsNullOrEmpty(input))
26 | {
27 | return "";
28 | }
29 | byte[] b = Convert.FromBase64String(input);
30 | return Encoding.UTF8.GetString(b);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/CallContextServiceActorInterceptor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Rpc;
5 | using DotBPE.Rpc.Server;
6 | using System.Threading.Tasks;
7 |
8 | namespace DotBPE.Extra
9 | {
10 | public class CallContextServiceActorInterceptor : Interceptor
11 | {
12 |
13 | private readonly IContextAccessor _contextAccessor;
14 |
15 | public CallContextServiceActorInterceptor(IContextAccessor contextAccessor)
16 | {
17 | _contextAccessor = contextAccessor;
18 | }
19 |
20 | protected override async Task> ServiceHandle(TRequest req, InvocationContext context, ServiceMethod continuation)
21 | {
22 | if (_contextAccessor != null)
23 | {
24 | if (_contextAccessor.CallContext == null)
25 | {
26 | _contextAccessor.CallContext = new CallContext();
27 | }
28 | _contextAccessor.CallContext.AddDef();
29 | }
30 |
31 | try
32 | {
33 | return await base.ServiceHandle(req, context, continuation);
34 | }
35 | finally
36 | {
37 | _contextAccessor?.CallContext.CloseDef();
38 | }
39 | }
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/ClientInterceptor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | namespace DotBPE.Extra
5 | {
6 | public abstract class ClientInterceptor : Interceptor
7 | {
8 |
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/DotBPE.Extra.Castle.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | netstandard2.0
6 | DotBPE.Extra
7 | $(ExtraCastlePackageVersion)
8 | Xuanye @ 2017-2019
9 | Xuanye Wong
10 | Xuanye Wong
11 | microservice,dotnet,peach,rpc,dotbpe
12 | icon.png
13 | dotbpe.rpc is a lightweight and high performance, easy to learn rpc framework
14 | dotbpe.rpc is a lightweight and high performance, easy to learn rpc framework
15 | https://github.com/dotbpe/dotbpe
16 | https://raw.githubusercontent.com/dotbpe/dotbpe/master/LICENSE
17 | https://github.com/dotbpe/dotbpe.git
18 | git
19 |
20 | $(ExtraCastlePackageNotes)
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/Extensions/ClientProxyFactoryExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Rpc.Client;
5 |
6 | namespace DotBPE.Extra
7 | {
8 | public static class ClientProxyFactoryExtensions
9 | {
10 | public static IClientProxyFactory UseCastleDynamicClientProxy(this IClientProxyFactory @this)
11 | {
12 | return @this.AddDependencyServices(services => { services.AddDynamicClientProxy(); });
13 | }
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/Extensions/HostBuilderExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using Microsoft.Extensions.Hosting;
5 |
6 | namespace DotBPE.Extra
7 | {
8 | public static class HostBuilderExtensions
9 | {
10 | public static IHostBuilder UseCastleDynamicProxy(this IHostBuilder @this)
11 | {
12 | return @this.ConfigureServices(services =>
13 | {
14 | services.AddDynamicProxy();
15 | });
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/IRpcServiceInterceptor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Castle.DynamicProxy;
3 |
4 | namespace DotBPE.Extra
5 | {
6 | /*
7 | public interface IRpcServiceInterceptor
8 | {
9 | void Before(IInvocation invocation);
10 |
11 | void After(IInvocation invocation);
12 |
13 | void Exception(IInvocation invocation, Exception ex);
14 | }
15 | */
16 | }
17 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/InvocationContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Reflection;
7 | using System.Text;
8 |
9 | namespace DotBPE.Extra
10 | {
11 | public class InvocationContext
12 | {
13 | public Type ServiceType { get; set; }
14 | public MethodInfo Method { get; set; }
15 | public MethodInfo MethodInvocationTarget { get; set; }
16 |
17 | public int Timeout { get; set; }
18 | }
19 | }
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/InvokeMeta.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using System;
5 | using System.Reflection;
6 |
7 | namespace DotBPE.Extra
8 | {
9 | public class InvokeMeta
10 | {
11 | public int ServiceId { get; set; }
12 | public ushort MessageId { get; set; }
13 |
14 | public string ServiceGroupName { get; set; }
15 |
16 | public MethodInfo InvokeMethod { get; set; }
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using System.Runtime.CompilerServices;
5 |
6 | [assembly: InternalsVisibleTo("DotBPE.Extra.Castle.Tests")]
7 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/ReflectionHelper.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using Castle.DynamicProxy;
5 | using DotBPE.Rpc;
6 | using DotBPE.Rpc.Exceptions;
7 | using System;
8 | using System.Threading.Tasks;
9 |
10 | namespace DotBPE.Extra
11 | {
12 | internal class ReflectionHelper
13 | {
14 | public static (Type requestType, Type responseType) GetInvocationCallTypes(IInvocation invocation)
15 | {
16 | var returnType = invocation.Method.ReturnType;
17 | Type responseType;
18 |
19 | if (typeof(Task).IsAssignableFrom(returnType) && returnType.IsGenericType) //Task
20 | {
21 | var innerType = returnType.GetGenericArguments()[0];
22 | if (typeof(RpcResult).IsAssignableFrom(innerType) && innerType.IsGenericType)
23 | {
24 | responseType = innerType.GetGenericArguments()[0];
25 | }
26 | else
27 | {
28 | throw new RpcException("Return type must be Task>");
29 | }
30 | }
31 | else
32 | {
33 | throw new RpcException("Return type must be Task>");
34 | }
35 |
36 |
37 | return (invocation.Arguments[0].GetType(), responseType);
38 | }
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/ServiceAuditLogInterceptor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Rpc;
5 | using DotBPE.Rpc.AuditLog;
6 | using DotBPE.Rpc.Protocols;
7 | using DotBPE.Rpc.Server;
8 | using System.Diagnostics;
9 | using System.Threading.Tasks;
10 |
11 | namespace DotBPE.Extra
12 | {
13 | public class ServiceAuditLogInterceptor : Interceptor
14 | {
15 | private readonly IAuditLoggerFactory _auditLoggerFactory;
16 |
17 | public ServiceAuditLogInterceptor(IAuditLoggerFactory auditLoggerFactory = null)
18 | {
19 | _auditLoggerFactory = auditLoggerFactory;
20 | }
21 |
22 | protected override async Task> ServiceHandle(TRequest req, InvocationContext context, ServiceMethod continuation)
23 | {
24 | RpcResult result = null;
25 | var sw = new Stopwatch();
26 | sw.Start();
27 | try
28 | {
29 | result = await base.ServiceHandle(req, context, continuation);
30 | }
31 | finally
32 | {
33 | if (result == null)
34 | {
35 | result = new RpcResult() { Code = RpcStatusCodes.CODE_INTERNAL_ERROR };
36 | }
37 | }
38 | sw.Stop();
39 | if (_auditLoggerFactory != null)
40 | {
41 | var methodName = $"{context.Method.DeclaringType.Name}.{context.Method.Name}";
42 | var logger = _auditLoggerFactory.GetLogger(AuditLogType.InProc);
43 | if (logger != null)
44 | {
45 | await logger.Log(methodName, req, result?.Data, result.Code, sw.ElapsedMilliseconds, LocalRpcContext.Instance);
46 | }
47 | }
48 | return result;
49 | }
50 |
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Castle/ServiceMethod.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Rpc;
5 | using System.Threading.Tasks;
6 |
7 | namespace DotBPE.Extra
8 | {
9 | ///
10 | /// Server-side handler for unary call.
11 | ///
12 | /// Request message type for this method.
13 | /// Response message type for this method.
14 | public delegate Task> ServiceMethod(TRequest request, InvocationContext callContext)
15 | where TRequest : class
16 | where TResponse : class;
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Json/ClientProxyFactoryExtensions.cs:
--------------------------------------------------------------------------------
1 | using DotBPE.Rpc.Client;
2 |
3 | namespace DotBPE.Extra
4 | {
5 | public static class ClientProxyFactoryExtensions
6 | {
7 | public static IClientProxyFactory UseJsonNetSerializer(this IClientProxyFactory @this)
8 | {
9 | return @this.AddDependencyServices(services => { services.AddTextJsonSerializer(); });
10 |
11 | }
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Json/DotBPE.Extra.Json.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | netcoreapp3.1
7 | DotBPE.Extra
8 | $(ExtraJsonPackageVersion)
9 | Xuanye @ 2017-2019
10 | Xuanye Wong
11 | Xuanye Wong
12 | microservice,dotnet,peach,rpc,dotbpe
13 | icon.png
14 | dotbpe.rpc is a lightweight and high performance, easy to learn rpc framework
15 | dotbpe.rpc is a lightweight and high performance, easy to learn rpc framework
16 | https://github.com/dotbpe/dotbpe
17 | https://raw.githubusercontent.com/dotbpe/dotbpe/master/LICENSE
18 | https://github.com/dotbpe/dotbpe.git
19 | git
20 |
21 | $(ExtraJsonPackageNotes)
22 |
23 | Library
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Json/HostBuilderExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Hosting;
2 |
3 | namespace DotBPE.Extra
4 | {
5 | public static class HostBuilderExtensions
6 | {
7 | public static IHostBuilder UseJsonNetSerializer(this IHostBuilder @this)
8 | {
9 | return @this.ConfigureServices(services => services.AddTextJsonSerializer());
10 | }
11 |
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DotBPE.Extra.Json/JsonParser.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Xuanye Wong. All rights reserved.
2 | // Licensed under MIT license
3 |
4 | using DotBPE.Rpc;
5 | using System;
6 | using System.Text;
7 | using System.Text.Json;
8 | using System.Text.Json.Serialization;
9 |
10 |
11 | namespace DotBPE.Extra
12 | {
13 | public class TextJsonParser : IJsonParser
14 | {
15 | private static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions
16 | {
17 | #if NET5_0_OR_GREATER
18 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
19 | #else
20 | IgnoreNullValues = true,
21 | #endif
22 | PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
23 | WriteIndented = false,
24 | IgnoreReadOnlyProperties = false,
25 | AllowTrailingCommas = false
26 | };
27 |
28 | public string ToJson(object item)
29 | {
30 | return JsonSerializer.Serialize(item, JsonSerializerOptions);
31 | }
32 |
33 | public string ToJson(T item) where T : class
34 | {
35 | return JsonSerializer.Serialize