/// <summary> /// Sends the query request and waits for the result /// </summary> /// <typeparam name="T">The expected result type</typeparam> /// <param name="socket">The connection to send and wait on</param> /// <param name="request">The request to send</param> /// <returns></returns> protected virtual async Task <CallResult <T> > QueryAndWait <T>(SocketConnection socket, object request) { CallResult <T> dataResult = new CallResult <T>(default(T), new ServerError("No response on query received")); await socket.SendAndWait(request, ResponseTimeout, (data) => { if (!HandleQueryResponse <T>(socket, request, data, out var callResult)) { return(false); } dataResult = callResult; return(true); }).ConfigureAwait(false); return(dataResult); }
/// <summary> /// Sends the subscribe request and waits for a response to that request /// </summary> /// <param name="socket">The connection to send the request on</param> /// <param name="request">The request to send</param> /// <param name="subscription">The subscription the request is for</param> /// <returns></returns> protected internal virtual async Task <CallResult <bool> > SubscribeAndWait(SocketConnection socket, object request, SocketSubscription subscription) { CallResult <object> callResult = null; await socket.SendAndWait(request, ResponseTimeout, (data) => { if (!HandleSubscriptionResponse(socket, subscription, request, data, out callResult)) { return(false); } return(true); }).ConfigureAwait(false); if (callResult?.Success == true) { subscription.Confirmed = true; } return(new CallResult <bool>(callResult?.Success ?? false, callResult == null ? new ServerError("No response on subscription request received"): callResult.Error)); }
/// <summary> /// Needs to check if a received message was an answer to a subscription request (preferable by id) and set the callResult out to whatever the response is /// </summary> /// <param name="s">The socket connection</param> /// <param name="subscription"></param> /// <param name="request">The request that a response is awaited for</param> /// <param name="data">The message</param> /// <param name="callResult">The interpretation (null if message wasn't a response to the request)</param> /// <returns>True if the message was a response to the subscription request</returns> protected internal abstract bool HandleSubscriptionResponse(SocketConnection s, SocketSubscription subscription, object request, JToken message, out CallResult <object> callResult);
/// <summary> /// Needs to check if a received message was an answer to a query request (preferable by id) and set the callResult out to whatever the response is /// </summary> /// <typeparam name="T">The type of response</typeparam> /// <param name="s">The socket connection</param> /// <param name="request">The request that a response is awaited for</param> /// <param name="data">The message</param> /// <param name="callResult">The interpretation (null if message wasn't a response to the request)</param> /// <returns>True if the message was a response to the query</returns> protected internal abstract bool HandleQueryResponse <T>(SocketConnection s, object request, JToken data, out CallResult <T> callResult);