コード例 #1
0
        protected QueryResult <IList <T> > GetResultOrThrow <T>(ICrateResponse <T> response)
        {
            var errorResponse = response as ErrorResponse <T>;

            if (errorResponse != null)
            {
                throw new DatabaseException(errorResponse.Error.Message);
            }

            var successResponse = response as SuccessResponse <T>;

            if (successResponse != null)
            {
                return(new QueryResult <IList <T> >(successResponse.Result, successResponse.ExecutionTime?.TotalMilliseconds));
            }

            throw new InvalidOperationException("Response is neither ErrorResponse nor SuccessResponse");
        }
コード例 #2
0
        private async Task <ICrateResponse <T> > HttpResponseToResponse <T>(HttpResponseMessage response, TimeSpan executionTime)
        {
            var responseContent = await response.Content.ReadAsStringAsync();

            ICrateResponse <T> result = null;

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                result = JsonConvert.DeserializeObject <ErrorResponse <T> >(responseContent);
            }
            else
            {
                result = JsonConvert.DeserializeObject <SuccessResponse <T> >(responseContent);
                (result as SuccessResponse <T>).MapResult();
            }

            result.ExecutionTime = executionTime;
            return(result);
        }