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); }
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); }
public Task SendAsync(string method, MidgeParameters parameters) { var request = CreateRequest(method, parameters); return(RestClient.SendMessageAsync(request.ToString())); }
public void Send(string methodName, MidgeParameters parameters) { var request = CreateRequest(methodName, parameters); RestClient.SendMessage(request.ToString()); }