本文整理匯總了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;
}