示例#1
0
        // virtual to allow mocking
        public virtual Task <NegotiationResponse> GetNegotiationResponse(IHttpClient httpClient, IConnection connection, string connectionData)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException("httpClient");
            }

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            var negotiateUrl = UrlBuilder.BuildNegotiate(connection, connectionData);

            httpClient.Initialize(connection);

            return(httpClient.Get(negotiateUrl, connection.PrepareRequest, isLongRunning: false)
                   .Then(response => response.ReadAsString())
                   .Then(raw =>
            {
                if (String.IsNullOrEmpty(raw))
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_ServerNegotiationFailed));
                }

                return JsonConvert.DeserializeObject <NegotiationResponse>(raw);
            }));
        }
        public virtual async Task <NegotiationResponse> GetNegotiationResponse(IHttpClient httpClient, IConnection connection, string connectionData)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException("httpClient");
            }

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            var negotiateUrl = UrlBuilder.BuildNegotiate(connection, connectionData);

            httpClient.Initialize(connection);
            var response = await httpClient.Get(negotiateUrl, connection.PrepareRequest, isLongRunning : false);

            if (response == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Error_ServerNegotiationFailed"));
            }
            else
            {
                var result = await response.ReadAsString();

                if (string.IsNullOrEmpty(result))
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Error_ServerNegotiationFailed"));
                }

                return(JsonConvert.DeserializeObject <NegotiationResponse>(result));
            }
        }
示例#3
0
        // virtual to allow mocking
        public virtual Task <NegotiationResponse> GetNegotiationResponse(IHttpClient httpClient, IConnection connection, string connectionData)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException("httpClient");
            }

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            var negotiateUrl = UrlBuilder.BuildNegotiate(connection, connectionData);

            httpClient.Initialize(connection);

            return(httpClient.Get(negotiateUrl, connection.PrepareRequest, isLongRunning: false)
                   .Then(response => response.ReadAsString())
                   .Then(raw =>
            {
                if (String.IsNullOrEmpty(raw))
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_ServerNegotiationFailed));
                }

                // We need to parse it into a JObject first so that we can check if this is an ASP.NET Core SignalR server
                var jobj = JObject.Parse(raw);
                if (jobj.Property("availableTransports") != null)
                {
                    // This is ASP.NET Core!
                    throw new InvalidOperationException(Resources.Error_AspNetCoreServerDetected);
                }

                return jobj.ToObject <NegotiationResponse>();
            }));
        }