forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPclExportClient.Net40.cs
More file actions
111 lines (91 loc) · 3.1 KB
/
PclExportClient.Net40.cs
File metadata and controls
111 lines (91 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//Copyright (c) Service Stack LLC. All Rights Reserved.
//License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt
#if !(XBOX || SL5 || NETFX_CORE || WP || PCL || NETSTANDARD1_1)
using System;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using ServiceStack;
using ServiceStack.Web;
namespace ServiceStack
{
#if !(ANDROID || __IOS__ || __MAC__)
using System.Web;
public class Net40PclExportClient : PclExportClient
{
public static Net40PclExportClient Provider = new Net40PclExportClient();
public static PclExportClient Configure()
{
Configure(Provider ?? (Provider = new Net40PclExportClient()));
Net40PclExport.Configure();
return Provider;
}
public override INameValueCollection NewNameValueCollection()
{
return new NameValueCollectionWrapper(new NameValueCollection());
}
public override INameValueCollection ParseQueryString(string query)
{
return HttpUtility.ParseQueryString(query).InWrapper();
}
public override string UrlEncode(string url)
{
return HttpUtility.UrlEncode(url);
}
public override string UrlDecode(string url)
{
return HttpUtility.UrlDecode(url);
}
public override string HtmlEncode(string html)
{
return HttpUtility.HtmlEncode(html);
}
public override string HtmlDecode(string html)
{
return HttpUtility.HtmlDecode(html);
}
public override string GetHeader(WebHeaderCollection headers, string name, Func<string, bool> valuePredicate)
{
var values = headers.GetValues(name);
return values == null ? null : values.FirstOrDefault(valuePredicate);
}
public override ITimer CreateTimer(TimerCallback cb, TimeSpan timeOut, object state)
{
return new AsyncTimer(new
System.Threading.Timer(s => cb(s), state, (int)timeOut.TotalMilliseconds, Timeout.Infinite));
}
public override Exception CreateTimeoutException(Exception ex, string errorMsg)
{
return new WebException("The request timed out", ex, WebExceptionStatus.Timeout, null);
}
public override bool IsWebException(WebException webEx)
{
return webEx != null && webEx.Response != null
&& webEx.Status == WebExceptionStatus.ProtocolError;
}
}
#endif
public class AsyncTimer : ITimer
{
public System.Threading.Timer Timer;
public AsyncTimer(System.Threading.Timer timer)
{
Timer = timer;
}
public void Cancel()
{
if (Timer == null) return;
this.Timer.Change(Timeout.Infinite, Timeout.Infinite);
this.Dispose();
}
public void Dispose()
{
if (Timer == null) return;
this.Timer.Dispose();
this.Timer = null;
}
}
}
#endif