|
12 | 12 | * express or implied. See the License for the specific language governing |
13 | 13 | * permissions and limitations under the License. |
14 | 14 | */ |
15 | | -using System; |
16 | | -using System.Net; |
17 | | -using System.Collections.Generic; |
18 | | -using Amazon.S3.Model; |
19 | 15 | using Amazon.Runtime; |
20 | 16 | using Amazon.Runtime.Internal; |
21 | 17 | using Amazon.Runtime.Internal.Transform; |
| 18 | +using Amazon.S3.Model; |
22 | 19 | using Amazon.S3.Util; |
| 20 | +using System; |
| 21 | +using System.Collections.Generic; |
| 22 | +using System.Net; |
23 | 23 |
|
24 | 24 | namespace Amazon.S3.Model.Internal.MarshallTransformations |
25 | 25 | { |
26 | 26 | /// <summary> |
27 | 27 | /// Response Unmarshaller for ListObjects operation |
28 | 28 | /// </summary> |
29 | | - public class ListObjectsResponseUnmarshaller : S3ReponseUnmarshaller |
| 29 | + public partial class ListObjectsResponseUnmarshaller : S3ReponseUnmarshaller |
30 | 30 | { |
31 | | - /// <summary> |
32 | | - /// Unmarshaller the response from the service to the response class. |
33 | | - /// </summary> |
34 | | - /// <param name="context"></param> |
35 | | - /// <returns></returns> |
36 | | - public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) |
37 | | - { |
38 | | - ListObjectsResponse response = new ListObjectsResponse(); |
39 | | - |
40 | | - while (context.Read()) |
41 | | - { |
42 | | - if (context.IsStartElement) |
43 | | - { |
44 | | - UnmarshallResult(context,response); |
45 | | - continue; |
46 | | - } |
47 | | - } |
48 | | - |
49 | | - IWebResponseData responseData = context.ResponseData; |
50 | | - if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged)) |
51 | | - response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged)); |
52 | | - |
53 | | - return response; |
54 | | - } |
55 | | - |
56 | | - private static void UnmarshallResult(XmlUnmarshallerContext context,ListObjectsResponse response) |
| 31 | + private static void ContentsCustomUnmarshall(XmlUnmarshallerContext context, ListObjectsResponse response) |
57 | 32 | { |
58 | | - |
59 | | - int originalDepth = context.CurrentDepth; |
60 | | - int targetDepth = originalDepth + 1; |
61 | | - |
62 | | - if (context.IsStartOfDocument) |
63 | | - targetDepth += 2; |
64 | | - |
65 | | - while (context.Read()) |
| 33 | + if (response.S3Objects == null) |
66 | 34 | { |
67 | | - if (context.IsStartElement || context.IsAttribute) |
68 | | - { |
69 | | - if (context.TestExpression("IsTruncated", targetDepth)) |
70 | | - { |
71 | | - response.IsTruncated = BoolUnmarshaller.GetInstance().Unmarshall(context); |
72 | | - |
73 | | - continue; |
74 | | - } |
75 | | - if (context.TestExpression("NextMarker", targetDepth)) |
76 | | - { |
77 | | - response.NextMarker = StringUnmarshaller.GetInstance().Unmarshall(context); |
78 | | - |
79 | | - continue; |
80 | | - } |
81 | | - if (context.TestExpression("Contents", targetDepth)) |
82 | | - { |
83 | | - if (response.S3Objects == null) |
84 | | - { |
85 | | - response.S3Objects = new List<S3Object>(); |
86 | | - } |
87 | | - |
88 | | - // adding the bucket name into the S3Object instance enables |
89 | | - // a better pipelining experience in PowerShell |
90 | | - var s3Object = ContentsItemUnmarshaller.Instance.Unmarshall(context); |
91 | | - s3Object.BucketName = response.Name; |
92 | | - response.S3Objects.Add(s3Object); |
93 | | - continue; |
94 | | - } |
95 | | - if (context.TestExpression("Name", targetDepth)) |
96 | | - { |
97 | | - response.Name = StringUnmarshaller.GetInstance().Unmarshall(context); |
98 | | - |
99 | | - continue; |
100 | | - } |
101 | | - if (context.TestExpression("Prefix", targetDepth)) |
102 | | - { |
103 | | - response.Prefix = StringUnmarshaller.GetInstance().Unmarshall(context); |
104 | | - |
105 | | - continue; |
106 | | - } |
107 | | - if (context.TestExpression("Delimiter", targetDepth)) |
108 | | - { |
109 | | - response.Delimiter = StringUnmarshaller.GetInstance().Unmarshall(context); |
110 | | - |
111 | | - continue; |
112 | | - } |
113 | | - if (context.TestExpression("MaxKeys", targetDepth)) |
114 | | - { |
115 | | - response.MaxKeys = IntUnmarshaller.GetInstance().Unmarshall(context); |
116 | | - |
117 | | - continue; |
118 | | - } |
119 | | - if (context.TestExpression("CommonPrefixes", targetDepth)) |
120 | | - { |
121 | | - var prefix = CommonPrefixesItemUnmarshaller.Instance.Unmarshall(context); |
122 | | - |
123 | | - if(prefix != null) |
124 | | - { |
125 | | - if (response.CommonPrefixes == null) |
126 | | - { |
127 | | - response.CommonPrefixes = new List<string>(); |
128 | | - } |
129 | | - response.CommonPrefixes.Add(prefix); |
130 | | - } |
131 | | - |
132 | | - continue; |
133 | | - } |
134 | | - } |
135 | | - else if (context.IsEndElement && context.CurrentDepth < originalDepth) |
136 | | - { |
137 | | - return; |
138 | | - } |
| 35 | + response.S3Objects = new List<S3Object>(); |
139 | 36 | } |
140 | | - |
141 | | - |
142 | 37 |
|
| 38 | + // adding the bucket name into the S3Object instance enables |
| 39 | + // a better pipelining experience in PowerShell |
| 40 | + var s3Object = ContentsItemUnmarshaller.Instance.Unmarshall(context); |
| 41 | + s3Object.BucketName = response.Name; |
| 42 | + response.S3Objects.Add(s3Object); |
143 | 43 | return; |
144 | 44 | } |
145 | | - |
146 | | - private static ListObjectsResponseUnmarshaller _instance; |
147 | | - |
148 | | - /// <summary> |
149 | | - /// Singleton for the unmarshaller |
150 | | - /// </summary> |
151 | | - public static ListObjectsResponseUnmarshaller Instance |
152 | | - { |
153 | | - get |
154 | | - { |
155 | | - if (_instance == null) |
156 | | - { |
157 | | - _instance = new ListObjectsResponseUnmarshaller(); |
158 | | - } |
159 | | - return _instance; |
160 | | - } |
161 | | - } |
162 | 45 | } |
163 | 46 | } |
164 | 47 |
|
0 commit comments