Skip to content

Commit

Permalink
try to make UniversalCodeGenerator(Initial)
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 3, 2018
1 parent 6c78aa5 commit d16109f
Show file tree
Hide file tree
Showing 25 changed files with 5,304 additions and 124 deletions.
9 changes: 8 additions & 1 deletion MagicOnion.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sandbox.NetCoreServer", "sa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicCodeDumper", "sandbox\DynamicCodeDumper\DynamicCodeDumper.csproj", "{A2156D81-1A67-4EAC-8A74-3E459385E4A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagicOnion.Redis", "src\MagicOnion.Redis\MagicOnion.Redis.csproj", "{5637ED33-7EB8-4C30-94EE-947C58FDE363}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagicOnion.Redis", "src\MagicOnion.Redis\MagicOnion.Redis.csproj", "{5637ED33-7EB8-4C30-94EE-947C58FDE363}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagicOnion.UniversalCodeGenerator", "src\MagicOnion.UniversalCodeGenerator\MagicOnion.UniversalCodeGenerator.csproj", "{4D10B1BA-494D-4FAF-ADC8-FA5156533EDB}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Expand Down Expand Up @@ -113,6 +115,10 @@ Global
{5637ED33-7EB8-4C30-94EE-947C58FDE363}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5637ED33-7EB8-4C30-94EE-947C58FDE363}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5637ED33-7EB8-4C30-94EE-947C58FDE363}.Release|Any CPU.Build.0 = Release|Any CPU
{4D10B1BA-494D-4FAF-ADC8-FA5156533EDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D10B1BA-494D-4FAF-ADC8-FA5156533EDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D10B1BA-494D-4FAF-ADC8-FA5156533EDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D10B1BA-494D-4FAF-ADC8-FA5156533EDB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -133,6 +139,7 @@ Global
{8174DFB5-0C46-440C-A225-C3A9851C2700} = {7682EFFC-681C-4DCC-B5E7-D8449E42DAC9}
{A2156D81-1A67-4EAC-8A74-3E459385E4A0} = {7682EFFC-681C-4DCC-B5E7-D8449E42DAC9}
{5637ED33-7EB8-4C30-94EE-947C58FDE363} = {1987061F-8970-4018-8D58-6932961C9EB4}
{4D10B1BA-494D-4FAF-ADC8-FA5156533EDB} = {1987061F-8970-4018-8D58-6932961C9EB4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D5B2E7E3-B727-40A1-BE68-7BAC9B9DE2FE}
Expand Down
24 changes: 10 additions & 14 deletions sandbox/Sandbox.NetCoreServer/Hubs/ChatHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Sandbox.NetCoreServer.Hubs
{
public interface IMessageReceiver
{
Task OnReceiveMessage(string senderUser, string message);
void OnReceiveMessage(string senderUser, string message);
}

public interface IChatHub : IStreamingHub<IChatHub, IMessageReceiver>
{
Task<Nil> JoinAsync(string userName, string roomName);
Task<Nil> LeaveAsync();
Task JoinAsync(string userName, string roomName);
Task LeaveAsync();
Task SendMessageAsync(string message);
}

Expand All @@ -27,28 +27,24 @@ public class ChatHub : StreamingHubBase<IChatHub, IMessageReceiver>, IChatHub
string userName;
IGroup room;

// return Task<T> wait server completed.
public async Task<Nil> JoinAsync(string userName, string roomName)
public async Task JoinAsync(string userName, string roomName)
{
this.userName = userName;
this.room = await Group.AddAsync("InMemoryRoom:" + roomName, this.Context);

return Nil.Default;
}

// return Task is fire and forget(does not wait server completed).
public async Task SendMessageAsync(string message)
public Task SendMessageAsync(string message)
{
// broadcast to connected group(same roomname members).
await Broadcast(room).OnReceiveMessage(this.userName, message);
Broadcast(room).OnReceiveMessage(this.userName, message);

return Task.CompletedTask;
}

public async Task<Nil> LeaveAsync()
public async Task LeaveAsync()
{
await BroadcastExceptSelf(room).OnReceiveMessage(userName, "SYSTEM_MESSAGE_LEAVE_USER");
BroadcastExceptSelf(room).OnReceiveMessage(userName, "SYSTEM_MESSAGE_LEAVE_USER");
await room.RemoveAsync(this.Context);

return Nil.Default;
}

protected override ValueTask OnConnecting()
Expand Down
6 changes: 2 additions & 4 deletions sandbox/Sandbox.NetCoreServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ public async Task Start(string user, string room)
var channel = new Channel("localhost:12345", ChannelCredentials.Insecure);

var client = StreamingHubClient.Connect<IChatHub, IMessageReceiver>(channel, this);
// RegisterDisconnect(client);
RegisterDisconnect(client);
try
{


await client.JoinAsync(user, room);

await client.SendMessageAsync("Who");
Expand Down Expand Up @@ -108,7 +106,7 @@ async void RegisterDisconnect(IChatHub client)

#pragma warning disable CS1998

public async Task OnReceiveMessage(string senderUser, string message)
public void OnReceiveMessage(string senderUser, string message)
{
Console.WriteLine(senderUser + ":" + message);
}
Expand Down
4 changes: 4 additions & 0 deletions src/MagicOnion.CodeGenerator/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<assemblyIdentity name="System.Composition.Hosting" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.30.0" newVersion="1.0.30.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Dataflow" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.6.0.0" newVersion="4.6.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Loading

0 comments on commit d16109f

Please sign in to comment.