forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPclExportClient.SL5.cs
More file actions
119 lines (102 loc) · 3.61 KB
/
PclExportClient.SL5.cs
File metadata and controls
119 lines (102 loc) · 3.61 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
112
113
114
115
116
117
118
119
//Copyright (c) Service Stack LLC. All Rights Reserved.
//License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt
#if SL5
using System;
using System.Collections.Specialized;
using System.Net;
using System.Threading;
using System.Web;
using ServiceStack.Pcl;
using ServiceStack.Text;
using ServiceStack.Web;
namespace ServiceStack
{
public class Sl5PclExportClient : PclExportClient
{
public static Sl5PclExportClient Provider = new Sl5PclExportClient();
public static PclExportClient Configure()
{
Configure(Provider ?? (Provider = new Sl5PclExportClient()));
Sl5PclExport.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 void RunOnUiThread(Action fn)
{
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(fn);
}
public override void SetCookieContainer(HttpWebRequest webRequest, ServiceClientBase client)
{
if (!client.EmulateHttpViaPost)
{
if (client.ShareCookiesWithBrowser)
{
if (client.CookieContainer == null)
client.CookieContainer = new CookieContainer();
client.CookieContainer.SetCookies(webRequest.RequestUri, System.Windows.Browser.HtmlPage.Document.Cookies);
}
}
try
{
webRequest.CookieContainer = client.CookieContainer;
}
catch (NotImplementedException) {}
}
public override void SetCookieContainer(HttpWebRequest webRequest, AsyncServiceClient client)
{
if (!client.EmulateHttpViaPost)
{
if (client.ShareCookiesWithBrowser)
{
if (client.CookieContainer == null)
client.CookieContainer = new CookieContainer();
client.CookieContainer.SetCookies(webRequest.RequestUri, System.Windows.Browser.HtmlPage.Document.Cookies);
}
}
try
{
webRequest.CookieContainer = client.CookieContainer;
}
catch (NotImplementedException) {}
}
public override void SynchronizeCookies(AsyncServiceClient client)
{
if (client.StoreCookies && client.ShareCookiesWithBrowser && !client.EmulateHttpViaPost)
{
// browser cookies must be set on the ui thread
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var cookieHeader = client.CookieContainer.GetCookieHeader(new Uri(client.BaseUri));
System.Windows.Browser.HtmlPage.Document.Cookies = cookieHeader;
});
}
}
}
public class AsyncTimer : ITimer
{
public System.Threading.Timer Timer;
public AsyncTimer(System.Threading.Timer timer)
{
Timer = timer;
}
public void Cancel()
{
this.Timer.Change(Timeout.Infinite, Timeout.Infinite);
this.Dispose();
}
public void Dispose()
{
if (Timer == null) return;
this.Timer.Dispose();
this.Timer = null;
}
}
}
#endif