Ejemplo n.º 1
0
        public AllocateJobChunkResponse Parse(AllocateJobChunkRequest request, IWebResponse response)
        {
            using (response)
            {
                ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK, HttpStatusCode.ServiceUnavailable, HttpStatusCode.NotFound);
                using (var responseStream = response.GetResponseStream())
                {
                    switch (response.StatusCode)
                    {
                    case HttpStatusCode.OK:
                        return(AllocateJobChunkResponse.Success(
                                   JobResponseParser <AllocateJobChunkRequest> .ParseObjectList(
                                       XmlExtensions
                                       .ReadDocument(responseStream)
                                       .ElementOrThrow("Objects")
                                       )
                                   ));

                    case HttpStatusCode.ServiceUnavailable:
                        return(AllocateJobChunkResponse.RetryAfter(TimeSpan.FromSeconds(int.Parse(response.Headers["retry-after"]))));

                    case HttpStatusCode.NotFound:
                        return(AllocateJobChunkResponse.ChunkGone);

                    default:
                        throw new NotSupportedException(Resources.InvalidEnumValueException);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public GetAvailableJobChunksResponse Parse(GetAvailableJobChunksRequest request, IWebResponse response)
        {
            using (response)
            {
                ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK, HttpStatusCode.NotFound);
                using (var responseStream = response.GetResponseStream())
                {
                    switch (response.StatusCode)
                    {
                    case HttpStatusCode.OK:
                        var jobResponse = JobResponseParser <GetAvailableJobChunksRequest> .ParseResponseContent(responseStream);

                        if (jobResponse.ObjectLists.Any())
                        {
                            return(GetAvailableJobChunksResponse.Success(RetryAfterHeader(response), jobResponse));
                        }
                        return(GetAvailableJobChunksResponse.RetryAfter(RetryAfterHeader(response)));

                    case HttpStatusCode.NotFound:
                        return(GetAvailableJobChunksResponse.JobGone);

                    default:
                        throw new NotSupportedException(Resources.InvalidEnumValueException);
                    }
                }
            }
        }