Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(198)

Side by Side Diff: Src/GoogleApis/Apis/Requests/ClientServiceRequest.cs

Issue 12772043: Issues 373 (Execute Bug), 374 (Remove Tests.Utility) and 375 (Clean warnings) (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Error in uploading the first time Created 10 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright 2011 Google Inc 2 Copyright 2011 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 public TResponse Execute() 84 public TResponse Execute()
85 { 85 {
86 try 86 try
87 { 87 {
88 using (var response = ExecuteUnparsed(CancellationToken.None).Re sult) 88 using (var response = ExecuteUnparsed(CancellationToken.None).Re sult)
89 { 89 {
90 return ParseResponse(response).Result; 90 return ParseResponse(response).Result;
91 } 91 }
92 } 92 }
93 catch (AggregateException ex) 93 catch (AggregateException aex)
94 { 94 {
95 // if an exception was thrown during the tasks, unwrap and throw it 95 // if an exception was thrown during the tasks, unwrap and throw it
96 throw ex.InnerException; 96 throw aex.InnerException;
97 }
98 catch (Exception ex)
99 {
100 throw ex;
97 } 101 }
98 } 102 }
99 103
100 public Stream ExecuteAsStream() 104 public Stream ExecuteAsStream()
101 { 105 {
102 // TODO(peleyal): should we copy the stream, and dispose the respons e? 106 // TODO(peleyal): should we copy the stream, and dispose the respons e?
103 try 107 try
104 { 108 {
105 // sync call 109 // sync call
106 var response = ExecuteUnparsed(CancellationToken.None).Result; 110 var response = ExecuteUnparsed(CancellationToken.None).Result;
107 return response.Content.ReadAsStreamAsync().Result; 111 return response.Content.ReadAsStreamAsync().Result;
108 } 112 }
109 catch (AggregateException ex) 113 catch (AggregateException aex)
110 { 114 {
111 // if an exception was thrown during the tasks, unwrap and throw it 115 // if an exception was thrown during the tasks, unwrap and throw it
112 throw ex.InnerException; 116 throw aex.InnerException;
117 }
118 catch (Exception ex)
119 {
120 throw ex;
113 } 121 }
114 } 122 }
115 123
116 public async Task<TResponse> ExecuteAsync() 124 public async Task<TResponse> ExecuteAsync()
117 { 125 {
118 return await ExecuteAsync(CancellationToken.None).ConfigureAwait(fal se); 126 return await ExecuteAsync(CancellationToken.None).ConfigureAwait(fal se);
119 } 127 }
120 128
121 public async Task<TResponse> ExecuteAsync(CancellationToken cancellation Token) 129 public async Task<TResponse> ExecuteAsync(CancellationToken cancellation Token)
122 { 130 {
(...skipping 25 matching lines...) Expand all
148 { 156 {
149 using (var request = CreateRequest()) 157 using (var request = CreateRequest())
150 { 158 {
151 return await service.HttpClient.SendAsync(request, cancellationT oken).ConfigureAwait(false); 159 return await service.HttpClient.SendAsync(request, cancellationT oken).ConfigureAwait(false);
152 } 160 }
153 } 161 }
154 162
155 /// <summary> Async executes the request without parsing the result. </s ummary> 163 /// <summary> Async executes the request without parsing the result. </s ummary>
156 private Task<HttpResponseMessage> ExecuteAsyncUnparsed(CancellationToken cancellationToken) 164 private Task<HttpResponseMessage> ExecuteAsyncUnparsed(CancellationToken cancellationToken)
157 { 165 {
166 // TODO(peleyal): remove the creation of a new Task (it's not necess ary).
167 // It should also be removed from ResumableMediaUpload and MediaDown loader!
168
158 // create a new task completion source and return its task. In addit ional task we actually send the request 169 // create a new task completion source and return its task. In addit ional task we actually send the request
159 // using ExecuteUnparsed and setting the result or the exception on the completion source 170 // using ExecuteUnparsed and setting the result or the exception on the completion source
160 TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompletionSo urce<HttpResponseMessage>(); 171 TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompletionSo urce<HttpResponseMessage>();
161 Task.Factory.StartNew(async () => 172 Task.Factory.StartNew(async () =>
162 { 173 {
163 try 174 try
164 { 175 {
165 var response = await ExecuteUnparsed(cancellationToken). ConfigureAwait(false); 176 var response = await ExecuteUnparsed(cancellationToken). ConfigureAwait(false);
166 tcs.SetResult(response); 177 tcs.SetResult(response);
167 } 178 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 dict.Add(name, value); 386 dict.Add(name, value);
376 } 387 }
377 } 388 }
378 389
379 return dict; 390 return dict;
380 } 391 }
381 392
382 #endregion 393 #endregion
383 } 394 }
384 } 395 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b