Esempio n. 1
0
        public async Task <RpcResult <AddRes> > AddAsync(AddReq req, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10005, 1);

            message.FriendlyServiceName = "Math.Add";
            message.Data = req.ToByteArray();
            var response = await base.CallInvoker.AsyncCall(message, timeOut);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <AddRes>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }

            if (response.Data == null)
            {
                result.Data = new AddRes();
            }
            else
            {
                result.Data = AddRes.Parser.ParseFrom(response.Data);
            }

            return(result);
        }
Esempio n. 2
0
        //调用委托
        private async Task <AmpMessage> ProcessPlusAsync(AmpMessage req)
        {
            AddReq request = null;

            if (req.Data == null)
            {
                request = new AddReq();
            }
            else
            {
                request = AddReq.Parser.ParseFrom(req.Data);
            }

            req.FriendlyServiceName = "MathInner.Plus";

            var result = await PlusAsync(request);

            var response = AmpMessage.CreateResponseMessage(req.ServiceId, req.MessageId);

            response.FriendlyServiceName = "MathInner.Plus";
            response.Code = result.Code;
            if (result.Data != null)
            {
                response.Data = result.Data.ToByteArray();
            }
            return(response);
        }
Esempio n. 3
0
        //同步方法
        public RpcResult <AddRes> Add(AddReq req)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10005, 1);

            message.FriendlyServiceName = "Math.Add";


            message.Data = req.ToByteArray();
            var response = base.CallInvoker.BlockingCall(message);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <AddRes>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }

            if (response.Data == null)
            {
                result.Data = new AddRes();
            }
            else
            {
                result.Data = AddRes.Parser.ParseFrom(response.Data);
            }

            return(result);
        }
Esempio n. 4
0
        //同步方法
        public AddRes Add(AddReq request)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10005, 1);

            message.Data = request.ToByteArray();
            var response = base.CallInvoker.BlockingCall(message);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            if (response.Data == null)
            {
                return(new AddRes());
            }
            return(AddRes.Parser.ParseFrom(response.Data));
        }
Esempio n. 5
0
        public async Task <AddRes> AddAsync(AddReq request, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10005, 1);

            message.Data = request.ToByteArray();
            var response = await base.CallInvoker.AsyncCall(message, timeOut);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            if (response.Data == null)
            {
                return(new AddRes());
            }
            return(AddRes.Parser.ParseFrom(response.Data));
        }
Esempio n. 6
0
//调用委托
        private async Task <AmpMessage> ProcessAddAsync(AmpMessage req)
        {
            AddReq request = null;

            if (req.Data == null)
            {
                request = new AddReq();
            }
            else
            {
                request = AddReq.Parser.ParseFrom(req.Data);
            }
            var data = await AddAsync(request);

            var response = AmpMessage.CreateResponseMessage(req.ServiceId, req.MessageId);

            response.Data = data.ToByteArray();
            return(response);
        }
Esempio n. 7
0
 //抽象方法
 public abstract Task <RpcResult <AddRes> > PlusAsync(AddReq req);
Esempio n. 8
0
//抽象方法
        public abstract Task <AddRes> AddAsync(AddReq request);