本文整理汇总了C#中MindTouch.Dream.DreamMessage.AsBytes方法的典型用法代码示例。如果您正苦于以下问题:C# DreamMessage.AsBytes方法的具体用法?C# DreamMessage.AsBytes怎么用?C# DreamMessage.AsBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MindTouch.Dream.DreamMessage
的用法示例。
在下文中一共展示了DreamMessage.AsBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PreProcessRequest
private DreamMessage PreProcessRequest(string verb, XUri uri, XUri normalizedUri, DreamMessage message) {
DreamContext current = DreamContext.Current;
DekiContext deki = DekiContext.Current;
DekiInstance instance = deki.Instance;
// set preferred culture
message.Headers.AcceptLanguage = string.Format("{0}, *;q=0.5", current.Culture.Name);
// add the 'deki' header
message.Headers[DekiExtService.DEKI_HEADER] = instance.Token;
// convert implicit environment into a message headers
DekiScriptMap implicitEnv = DreamContext.Current.GetState<DekiScriptMap>();
if(implicitEnv != null) {
foreach(KeyValuePair<string, DekiScriptLiteral> outer in implicitEnv.Value) {
DekiScriptMap map = outer.Value as DekiScriptMap;
if((map != null) && !map.IsEmpty) {
StringBuilder header = new StringBuilder();
foreach(KeyValuePair<string, DekiScriptLiteral> inner in map.Value) {
string value = inner.Value.AsString();
if(value != null) {
if(header.Length > 0) {
header.Append(", ");
}
header.AppendFormat("{0}.{1}={2}", outer.Key, inner.Key, value.QuoteString());
}
}
// add header
string headerValue = header.ToString();
message.Headers.Add(DekiExtService.IMPLICIT_ENVIRONMENT_HEADER, headerValue);
}
}
}
// add digital signature
DSACryptoServiceProvider dsa = instance.PrivateDigitalSignature;
if(dsa != null) {
MemoryStream data = new MemoryStream();
// get message bytes
byte[] bytes = message.AsBytes();
data.Write(bytes, 0, bytes.Length);
// retrieve headers to sign
string[] headers = message.Headers.GetValues(DekiExtService.IMPLICIT_ENVIRONMENT_HEADER);
if(!ArrayUtil.IsNullOrEmpty(headers)) {
Array.Sort(headers, StringComparer.Ordinal);
bytes = Encoding.UTF8.GetBytes(string.Join(",", headers));
data.Write(bytes, 0, bytes.Length);
}
// add request date
string date = DateTime.UtcNow.ToString(XDoc.RFC_DATETIME_FORMAT);
bytes = Encoding.UTF8.GetBytes(date);
data.Write(bytes, 0, bytes.Length);
// sign data
byte[] signature = dsa.SignData(data.GetBuffer());
message.Headers.Add(DekiExtService.IMPLICIT_SIGNATURE_HEADER, string.Format("dsig=\"{0}\", date=\"{1}\"", Convert.ToBase64String(signature), date));
}
return message;
}