Exemple #1
0
        public async Task <StreamFlowInvokeResult <TResponse> > InvokeAsync <TResponse>(StreamFlowMessageBO request)
        {
            //request.Recipient ??= TargetClient;
            var signalRResponse = await SignalRService.InvokeAsync(request);

            var tResponse = Activator.CreateInstance <TResponse>();

            switch (signalRResponse.HttpStatusCode)
            {
            case HttpStatusCode.Processing:

                tResponse.GetType().GetProperty("Message")?
                .SetValue(tResponse, $"Request is queued, waiting for connection to be re-established", null);
                tResponse.GetType().GetProperty("HttpStatusCode")?
                .SetValue(tResponse, HttpStatusCode.Processing, null);

                return(new(){
                    HttpStatusCode = HttpStatusCode.Processing,
                    Response = tResponse
                });

            case HttpStatusCode.NotFound:
                {
                    tResponse.GetType().GetProperty("Message")?
                    .SetValue(tResponse, $"Service is currently offline", null);
                    tResponse.GetType().GetProperty("HttpStatusCode")?
                    .SetValue(tResponse, HttpStatusCode.NotFound, null);

                    return(new(){
                        HttpStatusCode = HttpStatusCode.NotFound,
                        Response = tResponse
                    });
                }

            default:
                return(new(){
                    HttpStatusCode = HttpStatusCode.Accepted,
                    Response = JsonSerializer.Deserialize <TResponse>(signalRResponse.Response)
                });
            }
        }