Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add eventnext hello and actor samples
- Loading branch information
1 parent
484666d
commit 820650e
Showing
6 changed files
with
204 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,25 @@ | ||
|
||
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}") = "EventNext.Actor", "EventNext.Actor\EventNext.Actor.csproj", "{A9E35560-9423-4EEC-BECE-E849BCEB8542}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A9E35560-9423-4EEC-BECE-E849BCEB8542}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A9E35560-9423-4EEC-BECE-E849BCEB8542}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A9E35560-9423-4EEC-BECE-E849BCEB8542}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A9E35560-9423-4EEC-BECE-E849BCEB8542}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {43A6754D-F6A9-4D69-9DC8-26D22E5B0C6C} | ||
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="EventNext" Version="0.9.7.2" /> | ||
</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,88 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Collections.Generic; | ||
namespace EventNext.Actor | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
EventCenter.Default.Register(typeof(Program).Assembly); | ||
Test(); | ||
System.Threading.Thread.Sleep(-1); | ||
} | ||
|
||
static async void Test() | ||
{ | ||
var all = EventCenter.Default.Create<IAccount>(); | ||
//var all = EventCenter.Default.GetThreadContainer("t1").Create<IAccount>(); | ||
var henry = EventCenter.Default.Create<IAccount>("henry"); | ||
var ken = EventCenter.Default.Create<IAccount>("ken"); | ||
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 all.Income(k); | ||
await henry.Income(k); | ||
await ken.Income(k); | ||
} | ||
}); | ||
tasks.Add(t); | ||
|
||
t = Task.Run(async () => | ||
{ | ||
for (int k = 0; k < 100; k++) | ||
{ | ||
await all.Pay(k); | ||
await henry.Pay(k); | ||
await ken.Pay(k); | ||
} | ||
}); | ||
tasks.Add(t); | ||
} | ||
await Task.WhenAll(tasks); | ||
Console.WriteLine($"all:{await all.Value()}"); | ||
Console.WriteLine($"ken:{await ken.Value()}"); | ||
Console.WriteLine($"henry:{await henry.Value()}"); | ||
} | ||
} | ||
|
||
[Service(typeof(IAccount))] | ||
public class AccountImpl : IAccount | ||
{ | ||
|
||
private long mValue; | ||
|
||
public Task Income(int value) | ||
{ | ||
mValue += value; | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task Pay(int value) | ||
{ | ||
mValue -= value; | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task<long> Value() | ||
{ | ||
return mValue.ToTask(); | ||
} | ||
} | ||
|
||
|
||
public interface IAccount | ||
{ | ||
Task Income(int value); | ||
|
||
Task Pay(int value); | ||
|
||
Task<long> Value(); | ||
} | ||
|
||
|
||
} |
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,25 @@ | ||
|
||
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}") = "EventNext.Hello", "EventNext.Hello\EventNext.Hello.csproj", "{3174A87C-000D-4B69-8DCF-9952D3989D9B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{3174A87C-000D-4B69-8DCF-9952D3989D9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3174A87C-000D-4B69-8DCF-9952D3989D9B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3174A87C-000D-4B69-8DCF-9952D3989D9B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3174A87C-000D-4B69-8DCF-9952D3989D9B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {156FD1F9-9A2D-41BF-8AE3-D3F5853CA1E1} | ||
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="EventNext" Version="0.9.7.2" /> | ||
</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,42 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace EventNext.Hello | ||
{ | ||
class Program | ||
{ | ||
|
||
static void Main(string[] args) | ||
{ | ||
EventCenter.Default.Register(typeof(Program).Assembly); | ||
Test(); | ||
System.Threading.Thread.Sleep(-1); | ||
} | ||
static async void Test() | ||
{ | ||
var hello = EventCenter.Default.Create<IHello>(); | ||
while(true) | ||
{ | ||
Console.Write("Enter name:"); | ||
var name = Console.ReadLine(); | ||
var result = await hello.Say(name); | ||
Console.WriteLine(result); | ||
} | ||
} | ||
} | ||
[Service(typeof(IHello))] | ||
public class HelloImpl : IHello | ||
{ | ||
public Task<string> Say(string name) | ||
{ | ||
return $"hello {name} {DateTime.Now}".ToTask(); | ||
} | ||
} | ||
|
||
|
||
public interface IHello | ||
{ | ||
Task<string> Say(string name); | ||
} | ||
|
||
} |