private void TraceSet() { if (this.mTrace == null) { this.mTrace = new NetTrace(); } this.mTrace.UseTrace = this.mSettings.UseTrace; this.mTrace.TraceFile = this.mSettings.TraceFile; this.mTrace.TraceSize = this.mSettings.TraceSize; this.mTrace.IsDebug = this.mSettings.IsDebug; }
public MemoryStream ToMemoryStream(ComParameter data, string boundary, NetTrace trace) { byte[] bytes = Encoding.ASCII.GetBytes("\r\n"); MemoryStream stream = new MemoryStream(); bool flag = data.AttachCount > 0; if (!string.IsNullOrEmpty(data.DataString)) { string str = MimeFormat.TextPart(boundary, this.BaseCharset); MemoryStream stream2 = this.TextEncoding(data.DataString); try { if (flag) { if (trace != null) { trace.WriteString(NetTrace.Tracekind.MIME, string.Format("+ {0,-16} : {1}", "ToMemoryStream", string.Format("TextDataLength={0}{1}{2}", stream2.ToArray().Length, "\r\n", str))); } byte[] buffer = Encoding.ASCII.GetBytes(str); stream.Write(buffer, 0, buffer.Length); } stream.Write(stream2.ToArray(), 0, stream2.ToArray().Length); } finally { stream2.Close(); } } foreach (string str2 in data.AttachFiles) { if (stream.ToArray().Length > 0) { stream.Write(bytes, 0, bytes.Length); } string path = Path.Combine(data.AttachFolder, str2); string s = MimeFormat.AttachtPart(path, boundary); string str5 = this.ReadAttachFile(path) + "\r\n"; byte[] buffer3 = this.BaseEncoding.GetBytes(str5); if (trace != null) { trace.WriteString(NetTrace.Tracekind.MIME, string.Format("+ {0,-16} : {1}", "ToMemoryStream", string.Format("AttachFilename={0} DataLength={1}{2}{3}", new object[] { str2, buffer3.Length, "\r\n", s }))); } byte[] buffer4 = Encoding.ASCII.GetBytes(s); stream.Write(buffer4, 0, buffer4.Length); stream.Write(buffer3, 0, buffer3.Length); } if (flag) { stream.Write(bytes, 0, bytes.Length); byte[] buffer5 = Encoding.ASCII.GetBytes(MimeFormat.LastPart(boundary)); stream.Write(buffer5, 0, buffer5.Length); } return stream; }
public HttpClient() { this.mBuilder = new ComParamBuilder(); this.mBuilder.BaseCharset = "UTF-8"; this.mTrace = new NetTrace(); }
public ComParameter ToComParameter(MemoryStream mem, string boundary, NetTrace trace) { MimePart part; ComParameter parameter = new ComParameter(); byte[] buffer = mem.ToArray(); for (long i = 0L; this.GetPart(boundary, buffer, i, out part); i = part.NextOffset) { if (Encoding.ASCII.GetString(buffer, (((int) part.BodyOffset) + part.BodyLength) - 4, 4).EndsWith("\r\n\r\n")) { part.BodyLength -= 2; } ContentType ct = null; string str2 = null; ContentDisposition cd = null; string str3 = this.GetValue(part.HdList, "Content-type"); if (!string.IsNullOrEmpty(str3)) { ct = new ContentType(str3); } str2 = this.GetValue(part.HdList, "Content-Transfer-Encoding"); str3 = this.GetValue(part.HdList, "Content-Disposition"); if (!string.IsNullOrEmpty(str3)) { cd = new ContentDisposition(str3); } if (MimeFormat.IsAttachment(cd)) { if (string.IsNullOrEmpty(parameter.AttachFolder)) { parameter.AttachFolder = this.AttachFolder; this.CreateAttachFolder(parameter.AttachFolder); } string str4 = MimeFormat.DecodeAttachFile(cd.FileName); if (trace != null) { trace.WriteString(NetTrace.Tracekind.MIME, string.Format("+ {0,-16} : {1}", "ToComParameter", string.Format("AttachFilename={0} DataLength={1}{2}{3}", new object[] { str4, part.BodyLength, "\r\n", part.Header }))); } if ((str2 != null) && str2.StartsWith("base64", StringComparison.CurrentCultureIgnoreCase)) { string str5 = Encoding.ASCII.GetString(buffer, (int) part.BodyOffset, part.BodyLength); this.WriteAttachFile(Path.Combine(parameter.AttachFolder, str4), str5); } else { FileStream stream = new FileStream(Path.Combine(parameter.AttachFolder, str4), FileMode.OpenOrCreate, FileAccess.Write); stream.Write(buffer, (int) part.BodyOffset, part.BodyLength); stream.Close(); } } else if (MimeFormat.IsText(ct)) { if (trace != null) { trace.WriteString(NetTrace.Tracekind.MIME, string.Format("+ {0,-16} : {1}", "ToComParameter", string.Format("TextDataLength={0}{1}{2}", part.BodyLength, "\r\n", part.Header))); } if (string.IsNullOrEmpty(parameter.DataString)) { parameter.DataString = this.TextDecoding(buffer, (int) part.BodyOffset, part.BodyLength, ct.CharSet); } } if (part.LastPart) { return parameter; } } return parameter; }