本文整理汇总了C#中MindTouch.Dream.DreamMessage.ToBytes方法的典型用法代码示例。如果您正苦于以下问题:C# DreamMessage.ToBytes方法的具体用法?C# DreamMessage.ToBytes怎么用?C# DreamMessage.ToBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MindTouch.Dream.DreamMessage
的用法示例。
在下文中一共展示了DreamMessage.ToBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XMessage
//--- Constructors ---
/// <summary>
/// Serialize message into Xml.
/// </summary>
/// <param name="message">Message to serialize.</param>
public XMessage(DreamMessage message)
: base("message")
{
Elem("status", (int)message.Status);
Start("headers");
foreach(KeyValuePair<string, string> pair in message.Headers) {
Elem(pair.Key, pair.Value ?? string.Empty);
}
if(message.HasCookies) {
foreach(DreamCookie cookie in message.Cookies) {
// NOTE (steveb): we rely on the 'Version' being set to differentiate between 'Cookie' and a 'Set-Cookie' headers
if(cookie.Version != 0) {
Add(cookie.AsSetCookieDocument);
} else {
Add(cookie.AsCookieDocument);
}
}
}
End();
Start("body");
if(message.HasDocument) {
Attr("format", "xml").Add(message.ToDocument());
} else {
byte[] bytes = message.ToBytes();
string body = null;
string attr = "none";
// TODO (steveb): we need to use a content-type matching algorithm and match against all known text types (text/*, application/json, etc.)
if(bytes.Length > 0) {
if(message.ContentType.Match(MimeType.ANY_TEXT)) {
body = message.ContentType.CharSet.GetString(bytes).EncodeHtmlEntities(Encoding.UTF8, false);
attr = "text";
} else {
body = Convert.ToBase64String(bytes);
attr = "base64";
}
}
Attr("format", attr).Value(body);
}
End();
}
示例2: GetRequestAsBytes
private static object GetRequestAsBytes(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
return request.ToBytes();
}
示例3: PostConvert
internal Yield PostConvert(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
response.Return(DreamMessage.Ok(request.ContentType, request.ToBytes()));
yield break;
}
示例4: PostConvert
internal Yield PostConvert(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
// TODO (2014-11-25, steveb): what is this used for?
response.Return(DreamMessage.Ok(request.ContentType, request.ToBytes()));
yield break;
}
示例5: SetRequestResult
private void SetRequestResult(DreamMessage result, XUri uri)
{
String tempfilename = String.Empty;
_cookies.Update(result.Cookies, uri);
txtHeaders.Clear();
foreach (KeyValuePair<string, string> header in result.Headers) {
txtHeaders.Text += header.Key + " = " + header.Value + Environment.NewLine;
}
foreach (DreamCookie c in result.Cookies) {
txtHeaders.Text += string.Format("Cookie: '{0}' Value: '{1}' Path: '{2}', Expires: '{3}' Domain: '{4}' {5}", c.Name, c.Value, c.Path, c.Expires, c.Domain, Environment.NewLine);
}
// if we received a file, save it
if (!String.IsNullOrEmpty(result.Headers[DreamHeaders.CONTENT_DISPOSITION])) {
String filename;
String[] contentInfoList = result.Headers[DreamHeaders.CONTENT_DISPOSITION].Split(';');
foreach (String contentInfo in contentInfoList) {
String trimmedContentInfo = contentInfo.Trim();
if (StringUtil.StartsWithInvariantIgnoreCase(trimmedContentInfo, "filename=")) {
filename = trimmedContentInfo.Substring(9);
filename = filename.Trim('"', '\\');
tempfilename = Path.Combine(Path.GetTempPath(), filename);
result.ToStream().CopyToFile(tempfilename, result.ContentLength);
}
}
} else {
tempfilename = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks.ToString()) + ".xml";
RegistryKey key = Registry.ClassesRoot.OpenSubKey("MIME\\Database\\Content Type\\" + result.ContentType.FullType);
if (null != key) {
tempfilename = tempfilename + key.GetValue("Extension");
key.Close();
}
File.WriteAllBytes(tempfilename, result.ToBytes());
}
// browse to the saved temporary file
if (!String.IsNullOrEmpty(tempfilename))
{
webBrowser.Url = new Uri(tempfilename);
}
else{
webBrowser.Url = null;
}
tabControl1.SelectedTab = resultsTabPage;
}