OLD | NEW |
1 /* | 1 /* |
2 Copyright 2013 Google Inc | 2 Copyright 2013 Google Inc |
3 | 3 |
4 Licensed under the Apache License, Version 2.0 (the "License"); | 4 Licensed under the Apache License, Version 2.0 (the "License"); |
5 you may not use this file except in compliance with the License. | 5 you may not use this file except in compliance with the License. |
6 You may obtain a copy of the License at | 6 You may obtain a copy of the License at |
7 | 7 |
8 http://www.apache.org/licenses/LICENSE-2.0 | 8 http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 |
10 Unless required by applicable law or agreed to in writing, software | 10 Unless required by applicable law or agreed to in writing, software |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 private class InnerRequest<TResponse> : InnerRequest | 94 private class InnerRequest<TResponse> : InnerRequest |
95 where TResponse : class | 95 where TResponse : class |
96 { | 96 { |
97 /// <summary>Gets or sets a concrete type callback for an individual
response. </summary> | 97 /// <summary>Gets or sets a concrete type callback for an individual
response. </summary> |
98 public OnResponse<TResponse> OnResponseCallback { get; set; } | 98 public OnResponse<TResponse> OnResponseCallback { get; set; } |
99 | 99 |
100 public override void OnResponse(object content, RequestError error,
int index, | 100 public override void OnResponse(object content, RequestError error,
int index, |
101 HttpResponseMessage message) | 101 HttpResponseMessage message) |
102 { | 102 { |
103 base.OnResponse(content, error, index, message); | 103 base.OnResponse(content, error, index, message); |
| 104 if (OnResponseCallback == null) |
| 105 return; |
| 106 |
104 OnResponseCallback(content as TResponse, error, index, message); | 107 OnResponseCallback(content as TResponse, error, index, message); |
105 } | 108 } |
106 } | 109 } |
107 | 110 |
108 #endregion | 111 #endregion |
109 | 112 |
110 /// <summary> | 113 /// <summary> |
111 /// Constructs a new batch request using the given service. See· | 114 /// Constructs a new batch request using the given service. See· |
112 /// <see cref="BatchRequest(IClientService, string)"/> for more informat
ion. | 115 /// <see cref="BatchRequest(IClientService, string)"/> for more informat
ion. |
113 /// </summary> | 116 /// </summary> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 }); | 154 }); |
152 } | 155 } |
153 | 156 |
154 /// <summary>Asynchronously executes the batch request.</summary> | 157 /// <summary>Asynchronously executes the batch request.</summary> |
155 public Task ExecuteAsync() | 158 public Task ExecuteAsync() |
156 { | 159 { |
157 return ExecuteAsync(CancellationToken.None); | 160 return ExecuteAsync(CancellationToken.None); |
158 } | 161 } |
159 | 162 |
160 /// <summary>Asynchronously executes the batch request.</summary> | 163 /// <summary>Asynchronously executes the batch request.</summary> |
161 /// <param name="taskCancellationToken">Cancellation token to cancel ope
ration.</param> | 164 /// <param name="cancellationToken">Cancellation token to cancel operati
on.</param> |
162 public async Task ExecuteAsync(CancellationToken cancellationToken) | 165 public async Task ExecuteAsync(CancellationToken cancellationToken) |
163 { | 166 { |
164 if (Count < 1) | 167 if (Count < 1) |
165 return; | 168 return; |
166 | 169 |
167 ConfigurableHttpClient httpClient = service.HttpClient; | 170 ConfigurableHttpClient httpClient = service.HttpClient; |
168 | 171 |
169 var requests = from r in allRequests | 172 var requests = from r in allRequests |
170 select r.ClientRequest; | 173 select r.ClientRequest; |
171 HttpContent outerContent = await CreateOuterRequestContent(requests)
.ConfigureAwait(false); | 174 HttpContent outerContent = await CreateOuterRequestContent(requests)
.ConfigureAwait(false); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 var content = await requestMessage.Content.ReadAsStringAsync().C
onfigureAwait(false); | 357 var content = await requestMessage.Content.ReadAsStringAsync().C
onfigureAwait(false); |
355 sb.Append("Content-Length: ").Append(content.Length); | 358 sb.Append("Content-Length: ").Append(content.Length); |
356 | 359 |
357 sb.Append(Environment.NewLine).Append(Environment.NewLine).Appen
d(content); | 360 sb.Append(Environment.NewLine).Append(Environment.NewLine).Appen
d(content); |
358 } | 361 } |
359 | 362 |
360 return sb.Append(Environment.NewLine).ToString(); | 363 return sb.Append(Environment.NewLine).ToString(); |
361 } | 364 } |
362 } | 365 } |
363 } | 366 } |
OLD | NEW |