Example #1
0
        public void CLIENT_API_api_test(IMessage msg, Action <IMessage> cb)
        {
            var _msg = (ApiTestNtf)msg;

            this.ApiTest(_msg.uid, (code) =>
            {
                var cbMsg  = new ApiTestNtf.Callback();
                cbMsg.code = code;
                cb.Invoke(cbMsg);
            });
        }
Example #2
0
        public async Task <ApiTestNtf.Callback> client_on_api_test_async(global::System.String uid, global::System.Action <global::Shared.Protocol.ErrCode> callback = null)
        {
            var t        = new TaskCompletionSource <ApiTestNtf.Callback>();
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                global::System.Action <global::Shared.Protocol.ErrCode> _cb = (code) =>
                {
                    var cbMsg = new ApiTestNtf.Callback();
                    cbMsg.code = code;
                    callback?.Invoke(cbMsg.code);
                    t.TrySetResult(cbMsg);
                };
                var protoCode = ProtocolCode.API_TEST_NTF;
                if (protoCode < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = Global.NetManager.GetPeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { uid, _cb, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { uid, _cb });
                }
            }
            else
            {
                Action <ApiTestNtf.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke(cbMsg.code);
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new ApiTestNtf()
                    {
                        uid = uid
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new ApiTestNtf.Callback() : RpcUtil.Deserialize <ApiTestNtf.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(ProtocolCode.API_TEST_NTF, msg, cb);
                });
            }
            return(await t.Task);
        }