Exemplo n.º 1
0
        public void HandleResponse(RpcStreamingResponseMessage rpcStreamingResponse)
        {
            lock (_lockingObject)
            {
                if (rpcStreamingResponse.Method == null)
                {
                    if (rpcStreamingResponse.Id.ToString() == SubscribeRequestId.ToString())
                    {
                        if (rpcStreamingResponse.HasError)
                        {
                            HandleSubscribeResponseError(GetException(rpcStreamingResponse));
                        }
                        else
                        {
                            var result = rpcStreamingResponse.GetStreamingResult <string>();
                            this.SubscriptionState = SubscriptionState.Subscribed;
                            this.SubscriptionId    = result;
                            StreamingClient.AddSubscription(SubscriptionId, this);
                            HandleSubscribeResponse(result);
                        }
                    }

                    if (!string.IsNullOrEmpty(UnsubscribeRequestId) && rpcStreamingResponse.Id.ToString() == UnsubscribeRequestId)
                    {
                        if (rpcStreamingResponse.HasError)
                        {
                            HandleUnsubscribeResponseError(GetException(rpcStreamingResponse));
                        }
                        else
                        {
                            var result = rpcStreamingResponse.GetStreamingResult <bool>();
                            if (result)
                            {
                                this.SubscriptionState = SubscriptionState.Unsubscribed;
                                StreamingClient.RemoveSubscription(SubscriptionId);
                            }
                            HandleUnsubscribeResponse(result);
                        }
                    }
                }
                else
                {
                    if (rpcStreamingResponse.HasError)
                    {
                        HandleDataResponseError(GetException(rpcStreamingResponse));
                    }
                    else
                    {
                        var result = rpcStreamingResponse.GetStreamingResult <TSubscriptionDataResponse>();
                        HandleDataResponse(result);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void HandleResponse(RpcStreamingResponseMessage rpcStreamingResponse)
 {
     if (rpcStreamingResponse.HasError)
     {
         HandleResponseError(
             new RpcResponseException(new RpcError(rpcStreamingResponse.Error.Code, rpcStreamingResponse.Error.Message,
                                                   rpcStreamingResponse.Error.Data)));
     }
     else
     {
         var result = rpcStreamingResponse.GetStreamingResult <TResponse>();
         HandleResponse(result);
     }
 }