private async void InvokeController(ControllerCenter.HandlerItem handler, RPCPacket packet) { RPCPacket response = new RPCPacket(); try { packet.LoadParameters(handler.Parameters); var result = handler.Handler.Execute(handler.Controller, packet.Data); if (result is Task task) { await task; } var data = handler.GetValue(result); if (data != null) { response.Data = new object[] { data } } ; } catch (Exception e_) { response.Status = (short)StatusCode.INNER_ERROR; response.Data = new string[] { e_.Message }; } packet.ReplyPacket(response); }
protected virtual void OnProcess(RPCPacket response) { var awaitItem = mAwaiterFactory.GetItem(response.ID); if (awaitItem != null) { response.ResultType = awaitItem.ResultType; try { response.LoadParameters(response.ResultType); } catch (Exception e_) { response.Status = (short)StatusCode.INNER_ERROR; response.Data = new object[] { $"{e_.Message}@{e_.StackTrace}" }; } mAwaiterFactory.Completed(awaitItem, response); } else { try { if (response.Url.IndexOf(DELEGATE_TAG, StringComparison.OrdinalIgnoreCase) == 0) { InvokeDelegate(response); return; } //notfound; var item = Controllers.GetHandler(response.Url); if (item != null) { InvokeController(item, response); } else { if (Receive != null) { Receive(this, response); } else { if (response.NeedReply) { var result = new RPCPacket(); result.Status = (short)StatusCode.NOT_SUPPORT; result.Data = new object[] { $"{response.Url} not found!" }; response.ReplyPacket(result); } } } } catch (Exception e_) { OnError(response.Client, new ClientErrorArgs { Error = e_, Message = $"Packet process event error {e_.Message}" }); } } }