예제 #1
0
        public override ObjectListing Deserialize(ServiceResponse xmlStream)
        {
            var    listBucketResult = ContentDeserializer.Deserialize(xmlStream.Content);
            string encodeType       = listBucketResult.EncodingType == null ?
                                      string.Empty : listBucketResult.EncodingType.ToLowerInvariant();

            var objectList = new ObjectListing(listBucketResult.Name)
            {
                Delimiter   = Decode(listBucketResult.Delimiter, encodeType),
                IsTruncated = listBucketResult.IsTruncated,
                Marker      = Decode(listBucketResult.Marker, encodeType),
                MaxKeys     = listBucketResult.MaxKeys,
                NextMarker  = Decode(listBucketResult.NextMarker, encodeType),
                Prefix      = Decode(listBucketResult.Prefix, encodeType)
            };

            if (listBucketResult.Contents != null)
            {
                foreach (var contents in listBucketResult.Contents)
                {
                    var summary = new OssObjectSummary
                    {
                        BucketName                                 = listBucketResult.Name,
                        Key                                        = Decode(contents.Key, encodeType),
                        LastModified                               = contents.LastModified,
                        ETag                                       = contents.ETag != null?OssUtils.TrimQuotes(contents.ETag) : string.Empty,
                                                      Size         = contents.Size,
                                                      StorageClass = contents.StorageClass,
                                                      Owner        = contents.Owner != null ?
                                                                     new Owner(contents.Owner.Id, contents.Owner.DisplayName) : null
                    };

                    objectList.AddObjectSummary(summary);
                }
            }

            if (listBucketResult.CommonPrefixes != null)
            {
                foreach (var commonPrefixes in listBucketResult.CommonPrefixes)
                {
                    if (commonPrefixes.Prefix != null)
                    {
                        foreach (var prefix in commonPrefixes.Prefix)
                        {
                            objectList.AddCommonPrefix(Decode(prefix, encodeType));
                        }
                    }
                }
            }

            DeserializeGeneric(xmlStream, objectList);

            return(objectList);
        }
예제 #2
0
        public override ObjectVersionList Deserialize(ServiceResponse xmlStream)
        {
            var    model      = ContentDeserializer.Deserialize(xmlStream.Content);
            string encodeType = model.EncodingType == null ?
                                string.Empty : model.EncodingType.ToLowerInvariant();

            var result = new ObjectVersionList(model.Name)
            {
                Delimiter           = Decode(model.Delimiter, encodeType),
                Prefix              = Decode(model.Prefix, encodeType),
                KeyMarker           = Decode(model.KeyMarker, encodeType),
                NextKeyMarker       = Decode(model.NextKeyMarker, encodeType),
                VersionIdMarker     = model.VersionIdMarker,
                NextVersionIdMarker = model.NextVersionIdMarker
            };

            if (model.MaxKeys.HasValue)
            {
                result.MaxKeys = model.MaxKeys.Value;
            }
            if (model.IsTruncated.HasValue)
            {
                result.IsTruncated = model.IsTruncated.Value;
            }

            if (model.ObjectVersions != null)
            {
                foreach (var objectVersion in model.ObjectVersions)
                {
                    var summary = new ObjectVersionSummary
                    {
                        BucketName                                 = model.Name,
                        Key                                        = Decode(objectVersion.Key, encodeType),
                        VersionId                                  = objectVersion.VersionId,
                        IsLatest                                   = objectVersion.IsLatest,
                        LastModified                               = objectVersion.LastModified,
                        ETag                                       = objectVersion.ETag != null?OssUtils.TrimQuotes(objectVersion.ETag) : string.Empty,
                                                      Size         = objectVersion.Size,
                                                      StorageClass = objectVersion.StorageClass,
                                                      Type         = objectVersion.Type,
                                                      Owner        = objectVersion.Owner != null ?
                                                                     new Owner(objectVersion.Owner.Id, objectVersion.Owner.DisplayName) : null
                    };

                    result.AddObjectVersionSummary(summary);
                }
            }

            if (model.ObjectDeleteMarkers != null)
            {
                foreach (var deleteMarker in model.ObjectDeleteMarkers)
                {
                    var summary = new DeleteMarkerSummary
                    {
                        BucketName   = model.Name,
                        Key          = Decode(deleteMarker.Key, encodeType),
                        VersionId    = deleteMarker.VersionId,
                        IsLatest     = deleteMarker.IsLatest,
                        LastModified = deleteMarker.LastModified,
                        Owner        = deleteMarker.Owner != null ?
                                       new Owner(deleteMarker.Owner.Id, deleteMarker.Owner.DisplayName) : null
                    };

                    result.AddDeleteMarkerSummary(summary);
                }
            }

            if (model.CommonPrefixes != null)
            {
                foreach (var prefixes in model.CommonPrefixes)
                {
                    if (prefixes.Prefix != null)
                    {
                        result.AddCommonPrefix(Decode(prefixes.Prefix, encodeType));
                    }
                }
            }

            DeserializeGeneric(xmlStream, result);

            return(result);
        }