Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FileWebRequest.cs
Go to the documentation of this file.
1using System.IO;
5
6namespace System.Net;
7
9{
11
12 private string _method = "GET";
13
15
17
19
21
22 private readonly Uri _uri;
23
24 private long _contentLength;
25
26 private int _timeout = 100000;
27
28 private bool _readPending;
29
30 private bool _writePending;
31
32 private bool _writing;
33
34 private bool _syncHint;
35
36 private int _aborted;
37
38 internal bool Aborted => _aborted != 0;
39
40 public override string? ConnectionGroupName { get; set; }
41
42 public override long ContentLength
43 {
44 get
45 {
46 return _contentLength;
47 }
48 set
49 {
50 if (value < 0)
51 {
52 throw new ArgumentException(System.SR.net_clsmall, "value");
53 }
55 }
56 }
57
58 public override string? ContentType
59 {
60 get
61 {
62 return _headers["Content-Type"];
63 }
64 set
65 {
66 _headers["Content-Type"] = value;
67 }
68 }
69
70 public override ICredentials? Credentials { get; set; }
71
72 public override WebHeaderCollection Headers => _headers;
73
74 public override string Method
75 {
76 get
77 {
78 return _method;
79 }
80 set
81 {
82 if (string.IsNullOrEmpty(value))
83 {
84 throw new ArgumentException(System.SR.net_badmethod, "value");
85 }
86 _method = value;
87 }
88 }
89
90 public override bool PreAuthenticate { get; set; }
91
92 public override IWebProxy? Proxy { get; set; }
93
94 public override int Timeout
95 {
96 get
97 {
98 return _timeout;
99 }
100 set
101 {
102 if (value < 0 && value != -1)
103 {
105 }
106 _timeout = value;
107 }
108 }
109
110 public override Uri RequestUri => _uri;
111
112 public override bool UseDefaultCredentials
113 {
114 get
115 {
117 }
118 set
119 {
121 }
122 }
123
124 internal FileWebRequest(Uri uri)
125 {
126 if ((object)uri.Scheme != Uri.UriSchemeFile)
127 {
128 throw new ArgumentOutOfRangeException("uri");
129 }
130 _uri = uri;
131 }
132
133 [Obsolete("Serialization has been deprecated for FileWebRequest.")]
139
144
149
151 {
152 return new WebException(System.SR.Format(System.SR.net_requestaborted, WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
153 }
154
156 {
157 if (Aborted)
158 {
160 }
161 if (string.Equals(_method, "GET", StringComparison.OrdinalIgnoreCase) || string.Equals(_method, "HEAD", StringComparison.OrdinalIgnoreCase))
162 {
164 }
165 if (_response != null)
166 {
168 }
169 lock (this)
170 {
171 if (_writePending)
172 {
174 }
175 _writePending = true;
176 }
177 }
178
180 {
181 try
182 {
183 if (_stream == null)
184 {
185 _stream = new WebFileStream(this, _uri.LocalPath, FileMode.Create, FileAccess.Write, FileShare.Read);
186 _fileAccess = FileAccess.Write;
187 _writing = true;
188 }
189 return _stream;
190 }
191 catch (Exception ex)
192 {
193 throw new WebException(ex.Message, ex);
194 }
195 }
196
197 public override IAsyncResult BeginGetRequestStream(AsyncCallback? callback, object? state)
198 {
201 return System.Threading.Tasks.TaskToApm.Begin(task, callback, state);
202 }
203
205 {
207 return Task.Factory.StartNew(delegate(object s)
208 {
210 Stream result = fileWebRequest.CreateWriteStream();
212 return result;
214 }
215
217 {
218 if (Aborted)
219 {
221 }
222 lock (this)
223 {
224 if (_readPending)
225 {
227 }
228 _readPending = true;
229 }
230 }
231
233 {
234 if (_writePending || _writing)
235 {
236 lock (this)
237 {
238 if (_writePending || _writing)
239 {
241 }
242 }
243 }
245 try
246 {
247 return _response ?? (_response = new FileWebResponse(this, _uri, _fileAccess, !_syncHint));
248 }
249 catch (Exception ex)
250 {
251 throw new WebException(ex.Message, ex);
252 }
253 }
254
255 public override IAsyncResult BeginGetResponse(AsyncCallback? callback, object? state)
256 {
259 return System.Threading.Tasks.TaskToApm.Begin(task, callback, state);
260 }
261
263 {
265 return Task.Factory.StartNew(delegate(object s)
266 {
268 WebResponse result = fileWebRequest.CreateResponse();
269 _readPending = false;
270 return result;
272 }
273
275 {
277 _writePending = false;
278 return result;
279 }
280
282 {
284 _readPending = false;
285 return result;
286 }
287
288 public override Stream GetRequestStream()
289 {
291 if (Timeout != -1 && !asyncResult.IsCompleted && (!asyncResult.AsyncWaitHandle.WaitOne(Timeout, exitContext: false) || !asyncResult.IsCompleted))
292 {
293 _stream?.Close();
295 }
297 }
298
299 public override WebResponse GetResponse()
300 {
301 _syncHint = true;
303 if (Timeout != -1 && !asyncResult.IsCompleted && (!asyncResult.AsyncWaitHandle.WaitOne(Timeout, exitContext: false) || !asyncResult.IsCompleted))
304 {
305 _response?.Close();
307 }
309 }
310
311 internal void UnblockReader()
312 {
313 lock (this)
314 {
316 }
317 _writing = false;
318 }
319
320 public override void Abort()
321 {
323 {
324 _stream?.Abort();
325 _response?.Close();
326 }
327 }
328}
virtual void Close()
Definition Stream.cs:644
override Task< Stream > GetRequestStreamAsync()
override IAsyncResult BeginGetResponse(AsyncCallback? callback, object? state)
override? string ConnectionGroupName
ManualResetEventSlim _blockReaderUntilRequestStreamDisposed
override WebResponse EndGetResponse(IAsyncResult asyncResult)
FileWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext)
override bool UseDefaultCredentials
override Stream GetRequestStream()
readonly WebHeaderCollection _headers
override Task< WebResponse > GetResponseAsync()
override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
void CheckAndMarkAsyncGetRequestStreamPending()
override IAsyncResult BeginGetRequestStream(AsyncCallback? callback, object? state)
static Exception CreateRequestAbortedException()
override? string ContentType
override? IWebProxy Proxy
void ISerializable. GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
override WebResponse GetResponse()
override Stream EndGetRequestStream(IAsyncResult asyncResult)
override? ICredentials Credentials
virtual void Close()
static string net_reqsubmitted
Definition SR.cs:16
static string net_PropertyNotSupportedException
Definition SR.cs:76
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_nouploadonget
Definition SR.cs:36
static string net_clsmall
Definition SR.cs:110
static string net_badmethod
Definition SR.cs:22
static string net_io_timeout_use_ge_zero
Definition SR.cs:18
static string net_requestaborted
Definition SR.cs:42
static string net_repcall
Definition SR.cs:38
static string net_webstatus_Timeout
Definition SR.cs:46
Definition SR.cs:7
static int Increment(ref int location)
static IAsyncResult Begin(Task task, AsyncCallback callback, object state)
Definition TaskToApm.cs:43
static void End(IAsyncResult asyncResult)
Definition TaskToApm.cs:48
static new TaskFactory< TResult > Factory
Definition Task.cs:56
static readonly string UriSchemeFile
Definition Uri.cs:155
string Scheme
Definition Uri.cs:505
string LocalPath
Definition Uri.cs:280
void GetObjectData(SerializationInfo info, StreamingContext context)