Пример #1
0
        public async Task <T> SendAndWaitAsync <T>(string methodName, MidgeParameters parameters, int timeout = 100000)
        {
            Guid commandToken = Guid.NewGuid();

            var request = CreateRequest(methodName, parameters, commandToken);

            ResponseWaiter waiter = new ResponseWaiter(commandToken);

            _waiters.TryAdd(commandToken, waiter);

            await RestClient.SendMessageAsync(request.ToString());

            await waiter.WaitAsync(timeout);

            var result = waiter.Result.ToObject <T>(_jsonSerializer);

            return(result);
        }
Пример #2
0
        public JObject CreateRequest(string methodName, MidgeParameters @params, Guid?commandToken = null)
        {
            var request = new JObject(
                new JProperty("method", methodName));

            if (@params.Count > 0)
            {
                request.Add(
                    new JProperty("params",
                                  new JObject(from param in @params select new JProperty(param.Key, param.Value))));
            }

            if (commandToken != null)
            {
                request.Add(
                    new JProperty("command_token", commandToken.Value));
            }

            return(request);
        }
Пример #3
0
        public Task SendAsync(string method, MidgeParameters parameters)
        {
            var request = CreateRequest(method, parameters);

            return(RestClient.SendMessageAsync(request.ToString()));
        }
Пример #4
0
        public void Send(string methodName, MidgeParameters parameters)
        {
            var request = CreateRequest(methodName, parameters);

            RestClient.SendMessage(request.ToString());
        }