Initial Client/Server Communication

#1
Followed the MagicOnion quickstart guide, borrowing code from the chat sample app to get something working
This commit is contained in:
hyperion51 2020-02-26 17:48:40 +00:00
commit a0c8dbee72
493 changed files with 57790 additions and 3 deletions

View file

@ -0,0 +1,397 @@
// <auto-generated />
#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 219
#pragma warning disable 168
namespace MagicOnion
{
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::MagicOnion;
using global::MagicOnion.Client;
public static partial class MagicOnionInitializer
{
static bool isRegistered = false;
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void Register()
{
if(isRegistered) return;
isRegistered = true;
MagicOnionClientRegistry<ChatApp.Shared.Services.IChatService>.Register((x, y, z) => new ChatApp.Shared.Services.ChatServiceClient(x, y, z));
StreamingHubClientRegistry<ChatApp.Shared.Hubs.IChatHub, ChatApp.Shared.Hubs.IChatHubReceiver>.Register((a, _, b, c, d, e) => new ChatApp.Shared.Hubs.ChatHubClient(a, b, c, d, e));
}
}
}
#pragma warning restore 168
#pragma warning restore 219
#pragma warning restore 414
#pragma warning restore 612
#pragma warning restore 618
#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 219
#pragma warning disable 168
namespace MagicOnion.Resolvers
{
using System;
using MessagePack;
public class MagicOnionResolver : global::MessagePack.IFormatterResolver
{
public static readonly global::MessagePack.IFormatterResolver Instance = new MagicOnionResolver();
MagicOnionResolver()
{
}
public global::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
{
return FormatterCache<T>.formatter;
}
static class FormatterCache<T>
{
public static readonly global::MessagePack.Formatters.IMessagePackFormatter<T> formatter;
static FormatterCache()
{
var f = MagicOnionResolverGetFormatterHelper.GetFormatter(typeof(T));
if (f != null)
{
formatter = (global::MessagePack.Formatters.IMessagePackFormatter<T>)f;
}
}
}
}
internal static class MagicOnionResolverGetFormatterHelper
{
static readonly global::System.Collections.Generic.Dictionary<Type, int> lookup;
static MagicOnionResolverGetFormatterHelper()
{
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(3)
{
{typeof(global::MagicOnion.DynamicArgumentTuple<global::System.Collections.Generic.List<int>, global::System.Collections.Generic.Dictionary<int, string>>), 0 },
{typeof(global::System.Collections.Generic.Dictionary<int, string>), 1 },
{typeof(global::System.Collections.Generic.List<int>), 2 },
};
}
internal static object GetFormatter(Type t)
{
int key;
if (!lookup.TryGetValue(t, out key))
{
return null;
}
switch (key)
{
case 0: return new global::MagicOnion.DynamicArgumentTupleFormatter<global::System.Collections.Generic.List<int>, global::System.Collections.Generic.Dictionary<int, string>>(default(global::System.Collections.Generic.List<int>), default(global::System.Collections.Generic.Dictionary<int, string>));
case 1: return new global::MessagePack.Formatters.DictionaryFormatter<int, string>();
case 2: return new global::MessagePack.Formatters.ListFormatter<int>();
default: return null;
}
}
}
}
#pragma warning restore 168
#pragma warning restore 219
#pragma warning restore 414
#pragma warning restore 612
#pragma warning restore 618
#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 219
#pragma warning disable 168
namespace ChatApp.Shared.Services {
using System;
using MagicOnion;
using MagicOnion.Client;
using Grpc.Core;
using MessagePack;
[Ignore]
public class ChatServiceClient : MagicOnionClientBase<global::ChatApp.Shared.Services.IChatService>, global::ChatApp.Shared.Services.IChatService
{
static readonly Method<byte[], byte[]> GenerateExceptionMethod;
static readonly Func<RequestContext, ResponseContext> GenerateExceptionDelegate;
static readonly Method<byte[], byte[]> SendReportAsyncMethod;
static readonly Func<RequestContext, ResponseContext> SendReportAsyncDelegate;
static ChatServiceClient()
{
GenerateExceptionMethod = new Method<byte[], byte[]>(MethodType.Unary, "IChatService", "GenerateException", MagicOnionMarshallers.ThroughMarshaller, MagicOnionMarshallers.ThroughMarshaller);
GenerateExceptionDelegate = _GenerateException;
SendReportAsyncMethod = new Method<byte[], byte[]>(MethodType.Unary, "IChatService", "SendReportAsync", MagicOnionMarshallers.ThroughMarshaller, MagicOnionMarshallers.ThroughMarshaller);
SendReportAsyncDelegate = _SendReportAsync;
}
ChatServiceClient()
{
}
public ChatServiceClient(CallInvoker callInvoker, MessagePackSerializerOptions serializerOptions, IClientFilter[] filters)
: base(callInvoker, serializerOptions, filters)
{
}
protected override MagicOnionClientBase<IChatService> Clone()
{
var clone = new ChatServiceClient();
clone.host = this.host;
clone.option = this.option;
clone.callInvoker = this.callInvoker;
clone.serializerOptions = this.serializerOptions;
clone.filters = filters;
return clone;
}
public new IChatService WithHeaders(Metadata headers)
{
return base.WithHeaders(headers);
}
public new IChatService WithCancellationToken(System.Threading.CancellationToken cancellationToken)
{
return base.WithCancellationToken(cancellationToken);
}
public new IChatService WithDeadline(System.DateTime deadline)
{
return base.WithDeadline(deadline);
}
public new IChatService WithHost(string host)
{
return base.WithHost(host);
}
public new IChatService WithOptions(CallOptions option)
{
return base.WithOptions(option);
}
static ResponseContext _GenerateException(RequestContext __context)
{
return CreateResponseContext<string, Nil>(__context, GenerateExceptionMethod);
}
public global::MagicOnion.UnaryResult<Nil> GenerateException(string message)
{
return InvokeAsync<string, Nil>("IChatService/GenerateException", message, GenerateExceptionDelegate);
}
static ResponseContext _SendReportAsync(RequestContext __context)
{
return CreateResponseContext<string, Nil>(__context, SendReportAsyncMethod);
}
public global::MagicOnion.UnaryResult<Nil> SendReportAsync(string message)
{
return InvokeAsync<string, Nil>("IChatService/SendReportAsync", message, SendReportAsyncDelegate);
}
}
}
#pragma warning restore 168
#pragma warning restore 219
#pragma warning restore 414
#pragma warning restore 612
#pragma warning restore 618
#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 219
#pragma warning disable 168
namespace ChatApp.Shared.Hubs {
using Grpc.Core;
using Grpc.Core.Logging;
using MagicOnion;
using MagicOnion.Client;
using MessagePack;
using System;
using System.Threading.Tasks;
[Ignore]
public class ChatHubClient : StreamingHubClientBase<global::ChatApp.Shared.Hubs.IChatHub, global::ChatApp.Shared.Hubs.IChatHubReceiver>, global::ChatApp.Shared.Hubs.IChatHub
{
static readonly Method<byte[], byte[]> method = new Method<byte[], byte[]>(MethodType.DuplexStreaming, "IChatHub", "Connect", MagicOnionMarshallers.ThroughMarshaller, MagicOnionMarshallers.ThroughMarshaller);
protected override Method<byte[], byte[]> DuplexStreamingAsyncMethod { get { return method; } }
readonly global::ChatApp.Shared.Hubs.IChatHub __fireAndForgetClient;
public ChatHubClient(CallInvoker callInvoker, string host, CallOptions option, MessagePackSerializerOptions serializerOptions, ILogger logger)
: base(callInvoker, host, option, serializerOptions, logger)
{
this.__fireAndForgetClient = new FireAndForgetClient(this);
}
public global::ChatApp.Shared.Hubs.IChatHub FireAndForget()
{
return __fireAndForgetClient;
}
protected override void OnBroadcastEvent(int methodId, ArraySegment<byte> data)
{
switch (methodId)
{
case -1297457280: // OnJoin
{
var result = MessagePackSerializer.Deserialize<string>(data, serializerOptions);
receiver.OnJoin(result); break;
}
case 532410095: // OnLeave
{
var result = MessagePackSerializer.Deserialize<string>(data, serializerOptions);
receiver.OnLeave(result); break;
}
case -552695459: // OnSendMessage
{
var result = MessagePackSerializer.Deserialize<global::ChatApp.Shared.MessagePackObjects.MessageResponse>(data, serializerOptions);
receiver.OnSendMessage(result); break;
}
default:
break;
}
}
protected override void OnResponseEvent(int methodId, object taskCompletionSource, ArraySegment<byte> data)
{
switch (methodId)
{
case -733403293: // JoinAsync
{
var result = MessagePackSerializer.Deserialize<Nil>(data, serializerOptions);
((TaskCompletionSource<Nil>)taskCompletionSource).TrySetResult(result);
break;
}
case 1368362116: // LeaveAsync
{
var result = MessagePackSerializer.Deserialize<Nil>(data, serializerOptions);
((TaskCompletionSource<Nil>)taskCompletionSource).TrySetResult(result);
break;
}
case -601690414: // SendMessageAsync
{
var result = MessagePackSerializer.Deserialize<Nil>(data, serializerOptions);
((TaskCompletionSource<Nil>)taskCompletionSource).TrySetResult(result);
break;
}
case 517938971: // GenerateException
{
var result = MessagePackSerializer.Deserialize<Nil>(data, serializerOptions);
((TaskCompletionSource<Nil>)taskCompletionSource).TrySetResult(result);
break;
}
case -852153394: // SampleMethod
{
var result = MessagePackSerializer.Deserialize<Nil>(data, serializerOptions);
((TaskCompletionSource<Nil>)taskCompletionSource).TrySetResult(result);
break;
}
default:
break;
}
}
public global::System.Threading.Tasks.Task JoinAsync(global::ChatApp.Shared.MessagePackObjects.JoinRequest request)
{
return WriteMessageWithResponseAsync<global::ChatApp.Shared.MessagePackObjects.JoinRequest, Nil>(-733403293, request);
}
public global::System.Threading.Tasks.Task LeaveAsync()
{
return WriteMessageWithResponseAsync<Nil, Nil>(1368362116, Nil.Default);
}
public global::System.Threading.Tasks.Task SendMessageAsync(string message)
{
return WriteMessageWithResponseAsync<string, Nil>(-601690414, message);
}
public global::System.Threading.Tasks.Task GenerateException(string message)
{
return WriteMessageWithResponseAsync<string, Nil>(517938971, message);
}
public global::System.Threading.Tasks.Task SampleMethod(global::System.Collections.Generic.List<int> sampleList, global::System.Collections.Generic.Dictionary<int, string> sampleDictionary)
{
return WriteMessageWithResponseAsync<DynamicArgumentTuple<global::System.Collections.Generic.List<int>, global::System.Collections.Generic.Dictionary<int, string>>, Nil>(-852153394, new DynamicArgumentTuple<global::System.Collections.Generic.List<int>, global::System.Collections.Generic.Dictionary<int, string>>(sampleList, sampleDictionary));
}
class FireAndForgetClient : global::ChatApp.Shared.Hubs.IChatHub
{
readonly ChatHubClient __parent;
public FireAndForgetClient(ChatHubClient parentClient)
{
this.__parent = parentClient;
}
public global::ChatApp.Shared.Hubs.IChatHub FireAndForget()
{
throw new NotSupportedException();
}
public Task DisposeAsync()
{
throw new NotSupportedException();
}
public Task WaitForDisconnect()
{
throw new NotSupportedException();
}
public global::System.Threading.Tasks.Task JoinAsync(global::ChatApp.Shared.MessagePackObjects.JoinRequest request)
{
return __parent.WriteMessageAsync<global::ChatApp.Shared.MessagePackObjects.JoinRequest>(-733403293, request);
}
public global::System.Threading.Tasks.Task LeaveAsync()
{
return __parent.WriteMessageAsync<Nil>(1368362116, Nil.Default);
}
public global::System.Threading.Tasks.Task SendMessageAsync(string message)
{
return __parent.WriteMessageAsync<string>(-601690414, message);
}
public global::System.Threading.Tasks.Task GenerateException(string message)
{
return __parent.WriteMessageAsync<string>(517938971, message);
}
public global::System.Threading.Tasks.Task SampleMethod(global::System.Collections.Generic.List<int> sampleList, global::System.Collections.Generic.Dictionary<int, string> sampleDictionary)
{
return __parent.WriteMessageAsync<DynamicArgumentTuple<global::System.Collections.Generic.List<int>, global::System.Collections.Generic.Dictionary<int, string>>>(-852153394, new DynamicArgumentTuple<global::System.Collections.Generic.List<int>, global::System.Collections.Generic.Dictionary<int, string>>(sampleList, sampleDictionary));
}
}
}
}
#pragma warning restore 168
#pragma warning restore 219
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8101cc28afd16634bb4bbd1bff64cf99
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,223 @@
// <auto-generated>
// THIS (.cs) FILE IS GENERATED BY MPC(MessagePack-CSharp). DO NOT CHANGE IT.
// </auto-generated>
#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 168
#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1312 // Variable names should begin with lower-case letter
#pragma warning disable SA1649 // File name should match first type name
namespace MessagePack.Resolvers
{
using System;
using System.Buffers;
using MessagePack;
public class GeneratedResolver : global::MessagePack.IFormatterResolver
{
public static readonly global::MessagePack.IFormatterResolver Instance = new GeneratedResolver();
private GeneratedResolver()
{
}
public global::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
{
return FormatterCache<T>.Formatter;
}
private static class FormatterCache<T>
{
internal static readonly global::MessagePack.Formatters.IMessagePackFormatter<T> Formatter;
static FormatterCache()
{
var f = GeneratedResolverGetFormatterHelper.GetFormatter(typeof(T));
if (f != null)
{
Formatter = (global::MessagePack.Formatters.IMessagePackFormatter<T>)f;
}
}
}
}
internal static class GeneratedResolverGetFormatterHelper
{
private static readonly global::System.Collections.Generic.Dictionary<Type, int> lookup;
static GeneratedResolverGetFormatterHelper()
{
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(2)
{
{ typeof(global::ChatApp.Shared.MessagePackObjects.JoinRequest), 0 },
{ typeof(global::ChatApp.Shared.MessagePackObjects.MessageResponse), 1 },
};
}
internal static object GetFormatter(Type t)
{
int key;
if (!lookup.TryGetValue(t, out key))
{
return null;
}
switch (key)
{
case 0: return new MessagePack.Formatters.ChatApp.Shared.MessagePackObjects.JoinRequestFormatter();
case 1: return new MessagePack.Formatters.ChatApp.Shared.MessagePackObjects.MessageResponseFormatter();
default: return null;
}
}
}
}
#pragma warning restore 168
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612
#pragma warning restore SA1312 // Variable names should begin with lower-case letter
#pragma warning restore SA1200 // Using directives should be placed correctly
#pragma warning restore SA1649 // File name should match first type name
// <auto-generated>
// THIS (.cs) FILE IS GENERATED BY MPC(MessagePack-CSharp). DO NOT CHANGE IT.
// </auto-generated>
#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 168
#pragma warning disable SA1129 // Do not use default value type constructor
#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1309 // Field names should not begin with underscore
#pragma warning disable SA1312 // Variable names should begin with lower-case letter
#pragma warning disable SA1403 // File may only contain a single namespace
#pragma warning disable SA1649 // File name should match first type name
namespace MessagePack.Formatters.ChatApp.Shared.MessagePackObjects
{
using System;
using System.Buffers;
using MessagePack;
public sealed class JoinRequestFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::ChatApp.Shared.MessagePackObjects.JoinRequest>
{
public void Serialize(ref MessagePackWriter writer, global::ChatApp.Shared.MessagePackObjects.JoinRequest value, global::MessagePack.MessagePackSerializerOptions options)
{
IFormatterResolver formatterResolver = options.Resolver;
writer.WriteArrayHeader(2);
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.RoomName, options);
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.UserName, options);
}
public global::ChatApp.Shared.MessagePackObjects.JoinRequest Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
{
if (reader.TryReadNil())
{
throw new InvalidOperationException("typecode is null, struct not supported");
}
IFormatterResolver formatterResolver = options.Resolver;
var length = reader.ReadArrayHeader();
var __RoomName__ = default(string);
var __UserName__ = default(string);
for (int i = 0; i < length; i++)
{
var key = i;
switch (key)
{
case 0:
__RoomName__ = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
break;
case 1:
__UserName__ = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
break;
default:
reader.Skip();
break;
}
}
var ____result = new global::ChatApp.Shared.MessagePackObjects.JoinRequest();
____result.RoomName = __RoomName__;
____result.UserName = __UserName__;
return ____result;
}
}
public sealed class MessageResponseFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::ChatApp.Shared.MessagePackObjects.MessageResponse>
{
public void Serialize(ref MessagePackWriter writer, global::ChatApp.Shared.MessagePackObjects.MessageResponse value, global::MessagePack.MessagePackSerializerOptions options)
{
IFormatterResolver formatterResolver = options.Resolver;
writer.WriteArrayHeader(2);
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.UserName, options);
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.Message, options);
}
public global::ChatApp.Shared.MessagePackObjects.MessageResponse Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
{
if (reader.TryReadNil())
{
throw new InvalidOperationException("typecode is null, struct not supported");
}
IFormatterResolver formatterResolver = options.Resolver;
var length = reader.ReadArrayHeader();
var __UserName__ = default(string);
var __Message__ = default(string);
for (int i = 0; i < length; i++)
{
var key = i;
switch (key)
{
case 0:
__UserName__ = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
break;
case 1:
__Message__ = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
break;
default:
reader.Skip();
break;
}
}
var ____result = new global::ChatApp.Shared.MessagePackObjects.MessageResponse();
____result.UserName = __UserName__;
____result.Message = __Message__;
return ____result;
}
}
}
#pragma warning restore 168
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612
#pragma warning restore SA1129 // Do not use default value type constructor
#pragma warning restore SA1200 // Using directives should be placed correctly
#pragma warning restore SA1309 // Field names should not begin with underscore
#pragma warning restore SA1312 // Variable names should begin with lower-case letter
#pragma warning restore SA1403 // File may only contain a single namespace
#pragma warning restore SA1649 // File name should match first type name

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 06622dddf17e3734bb11f4133d2427d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: