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


C# DreamMessage.Clone方法代码示例

本文整理汇总了C#中DreamMessage.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# DreamMessage.Clone方法的具体用法?C# DreamMessage.Clone怎么用?C# DreamMessage.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DreamMessage的用法示例。


在下文中一共展示了DreamMessage.Clone方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Can_clone_a_memory_stream_message

 public void Can_clone_a_memory_stream_message()
 {
     var text = "blah";
     var stream = new MemoryStream();
     var writer = new StreamWriter(stream);
     writer.Write(text);
     writer.Flush();
     stream.Position = 0;
     var m = new DreamMessage(DreamStatus.Ok, new DreamHeaders().Add("foo", "bar"), MimeType.TEXT, stream.Length, stream);
     m.Headers.Add("baz", "blah");
     _log.Debug("about to clone");
     var m2 = m.Clone();
     var reader = new StreamReader(m2.ToStream());
     Assert.AreEqual(text, reader.ReadToEnd());
     Assert.AreEqual(m.ContentType.ToString(), m2.ContentType.ToString());
     Assert.AreEqual(m.Headers["foo"], m2.Headers["foo"]);
     Assert.AreEqual(m.Headers["baz"], m2.Headers["baz"]);
 }
开发者ID:sdether,项目名称:DReAM,代码行数:18,代码来源:DreamMessageTests.cs

示例2: Can_clone_no_content_message

 public void Can_clone_no_content_message()
 {
     var m = new DreamMessage(DreamStatus.Ok, new DreamHeaders().Add("foo", "bar"));
     m.Headers.Add("baz", "blah");
     var m2 = m.Clone();
     Assert.AreEqual(m.ToText(), m2.ToText());
     Assert.AreEqual(m.Headers["foo"], m2.Headers["foo"]);
     Assert.AreEqual(m.Headers["baz"], m2.Headers["baz"]);
 }
开发者ID:sdether,项目名称:DReAM,代码行数:9,代码来源:DreamMessageTests.cs

示例3: Can_clone_xdoc_message

 public void Can_clone_xdoc_message()
 {
     var m = new DreamMessage(DreamStatus.Ok, new DreamHeaders().Add("foo", "bar"), new XDoc("doc"));
     m.Headers.Add("baz", "blah");
     var m2 = m.Clone();
     Assert.AreEqual(m.ToDocument().ToCompactString(), m2.ToDocument().ToCompactString());
     Assert.AreEqual(m.Headers["foo"], m2.Headers["foo"]);
     Assert.AreEqual(m.Headers["baz"], m2.Headers["baz"]);
 }
开发者ID:sdether,项目名称:DReAM,代码行数:9,代码来源:DreamMessageTests.cs

示例4: Can_clone_byte_message

 public void Can_clone_byte_message()
 {
     var m = new DreamMessage(DreamStatus.Ok, new DreamHeaders().Add("foo", "bar"), MimeType.TIFF, new byte[] { 1, 2, 3, 4 });
     m.Headers.Add("baz", "blah");
     var m2 = m.Clone();
     Assert.AreEqual(m.ToBytes(), m2.ToBytes());
     Assert.AreEqual(m.ContentType.ToString(), m2.ContentType.ToString());
     Assert.AreEqual(m.Headers["foo"], m2.Headers["foo"]);
     Assert.AreEqual(m.Headers["baz"], m2.Headers["baz"]);
 }
开发者ID:sdether,项目名称:DReAM,代码行数:10,代码来源:DreamMessageTests.cs

示例5: Can_clone_a_null_stream_message

 public void Can_clone_a_null_stream_message()
 {
     var m = new DreamMessage(DreamStatus.Ok, new DreamHeaders().Add("foo", "bar"), MimeType.TEXT, Stream.Null.Length, Stream.Null);
     m.Headers.Add("baz", "blah");
     var m2 = m.Clone();
     Assert.AreEqual(0, m2.ContentLength);
     Assert.AreEqual(m.ContentType.ToString(), m2.ContentType.ToString());
     Assert.AreEqual(m.Headers["foo"], m2.Headers["foo"]);
     Assert.AreEqual(m.Headers["baz"], m2.Headers["baz"]);
 }
开发者ID:sdether,项目名称:DReAM,代码行数:10,代码来源:DreamMessageTests.cs

示例6: MemorizeAndClone

 private DreamMessage MemorizeAndClone(DreamMessage request)
 {
     return request.IsCloneable ? request.Clone() : new DreamMessage(request.Status,request.Headers,request.ContentType,request.ToBytes());
 }
开发者ID:nataren,项目名称:DReAM,代码行数:4,代码来源:MockEndpoint.cs

示例7: DispatcherEvent

        //--- Constructors ---
        /// <summary>
        /// Create a new event from a dream message.
        /// </summary>
        /// <param name="message">Message to parse.</param>
        public DispatcherEvent(DreamMessage message)
        {
            // sanity check the input
            string[] origins = message.Headers.DreamEventOrigin;
            if(origins.Length == 0) {
                throw new DreamBadRequestException(string.Format("message must specify at least one DreamEventOrigin header"));
            }
            if(string.IsNullOrEmpty(message.Headers.DreamEventChannel)) {
                throw new DreamBadRequestException("message must have exactly one DreamEventChannel header");
            }

            // parse message
            _message = message.Clone();
            Channel = new XUri(_message.Headers.DreamEventChannel);
            if(!string.IsNullOrEmpty(_message.Headers.DreamEventResource)) {
                Resource = new XUri(_message.Headers.DreamEventResource);
            }
            List<XUri> originList = new List<XUri>();
            foreach(string origin in origins) {
                originList.Add(new XUri(origin));
            }
            Origins = originList.ToArray();
            List<DispatcherRecipient> recipientList = new List<DispatcherRecipient>();
            foreach(string recipient in _message.Headers.DreamEventRecipients) {
                recipientList.Add(new DispatcherRecipient(new XUri(recipient)));
            }
            Recipients = recipientList.ToArray();
            List<XUri> viaList = new List<XUri>();
            foreach(string via in _message.Headers.DreamEventVia) {
                viaList.Add(new XUri(via));
            }
            Via = viaList.ToArray();
            // attach an Id, if one does not exist
            Id = message.Headers.DreamEventId;
            if(string.IsNullOrEmpty(Id)) {
                Id = Guid.NewGuid().ToString();
            }
        }
开发者ID:maximmass,项目名称:DReAM,代码行数:43,代码来源:DispatcherEvent.cs

示例8: Invoke

 public IEnumerator<IYield> Invoke(Plug plug, string verb, XUri uri, DreamMessage request, Result<DreamMessage> response)
 {
     MockPlug.MockInvokeDelegate callback;
     var match = GetBestMatch(uri);
     if(match.Item1 == null) {
         response.Return(DreamMessage.Ok(new XDoc("empty")));
         yield break;
     }
     lock(_registry) {
         callback = _registry[match.Item1];
     }
     yield return Async.Fork(() => callback(plug, verb, uri, request.Clone(), response), new Result(TimeSpan.MaxValue));
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:13,代码来源:MockEndpoint.cs


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