コード例 #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 NegotiationResponse.FromJson(JSON.Parse(raw));
            }));
        }