当前位置: 首页>>代码示例>>C#>>正文


C# DreamMessage.ToBytes方法代码示例

本文整理汇总了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();
        }
开发者ID:maximmass,项目名称:DReAM,代码行数:48,代码来源:XTypes.cs

示例2: GetRequestAsBytes

 private static object GetRequestAsBytes(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     return request.ToBytes();
 }
开发者ID:aaronmars,项目名称:DReAM,代码行数:4,代码来源:DreamFeatureStage.cs

示例3: PostConvert

 internal Yield PostConvert(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     response.Return(DreamMessage.Ok(request.ContentType, request.ToBytes()));
     yield break;
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:5,代码来源:DreamHostService.cs

示例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;
        }
开发者ID:nataren,项目名称:DReAM,代码行数:7,代码来源:DreamHostService.cs

示例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;
        }
开发者ID:sdether,项目名称:DReAM,代码行数:49,代码来源:DreamAPITest.cs


注:本文中的MindTouch.Dream.DreamMessage.ToBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。