Ejemplo n.º 1
0
        public static async Task <IDictionary <string, object> > RpcAsync(this TMClient @this, string methodName, params object[] args)
        {
            var rpcRequest = new TMJsonRequest();

            var encodedArgs = new List <object>();

            foreach (var a in args)
            {
                var ea = TMEncoding.Instance.Encode(a);
                encodedArgs.Add(ea);
            }

            Dictionary <string, object> body = new Dictionary <string, object>()
            {
                { "args", encodedArgs },
            };

            rpcRequest.Url  = string.Format("/rpc/{0}", methodName);
            rpcRequest.Body = body;
            var json = await @this.SendAsync(rpcRequest);

            var result = json.Results;

            return(result);
        }
Ejemplo n.º 2
0
        public static async Task <T> RpcWithChoiceAsync <T>(this TMClient @this, string methodName, IEnumerable <T> choices, bool canBeSkip = false, int timeLimitForDefaultResult = 15000)
        {
            var rpcRequest = new TMJsonRequest();

            var encodedArgs = new List <object>();

            object[] args = new object[] { choices, canBeSkip, timeLimitForDefaultResult };
            foreach (var a in args)
            {
                var ea = TMEncoding.Instance.Encode(a);
                encodedArgs.Add(ea);
            }

            Dictionary <string, object> body = new Dictionary <string, object>()
            {
                { "args", encodedArgs },
            };

            rpcRequest.Url  = string.Format("/rpc/{0}", methodName);
            rpcRequest.Body = body;
            if (timeLimitForDefaultResult == 0)
            {
                timeLimitForDefaultResult = 15000;
            }
            var json = await @this.SendAsync(rpcRequest, true, timeLimitForDefaultResult);

            var result = json.Results;

            if (result == null)
            {
                if (!canBeSkip)
                {
                    return(choices.PickRandom());
                }
            }
            var deocdedObj = AVDecoder.Instance.Decode(result);
            T   rtn        = Conversion.To <T>(deocdedObj);

            return(rtn);
        }
Ejemplo n.º 3
0
        public static Task RpcClientAsync(this TMRoom @this, TMClient client, string methodName, params object[] args)
        {
            var rpcMethodName = $"TMRoom_{@this.Id}_{methodName}";

            return(client.RpcAsync(rpcMethodName, args));
        }