Skip to content

Commit f6ebdb7

Browse files
committed
Enable async/task extensions for monodroid and monotouch
1 parent 159ab12 commit f6ebdb7

File tree

6 files changed

+68
-4
lines changed

6 files changed

+68
-4
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Net;
3+
4+
namespace RestSharp.Extensions
5+
{
6+
public static class ResponseStatusExtensions
7+
{
8+
/// <summary>
9+
/// Convert a <see cref="ResponseStatus"/> to a <see cref="WebException"/> instance.
10+
/// </summary>
11+
/// <param name="responseStatus">The response status.</param>
12+
/// <returns></returns>
13+
/// <exception cref="System.ArgumentOutOfRangeException">responseStatus</exception>
14+
public static WebException ToWebException(this ResponseStatus responseStatus)
15+
{
16+
switch (responseStatus)
17+
{
18+
case ResponseStatus.None:
19+
return new WebException("The request could not be processed.", WebExceptionStatus.ServerProtocolViolation);
20+
case ResponseStatus.Error:
21+
return new WebException("An error occured while processing the request.", WebExceptionStatus.ServerProtocolViolation);
22+
case ResponseStatus.TimedOut:
23+
return new WebException("The request timed-out.", WebExceptionStatus.Timeout);
24+
case ResponseStatus.Aborted:
25+
return new WebException("The request was aborted.", WebExceptionStatus.Timeout);
26+
default:
27+
throw new ArgumentOutOfRangeException("responseStatus");
28+
}
29+
}
30+
}
31+
}

RestSharp.MonoDroid/RestSharp.MonoDroid.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
<Compile Include="..\RestSharp\SharedAssemblyInfo.cs">
255255
<Link>SharedAssemblyInfo.cs</Link>
256256
</Compile>
257+
<Compile Include="Extensions\ResponseStatusExtensions.cs" />
257258
<Compile Include="Properties\AssemblyInfo.cs" />
258259
</ItemGroup>
259260
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Net;
3+
4+
namespace RestSharp.Extensions
5+
{
6+
public static class ResponseStatusExtensions
7+
{
8+
/// <summary>
9+
/// Convert a <see cref="ResponseStatus"/> to a <see cref="WebException"/> instance.
10+
/// </summary>
11+
/// <param name="responseStatus">The response status.</param>
12+
/// <returns></returns>
13+
/// <exception cref="System.ArgumentOutOfRangeException">responseStatus</exception>
14+
public static WebException ToWebException(this ResponseStatus responseStatus)
15+
{
16+
switch (responseStatus)
17+
{
18+
case ResponseStatus.None:
19+
return new WebException("The request could not be processed.", WebExceptionStatus.ServerProtocolViolation);
20+
case ResponseStatus.Error:
21+
return new WebException("An error occured while processing the request.", WebExceptionStatus.ServerProtocolViolation);
22+
case ResponseStatus.TimedOut:
23+
return new WebException("The request timed-out.", WebExceptionStatus.Timeout);
24+
case ResponseStatus.Aborted:
25+
return new WebException("The request was aborted.", WebExceptionStatus.Timeout);
26+
default:
27+
throw new ArgumentOutOfRangeException("responseStatus");
28+
}
29+
}
30+
}
31+
}

RestSharp.MonoTouch/RestSharp.MonoTouch.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
<Compile Include="..\RestSharp\SharedAssemblyInfo.cs">
304304
<Link>SharedAssemblyInfo.cs</Link>
305305
</Compile>
306+
<Compile Include="Extensions\ResponseStatusExtensions.cs" />
306307
<Compile Include="Properties\AssemblyInfo.cs" />
307308
</ItemGroup>
308309
</Project>

RestSharp/IRestClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using System.Net;
1919
using System.Collections.Generic;
2020
using System.Security.Cryptography.X509Certificates;
21-
#if NET4
21+
#if NET4 || MONODROID || MONOTOUCH
2222
using System.Threading;
2323
using System.Threading.Tasks;
2424
#endif
@@ -123,7 +123,7 @@ public interface IRestClient
123123
IRestResponse<T> ExecuteAsPost<T>(IRestRequest request, string httpMethod) where T : new();
124124
#endif
125125

126-
#if NET4
126+
#if NET4 || MONODROID || MONOTOUCH
127127
/// <summary>
128128
/// Executes the request and callback asynchronously, authenticating if needed
129129
/// </summary>

RestSharp/RestClient.Async.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using System.Collections.Generic;
1919
using System.Linq;
2020
using System.Threading;
21-
#if NET4
21+
#if NET4 || MONODROID || MONOTOUCH
2222
using System.Threading.Tasks;
2323
#endif
2424
using System.Text;
@@ -158,7 +158,7 @@ private void DeserializeResponse<T>(IRestRequest request, Action<IRestResponse<T
158158
callback(restResponse, asyncHandle);
159159
}
160160

161-
#if NET4
161+
#if NET4 || MONODROID || MONOTOUCH
162162
/// <summary>
163163
/// Executes a GET-style request asynchronously, authenticating if needed
164164
/// </summary>

0 commit comments

Comments
 (0)