public DeleteObjectListResponse Parse(DeleteObjectListRequest request, IWebResponse response)
 {
     using (response)
     {
         ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK);
         using (var content = response.GetResponseStream())
         {
             var deleteResult = XmlExtensions
                                .ReadDocument(content)
                                .ElementOrThrow("DeleteResult");
             return(new DeleteObjectListResponse(
                        deletedObjects: deleteResult
                        .Elements("Deleted")
                        .Select(el => el.TextOf("Key"))
                        .ToList(),
                        deleteErrors: deleteResult
                        .Elements("Error")
                        .Select(el => new DeleteDs3ObjectError(
                                    el.TextOf("Key"),
                                    el.TextOf("Code"),
                                    el.TextOf("Message")
                                    ))
                        .ToList()
                        ));
         }
     }
 }
 public GetJobListResponse Parse(GetJobListRequest request, IWebResponse response)
 {
     using (response)
     {
         ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK);
         using (var stream = response.GetResponseStream())
         {
             return(new GetJobListResponse(
                        jobs: XmlExtensions
                        .ReadDocument(stream)
                        .ElementOrThrow("Jobs")
                        .Elements("Job")
                        .Select(jobElement => new JobInfo(
                                    jobElement.AttributeText("BucketName"),
                                    jobElement.AttributeText("StartDate"),
                                    Guid.Parse(jobElement.AttributeText("JobId")),
                                    jobElement.AttributeText("Priority"),
                                    jobElement.AttributeText("RequestType"),
                                    ResponseParseUtilities.ParseJobStatus(jobElement.AttributeText("Status"))
                                    ))
                        .ToList()
                        ));
         }
     }
 }
Exemple #3
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);
                    }
                }
            }
        }
Exemple #4
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);
                    }
                }
            }
        }
        public static JobResponse ParseResponseContent(Stream content)
        {
            var masterObjectList = XmlExtensions.ReadDocument(content).ElementOrThrow("MasterObjectList");

            return(new JobResponse(
                       bucketName: masterObjectList.AttributeText("BucketName"),
                       jobId: Guid.Parse(masterObjectList.AttributeText("JobId")),
                       priority: masterObjectList.AttributeText("Priority"),
                       requestType: masterObjectList.AttributeText("RequestType"),
                       startDate: DateTime.Parse(masterObjectList.AttributeText("StartDate")),
                       chunkOrder: ParseChunkOrdering(masterObjectList.AttributeText("ChunkClientProcessingOrderGuarantee")),
                       nodes: (
                           from nodesElement in masterObjectList.Elements("Nodes")
                           from nodeElement in nodesElement.Elements("Node")
                           select new Node(
                               Guid.Parse(nodeElement.AttributeText("Id")),
                               nodeElement.AttributeText("EndPoint"),
                               ParseIntOrNull(nodeElement.AttributeTextOrNull("HttpPort")),
                               ParseIntOrNull(nodeElement.AttributeTextOrNull("HttpsPort"))
                               )
                           ).ToList(),
                       objectLists: masterObjectList
                       .Elements("Objects")
                       .Select(ParseObjectList)
                       .ToList(),
                       status: ResponseParseUtilities.ParseJobStatus(masterObjectList.AttributeTextOrNull("Status"))
                       ));
        }
 public HeadObjectResponse Parse(HeadObjectRequest request, IWebResponse response)
 {
     using (response)
     {
         return(new HeadObjectResponse(
                    long.Parse(response.Headers.Single(kvp => kvp.Key.ToLowerInvariant() == "content-length").Value),
                    response.Headers.Single(kvp => kvp.Key.ToLowerInvariant() == "etag").Value,
                    ResponseParseUtilities.ExtractCustomMetadata(response.Headers)
                    ));
     }
 }
 public JobResponse Parse(TRequest request, IWebResponse response)
 {
     using (response)
     {
         ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK);
         using (Stream content = response.GetResponseStream())
         {
             return(ParseResponseContent(content));
         }
     }
 }
Exemple #8
0
 public GetServiceResponse Parse(GetServiceRequest request, IWebResponse response)
 {
     ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK);
     using (Stream content = response.GetResponseStream())
     {
         var root  = XmlExtensions.ReadDocument(content).ElementOrThrow("ListAllMyBucketsResult");
         var owner = root.ElementOrThrow("Owner");
         return(new GetServiceResponse(
                    owner: new Owner(owner.ElementOrThrow("ID").Value, owner.ElementOrThrow("DisplayName").Value),
                    buckets: (
                        from bucket in root.ElementOrThrow("Buckets").Elements("Bucket")
                        select new Bucket(bucket.ElementOrThrow("Name").Value, bucket.ElementOrThrow("CreationDate").Value)
                        ).ToList()
                    ));
     }
 }
        public HeadBucketResponse Parse(HeadBucketRequest request, IWebResponse response)
        {
            using (response)
            {
                ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK, HttpStatusCode.Forbidden, HttpStatusCode.NotFound);
                HeadBucketStatus status;
                switch (response.StatusCode)
                {
                case HttpStatusCode.OK: status = HeadBucketStatus.Exists; break;

                case HttpStatusCode.Forbidden: status = HeadBucketStatus.NotAuthorized; break;

                case HttpStatusCode.NotFound: status = HeadBucketStatus.DoesntExist; break;

                default: throw new NotSupportedException(Resources.InvalidEnumValueException);
                }
                return(new HeadBucketResponse(status: status));
            }
        }
 public GetObjectResponse Parse(GetObjectRequest request, IWebResponse response)
 {
     using (response)
     {
         ResponseParseUtilities.HandleStatusCode(
             response,
             request.GetByteRanges().Any()
                 ? HttpStatusCode.PartialContent
                 : HttpStatusCode.OK
             );
         using (var responseStream = response.GetResponseStream())
         {
             responseStream.CopyTo(request.DestinationStream, this._copyBufferSize);
         }
         return(new GetObjectResponse(
                    metadata: ResponseParseUtilities.ExtractCustomMetadata(response.Headers)
                    ));
     }
 }
 public GetAggregatePhysicalPlacementResponse Parse(GetAggregatePhysicalPlacementRequest request, IWebResponse response)
 {
     using (response)
     {
         ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK);
         using (var stream = response.GetResponseStream())
         {
             return(new GetAggregatePhysicalPlacementResponse(
                        XmlExtensions
                        .ReadDocument(stream)
                        .ElementOrThrow("Data")
                        .ElementOrThrow("Tapes")
                        .Elements("Tape")
                        .Select(ParseTape)
                        .ToList()
                        ));
         }
     }
 }
Exemple #12
0
 public GetBucketResponse Parse(GetBucketRequest request, IWebResponse response)
 {
     using (response)
     {
         ResponseParseUtilities.HandleStatusCode(response, HttpStatusCode.OK);
         using (Stream content = response.GetResponseStream())
         {
             var root = XmlExtensions.ReadDocument(content).ElementOrThrow("ListBucketResult");
             return(new GetBucketResponse(
                        name: root.TextOf("Name"),
                        prefix: root.TextOf("Prefix"),
                        marker: root.TextOf("Marker"),
                        nextMarker: root.TextOfOrNull("NextMarker"),
                        delimiter: root.TextOfOrNull("Delimiter"),
                        maxKeys: int.Parse(root.TextOf("MaxKeys")),
                        isTruncated: bool.Parse(root.TextOf("IsTruncated")),
                        creationDate: ParseDateTime(root.TextOfOrNull("CreationDate")),
                        objects: (
                            from obj in root.Elements("Contents")
                            let owner = obj.ElementOrThrow("Owner")
                                        select new Ds3ObjectInfo(
                                obj.TextOf("Key"),
                                long.Parse(obj.TextOf("Size")),
                                new Owner(owner.TextOf("ID"), owner.TextOf("DisplayName")),
                                obj.TextOf("ETag"),
                                obj.TextOf("StorageClass"),
                                ParseDateTime(obj.TextOf("LastModified"))
                                )
                            ).ToList(),
                        metadata: ResponseParseUtilities.ExtractCustomMetadata(response.Headers),
                        commonPrefixes: root
                        .Elements("CommonPrefixes")
                        .Select(cp => cp.TextOf("Prefix"))
                        .ToList()
                        ));
         }
     }
 }