forked from igorshmukler/XMLRPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XmlRpcAsyncResult.cs
executable file
·280 lines (248 loc) · 6.63 KB
/
XmlRpcAsyncResult.cs
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
XML-RPC.NET library
Copyright (c) 2001-2006, Charles Cook <charlescook@cookcomputing.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
namespace CookComputing.XmlRpc
{
using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading;
public class XmlRpcAsyncResult : IAsyncResult
{
// IAsyncResult members
public object AsyncState
{
get { return userAsyncState; }
}
public WaitHandle AsyncWaitHandle
{
get
{
bool completed = isCompleted;
if (manualResetEvent == null)
{
lock(this)
{
if (manualResetEvent == null)
manualResetEvent = new ManualResetEvent(completed);
}
}
if (!completed && isCompleted)
manualResetEvent.Set();
return manualResetEvent;
}
}
public bool CompletedSynchronously
{
get { return completedSynchronously; }
set
{
if (completedSynchronously)
completedSynchronously = value;
}
}
public bool IsCompleted
{
get { return isCompleted; }
}
#if (!COMPACT_FRAMEWORK)
public CookieCollection ResponseCookies
{
get { return _responseCookies; }
}
#endif
#if (!COMPACT_FRAMEWORK)
public WebHeaderCollection ResponseHeaders
{
get { return _responseHeaders; }
}
#endif
public bool UseEmptyParamsTag
{
get { return _useEmptyParamsTag; }
}
public bool UseIndentation
{
get { return _useIndentation; }
}
public int Indentation
{
get { return _indentation; }
}
public bool UseIntTag
{
get { return _useIntTag; }
}
public bool UseStringTag
{
get { return _useStringTag; }
}
// public members
public void Abort()
{
if (request != null)
request.Abort();
}
public Exception Exception
{
get { return exception; }
}
public XmlRpcClientProtocol ClientProtocol
{
get { return clientProtocol; }
}
//internal members
internal XmlRpcAsyncResult(
XmlRpcClientProtocol ClientProtocol,
XmlRpcRequest XmlRpcReq,
Encoding XmlEncoding,
bool useEmptyParamsTag,
bool useIndentation,
int indentation,
bool UseIntTag,
bool UseStringTag,
WebRequest Request,
AsyncCallback UserCallback,
object UserAsyncState,
int retryNumber)
{
xmlRpcRequest = XmlRpcReq;
clientProtocol = ClientProtocol;
request = Request;
userAsyncState = UserAsyncState;
userCallback = UserCallback;
completedSynchronously = true;
xmlEncoding = XmlEncoding;
_useEmptyParamsTag = useEmptyParamsTag;
_useIndentation = useIndentation;
_indentation = indentation;
_useIntTag = UseIntTag;
_useStringTag = UseStringTag;
}
internal void Complete(
Exception ex)
{
exception = ex;
Complete();
}
internal void Complete()
{
try
{
if (responseStream != null)
{
responseStream.Close();
responseStream = null;
}
if (responseBufferedStream != null)
responseBufferedStream.Position = 0;
}
catch(Exception ex)
{
if (exception == null)
exception = ex;
}
isCompleted = true;
try
{
if (manualResetEvent != null)
manualResetEvent.Set();
}
catch(Exception ex)
{
if (exception == null)
exception = ex;
}
if (userCallback != null)
userCallback(this);
}
internal WebResponse WaitForResponse()
{
if (!isCompleted)
AsyncWaitHandle.WaitOne();
if (exception != null)
throw exception;
return response;
}
internal bool EndSendCalled
{
get { return endSendCalled; }
set { endSendCalled = value; }
}
internal byte[] Buffer
{
get { return buffer; }
set { buffer = value; }
}
internal WebRequest Request { get { return request; }
}
internal WebResponse Response
{
get { return response; }
set { response = value; }
}
internal Stream ResponseStream
{
get { return responseStream; }
set { responseStream = value; }
}
internal XmlRpcRequest XmlRpcRequest
{
get { return xmlRpcRequest; }
set { xmlRpcRequest = value; }
}
internal Stream ResponseBufferedStream
{
get { return responseBufferedStream; }
set { responseBufferedStream = value; }
}
internal Encoding XmlEncoding
{
get { return xmlEncoding; }
}
XmlRpcClientProtocol clientProtocol;
WebRequest request;
AsyncCallback userCallback;
object userAsyncState;
bool completedSynchronously;
bool isCompleted;
bool endSendCalled = false;
ManualResetEvent manualResetEvent;
Exception exception;
WebResponse response;
Stream responseStream;
Stream responseBufferedStream;
byte[] buffer;
XmlRpcRequest xmlRpcRequest;
Encoding xmlEncoding;
bool _useEmptyParamsTag;
bool _useIndentation;
int _indentation;
bool _useIntTag;
bool _useStringTag;
#if (!COMPACT_FRAMEWORK)
internal CookieCollection _responseCookies;
internal WebHeaderCollection _responseHeaders;
#endif
}
}