Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MimeMultiPart.cs
Go to the documentation of this file.
3using System.IO;
6
7namespace System.Net.Mime;
8
9internal sealed class MimeMultiPart : MimeBasePart
10{
32
34
35 private static int s_boundary;
36
37 private AsyncCallback _mimePartSentCallback;
38
39 private bool _allowUnicode;
40
42 {
43 set
44 {
45 if (value > MimeMultiPartType.Related || value < MimeMultiPartType.Mixed)
46 {
47 throw new NotSupportedException(value.ToString());
48 }
50 }
51 }
52
54 {
55 get
56 {
57 if (_parts == null)
58 {
60 }
61 return _parts;
62 }
63 }
64
69
71 {
72 base.ContentType.MediaType = "multipart/" + type.ToString().ToLowerInvariant();
73 base.ContentType.Boundary = GetNextBoundary();
74 }
75
76 internal void Complete(IAsyncResult result, Exception e)
77 {
79 if (mimePartContext._completed)
80 {
82 }
83 try
84 {
85 mimePartContext._outputStream.Close();
86 }
87 catch (Exception ex)
88 {
89 if (e == null)
90 {
91 e = ex;
92 }
93 }
94 mimePartContext._completed = true;
95 mimePartContext._result.InvokeCallback(e);
96 }
97
99 {
100 if (result.CompletedSynchronously)
101 {
102 return;
103 }
104 ((MimePartContext)result.AsyncState)._completedSynchronously = false;
105 try
106 {
108 }
109 catch (Exception e)
110 {
111 Complete(result, e);
112 }
113 }
114
116 {
118 ((MimeWriter)mimePartContext._writer).EndClose(result);
119 Complete(result, null);
120 }
121
122 internal void MimePartSentCallback(IAsyncResult result)
123 {
124 if (result.CompletedSynchronously)
125 {
126 return;
127 }
128 ((MimePartContext)result.AsyncState)._completedSynchronously = false;
129 try
130 {
132 }
133 catch (Exception e)
134 {
135 Complete(result, e);
136 }
137 }
138
140 {
142 MimeBasePart current = mimePartContext._partsEnumerator.Current;
143 current.EndSend(result);
144 if (mimePartContext._partsEnumerator.MoveNext())
145 {
146 current = mimePartContext._partsEnumerator.Current;
148 if (asyncResult.CompletedSynchronously)
149 {
151 }
152 }
153 else
154 {
156 if (asyncResult2.CompletedSynchronously)
157 {
159 }
160 }
161 }
162
164 {
165 if (result.CompletedSynchronously)
166 {
167 return;
168 }
169 ((MimePartContext)result.AsyncState)._completedSynchronously = false;
170 try
171 {
173 }
174 catch (Exception e)
175 {
176 Complete(result, e);
177 }
178 }
179
181 {
183 mimePartContext._outputStream = mimePartContext._writer.EndGetContentStream(result);
184 mimePartContext._writer = new MimeWriter(mimePartContext._outputStream, base.ContentType.Boundary);
185 if (mimePartContext._partsEnumerator.MoveNext())
186 {
187 MimeBasePart current = mimePartContext._partsEnumerator.Current;
190 if (asyncResult.CompletedSynchronously)
191 {
193 }
194 }
195 else
196 {
198 if (asyncResult2.CompletedSynchronously)
199 {
201 }
202 }
203 }
204
205 internal override IAsyncResult BeginSend(BaseWriter writer, AsyncCallback callback, bool allowUnicode, object state)
206 {
209 writer.WriteHeaders(base.Headers, allowUnicode);
210 MimePartAsyncResult result = new MimePartAsyncResult(this, state, callback);
213 if (asyncResult.CompletedSynchronously)
214 {
216 }
217 return result;
218 }
219
220 internal override void Send(BaseWriter writer, bool allowUnicode)
221 {
223 writer.WriteHeaders(base.Headers, allowUnicode);
224 Stream contentStream = writer.GetContentStream();
225 MimeWriter mimeWriter = new MimeWriter(contentStream, base.ContentType.Boundary);
226 foreach (MimeBasePart part in Parts)
227 {
229 }
230 mimeWriter.Close();
231 contentStream.Close();
232 }
233
234 internal string GetNextBoundary()
235 {
237 return $"--boundary_{value}_{Guid.NewGuid()}";
238 }
239}
void EndSend(IAsyncResult asyncResult)
virtual IAsyncResult BeginSend(BaseWriter writer, AsyncCallback callback, bool allowUnicode, object state)
void PrepareHeaders(bool allowUnicode)
IEnumerator< MimeBasePart > _partsEnumerator
MimePartContext(BaseWriter writer, System.Net.LazyAsyncResult result, IEnumerator< MimeBasePart > partsEnumerator)
void MimeWriterCloseCallback(IAsyncResult result)
void SetType(MimeMultiPartType type)
Collection< MimeBasePart > _parts
void ContentStreamCallbackHandler(IAsyncResult result)
void Complete(IAsyncResult result, Exception e)
MimeMultiPart(MimeMultiPartType type)
override void Send(BaseWriter writer, bool allowUnicode)
void MimeWriterCloseCallbackHandler(IAsyncResult result)
void MimePartSentCallback(IAsyncResult result)
void MimePartSentCallbackHandler(IAsyncResult result)
Collection< MimeBasePart > Parts
void ContentStreamCallback(IAsyncResult result)
override IAsyncResult BeginSend(BaseWriter writer, AsyncCallback callback, bool allowUnicode, object state)
static int Increment(ref int location)