/// <summary> /// Tries to send the <see cref="RequestEnvelope"/> message to the network. /// Returns an <see cref="IFuture{ResponseEnvelope}"/> when completed. /// </summary> /// <param name="envelope">Envolope to send.</param> /// <returns>An awaitable future result.</returns> public IFuture <ResponseEnvelope> SendRequestAsResponseFuture <TFutureType>(RequestEnvelope envelope, TFutureType responseEnvelopeFuture, string url) where TFutureType : IFuture <ResponseEnvelope>, IAsyncCallBackTarget { //TODO: Add URL/URI //TODO: Verify header stuff IRestRequest request = new RestRequest(url).AddParameter("application/x-www-form-urlencoded", envelope.ToByteArray(), ParameterType.RequestBody); request.Method = Method.POST; var requestFuture = new RestSharpAsyncRequestFutureDeserializationDecorator <TFutureType>(responseEnvelopeFuture); httpClient.ExecuteAsync(request, (res, hand) => { requestFuture.OnResponse(res); }); return(requestFuture); }
/// <summary> /// Tries to send the <see cref="RequestEnvelope"/> message to the network. /// Returns an <typeparamref name="TResponseType"/> when completed. /// </summary> /// <param name="envelope">Envolope to send.</param> /// <returns>An awaitable future result.</returns> public IFuture <TResponseType> SendRequestAsFuture <TResponseType, TFutureType>(RequestEnvelope envelope, TFutureType responseMessageFuture, string url) where TResponseType : class, IResponseMessage, IMessage <TResponseType>, IMessage, new() where TFutureType : IFuture <TResponseType>, IAsyncCallBackTarget { //TODO: Verify header stuff IRestRequest request = new RestRequest(url).AddParameter("application/x-www-form-urlencoded", envelope.ToByteArray(), ParameterType.RequestBody); request.Method = Method.POST; var requestFuture = new RestSharpAsyncRequestFutureDeserializationDecorator <TFutureType, TResponseType>(responseMessageFuture); //To send protobuf requests httpClient.ExecuteAsync(request, (res, hand) => { requestFuture.OnResponse(res); }); //we have to provide the future as the callback return(requestFuture); }