コード例 #1
0
ファイル: RpcServer.cs プロジェクト: Silvenga/Yals
        public async Task ProcessEncounter(string rpcMessageJson)
        {
            var message = JsonConvert.DeserializeObject <IRpcInputMessage>(rpcMessageJson);

            var context          = new EncounterContext(message.Method);
            var possibleHandlers = _handlerRegistrar.GetRegistrations(context);

            switch (message)
            {
            case IRpcRequest <JToken> request:
                await ProcessRequest(context, possibleHandlers.OfType <IRequestHandlerRegistration>().ToList(), request);

                break;

            case IRpcNotification <JToken> notification:
                await ProcessNotification(context, possibleHandlers.OfType <INotificationHandlerRegistration>().ToList(), notification);

                break;

            default:
                throw new ArgumentOutOfRangeException($"Don't know how to handle message of type ${message.GetType()}");
            }

            throw new NotImplementedException();
        }
コード例 #2
0
ファイル: RpcServer.cs プロジェクト: Silvenga/Yals
 private async Task ProcessNotification(EncounterContext context, IList <INotificationHandlerRegistration> possibleHandlers,
                                        IRpcNotification <JToken> message)
 {
     foreach (var handler in possibleHandlers)
     {
         await handler.HandleNotification(context, message.Parameters);
     }
 }
コード例 #3
0
ファイル: RpcServer.cs プロジェクト: Silvenga/Yals
        private async Task ProcessRequest(EncounterContext context, IList <IRequestHandlerRegistration> possibleHandlers, IRpcRequest <JToken> message)
        {
            if (!possibleHandlers.Any())
            {
                throw new Exception($"No handlers registered to respond to encounter with method '${message}'."); // TODO Update this exception type.
            }
            if (possibleHandlers.Count > 1)
            {
                throw new Exception($"Multiple handlers registered to respond to encounter with method '${message}'."); // TODO Update this exception type.
            }

            var handler = possibleHandlers.Single();
            var result  = await handler.HandleRequest(context, message.Parameters);
        }