-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4343f2
commit 2708fa7
Showing
84 changed files
with
3,696 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BeetleX.XRPC" Version="0.7.3.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using BeetleX.XRPC.Clients; | ||
using BeetleX.XRPC.Packets; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Client | ||
{ | ||
class Program | ||
{ | ||
static XRPCClient client; | ||
static IAmount henry, ken, none; | ||
static void Main(string[] args) | ||
{ | ||
client = new XRPCClient("localhost", 9090); | ||
client.Options.ParameterFormater = new JsonPacket();//default messagepack | ||
henry = client.Create<IAmount>("henry"); | ||
ken = client.Create<IAmount>("ken"); | ||
Test(); | ||
Console.Read(); | ||
} | ||
|
||
static async void Test() | ||
{ | ||
await Income(); | ||
await Pay(); | ||
Console.WriteLine($"henry actor:{await henry.GetValue()} | ken actor:{await ken.GetValue()}"); | ||
} | ||
|
||
static async Task Income() | ||
{ | ||
List<Task> tasks = new List<Task>(); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
var t = Task.Run(async () => | ||
{ | ||
for (int k = 0; k < 100; k++) | ||
{ | ||
await henry.Income(10); | ||
await ken.Income(10); | ||
} | ||
}); | ||
tasks.Add(t); | ||
} | ||
await Task.WhenAll(tasks.ToArray()); | ||
|
||
} | ||
|
||
static async Task Pay() | ||
{ | ||
List<Task> tasks = new List<Task>(); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
var t = Task.Run(async () => | ||
{ | ||
for (int k = 0; k < 100; k++) | ||
{ | ||
await henry.Pay(10); | ||
await ken.Pay(10); | ||
} | ||
}); | ||
tasks.Add(t); | ||
} | ||
await Task.WhenAll(tasks); | ||
} | ||
} | ||
|
||
public interface IAmount | ||
{ | ||
Task Income(int value); | ||
Task Pay(int value); | ||
Task<int> GetValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using BeetleX.XRPC.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
using System; | ||
using System.Threading.Tasks; | ||
using EventNext; | ||
using BeetleX.XRPC.Packets; | ||
|
||
namespace Server | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var builder = new HostBuilder() | ||
.ConfigureServices((hostContext, services) => | ||
{ | ||
services.UseXRPC(s => | ||
{ | ||
s.ServerOptions.LogLevel = BeetleX.EventArgs.LogType.Warring; | ||
s.ServerOptions.DefaultListen.Port = 9090; | ||
s.RPCOptions.ParameterFormater = new JsonPacket();//default messagepack | ||
}, | ||
typeof(Program).Assembly); | ||
}); | ||
builder.Build().Run(); | ||
} | ||
} | ||
|
||
public interface IAmount | ||
{ | ||
Task Income(int value); | ||
Task Pay(int value); | ||
Task<int> GetValue(); | ||
} | ||
[Service(typeof(IAmount))] | ||
public class AmountImpl : IAmount | ||
{ | ||
|
||
private int mAmount; | ||
|
||
public Task<int> GetValue() | ||
{ | ||
return mAmount.ToTask(); | ||
} | ||
|
||
public Task Income(int value) | ||
{ | ||
mAmount -= value; | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task Pay(int value) | ||
{ | ||
mAmount += value; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BeetleX.XRPC.Hosting" Version="0.7.3.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.705 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{750A98AD-7063-46AF-9272-42390A6491C0}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{4CC52F27-DBF2-4180-8D96-335A0D3E1C09}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{750A98AD-7063-46AF-9272-42390A6491C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{750A98AD-7063-46AF-9272-42390A6491C0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{750A98AD-7063-46AF-9272-42390A6491C0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{750A98AD-7063-46AF-9272-42390A6491C0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{4CC52F27-DBF2-4180-8D96-335A0D3E1C09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4CC52F27-DBF2-4180-8D96-335A0D3E1C09}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4CC52F27-DBF2-4180-8D96-335A0D3E1C09}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4CC52F27-DBF2-4180-8D96-335A0D3E1C09}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {9BA915BD-D999-4343-B741-0761F31F3223} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BeetleX.XRPC" Version="0.7.3.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using BeetleX.XRPC.Clients; | ||
using BeetleX.XRPC.Packets; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Client | ||
{ | ||
class Program | ||
{ | ||
static XRPCClient client; | ||
static IHello hello; | ||
static void Main(string[] args) | ||
{ | ||
client = new XRPCClient("localhost", 9090); | ||
client.Options.ParameterFormater = new JsonPacket();//default messagepack | ||
hello = client.Create<IHello>(); | ||
while(true) | ||
{ | ||
Console.Write("Enter you name:"); | ||
var name = Console.ReadLine(); | ||
var task = hello.Hello(name); | ||
task.Wait(); | ||
Console.WriteLine(task.Result); | ||
} | ||
Console.Read(); | ||
} | ||
} | ||
|
||
public interface IHello | ||
{ | ||
Task<string> Hello(string name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using BeetleX.EventArgs; | ||
using BeetleX.XRPC.Hosting; | ||
using BeetleX.XRPC.Packets; | ||
using EventNext; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Server | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var builder = new HostBuilder() | ||
.ConfigureServices((hostContext, services) => | ||
{ | ||
services.AddSingleton(new User { Name = "BeetleX" }); | ||
services.UseXRPC(s => | ||
{ | ||
s.ServerOptions.LogLevel = BeetleX.EventArgs.LogType.Trace; | ||
s.ServerOptions.DefaultListen.Port = 9090; | ||
s.RPCOptions.ParameterFormater = new JsonPacket();//default messagepack | ||
}, | ||
typeof(Program).Assembly); | ||
}); | ||
builder.Build().Run(); | ||
} | ||
} | ||
|
||
public interface IHello | ||
{ | ||
Task<string> Hello(string name); | ||
} | ||
|
||
[Service(typeof(IHello))] | ||
public class HelloImpl : IHello | ||
{ | ||
public HelloImpl(BeetleX.XRPC.XRPCServer server, User user) | ||
{ | ||
mServer = server; | ||
mUser = user; | ||
} | ||
|
||
private BeetleX.XRPC.XRPCServer mServer; | ||
|
||
private User mUser; | ||
|
||
public Task<string> Hello(string name) | ||
{ | ||
return $"hello {name} {DateTime.Now}\r\n{mServer}\r\n{mUser.Name}".ToTask(); | ||
} | ||
} | ||
|
||
|
||
public class User | ||
{ | ||
|
||
public string Name { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BeetleX.XRPC.Hosting" Version="0.7.3.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.705 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{B2C1FB4C-3082-448A-BB13-AB1E056AE7AB}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{F42DE94D-03D2-4146-A918-8E677802BDE2}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{B2C1FB4C-3082-448A-BB13-AB1E056AE7AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B2C1FB4C-3082-448A-BB13-AB1E056AE7AB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B2C1FB4C-3082-448A-BB13-AB1E056AE7AB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B2C1FB4C-3082-448A-BB13-AB1E056AE7AB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{F42DE94D-03D2-4146-A918-8E677802BDE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F42DE94D-03D2-4146-A918-8E677802BDE2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F42DE94D-03D2-4146-A918-8E677802BDE2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F42DE94D-03D2-4146-A918-8E677802BDE2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {5B8C9CC2-FBF1-4130-AB28-2747109FA907} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BeetleX.XRPC" Version="0.7.3.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using BeetleX.XRPC.Clients; | ||
using BeetleX.XRPC.Packets; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Client | ||
{ | ||
class Program | ||
{ | ||
static XRPCClient client; | ||
static IHello hello; | ||
static void Main(string[] args) | ||
{ | ||
client = new XRPCClient("localhost", 9090); | ||
client.Options.ParameterFormater = new JsonPacket();//default messagepack | ||
hello = client.Create<IHello>(); | ||
while(true) | ||
{ | ||
Console.Write("Enter you name:"); | ||
var name = Console.ReadLine(); | ||
var task = hello.Hello(name); | ||
task.Wait(); | ||
Console.WriteLine(task.Result); | ||
} | ||
Console.Read(); | ||
} | ||
} | ||
|
||
public interface IHello | ||
{ | ||
Task<string> Hello(string name); | ||
} | ||
} |
Oops, something went wrong.