private static void WriteHeaderToFile(FileStream file, string header, string content) { byte[] bytes = CTSGlobals.AsciiEncoding.GetBytes(MessageSnapshotWriter.Rfc2047Encode(header + ": " + content)); file.Write(bytes, 0, bytes.Length); file.WriteByte(13); file.WriteByte(10); }
private static void WriteBeginningHeadersToFile(FileStream file, string id, string topic, string agent, string messageState) { StringBuilder stringBuilder = new StringBuilder(512); stringBuilder.Append("X-CreatedBy: MessageSnapshot-Begin injected headers\r\n"); stringBuilder.Append("X-MessageSnapshot-UTC-Time: "); stringBuilder.Append(DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture)); stringBuilder.Append("\r\n"); if (topic == "OnSubmittedMessage" || topic == "OnRoutedMessage" || topic == "OnResolvedMessage" || topic == "OnCategorizedMessage") { stringBuilder.Append("X-MessageSnapshot-Record-Id: "); } else { stringBuilder.Append("X-MessageSnapshot-Protocol-Id: "); } stringBuilder.Append(id); stringBuilder.Append("\r\n"); if (agent == null) { stringBuilder.Append("X-MessageSnapshot-Source: Original\r\n"); } else { string format = (agent.Length == 0) ? "X-MessageSnapshot-Source: {0}" : "X-MessageSnapshot-Source: {0},{1}"; string value = string.Format(CultureInfo.InvariantCulture, format, new object[] { topic, agent }); stringBuilder.Append(MessageSnapshotWriter.Rfc2047Encode(value)); stringBuilder.Append("\r\n"); } if (!string.IsNullOrEmpty(messageState)) { stringBuilder.AppendFormat("X-MessageSnapshot-MessageStatus: {0}\r\n", messageState); } byte[] bytes = CTSGlobals.AsciiEncoding.GetBytes(stringBuilder.ToString()); file.Write(bytes, 0, bytes.Length); }