Ejemplo n.º 1
0
        public void SayHello(global::System.Action <global::Fenix.Common.DefaultErrCode, global::Fenix.HostInfo> callback)
#endif
        {
#if !FENIX_CODEGEN
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);
            if (this.FromHostId == toHostId)
            {
                var protoCode = OpCode.SAY_HELLO_REQ;
                if (Math.Abs(protoCode) < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = Global.NetManager.GetRemotePeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { callback });
                }
                return;
            }
            Task.Run(() => {
                var msg = new SayHelloReq()
                {
                };
                var cb = new Action <byte[]>((cbData) => {
                    var cbMsg = cbData == null?new SayHelloReq.Callback():global::Fenix.Common.Utils.RpcUtil.Deserialize <SayHelloReq.Callback>(cbData);
                    callback?.Invoke(cbMsg.code, cbMsg.arg1);
                });
                this.CallRemoteMethod(OpCode.SAY_HELLO_REQ, msg, cb);
            });
#endif
        }
Ejemplo n.º 2
0
        public async Task <SayHelloReq.Callback> SayHelloAsync(global::System.Action <global::Fenix.Common.DefaultErrCode, global::Fenix.HostInfo> callback = null)
#endif
        {
#if FENIX_CODEGEN
#if !RUNTIME
            var t = new TaskCompletionSource <dynamic>();
#else
            var t = new TaskCompletionSource <SayHelloReq.Callback>();
#endif
#else
            var t        = new TaskCompletionSource <SayHelloReq.Callback>();
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);
            if (this.FromHostId == toHostId)
            {
                global::System.Action <global::Fenix.Common.DefaultErrCode, global::Fenix.HostInfo> _cb = (code, arg1) =>
                {
                    var cbMsg = new SayHelloReq.Callback();
                    cbMsg.code = code;
                    cbMsg.arg1 = arg1;
                    callback?.Invoke(cbMsg.code, cbMsg.arg1);
                    t.TrySetResult(cbMsg);
                };
                var protoCode = OpCode.SAY_HELLO_REQ;
                if (Math.Abs(protoCode) < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = Global.NetManager.GetRemotePeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { _cb, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { _cb });
                }
            }
            else
            {
                Action <SayHelloReq.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke(cbMsg.code, cbMsg.arg1);
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new SayHelloReq()
                    {
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new SayHelloReq.Callback() : global::Fenix.Common.Utils.RpcUtil.Deserialize <SayHelloReq.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(OpCode.SAY_HELLO_REQ, msg, cb);
                });
            }
#endif
            return(await t.Task);
        }