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


C# DreamMessage.ToText方法代码示例

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


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

示例1: Call

 public void Call(string verb, XUri uri, DreamMessage request)
 {
     _called = true;
     if(_autoInvokeDelegate != null) {
         DreamMessage response;
         string failure;
         if(!_autoInvokeDelegate(verb, uri, request, out response, out failure)) {
             AddFailure(failure);
         } else {
             _response = response;
         }
     }
     if(_expectedVerb != null && _expectedVerb != verb) {
         AddFailure("Expected verb '{0}', got '{1}'", _expectedVerb, verb);
     }
     if(_expectedUri != null && _expectedUri != uri) {
         AddFailure("Uri:\r\nExpected: {0}\r\nGot:      {1}", _expectedUri, uri);
     }
     if(_expectedRequest != null) {
         if(request.Status != _expectedRequest.Status) {
             AddFailure("Status:\r\nExpected: {0}\r\nGot:      {1}", _expectedRequest.Status, request.Status);
         } else if(!request.ContentType.Match(_expectedRequest.ContentType)) {
             AddFailure("Content type:\r\nExpected: {0}\r\nGot:      {1}", _expectedRequest.ContentType, request.ContentType);
         } else if(!StringUtil.EqualsInvariant(request.ToText(), _expectedRequest.ToText())) {
             AddFailure("Content:\r\nExpected: {0}\r\nGot:      {1}", _expectedRequest.ToText(), request.ToText());
         }
     } else if(_expectedRequestDocCallback == null) {
         if(!request.HasDocument && _expectedRequestDoc != null) {
             AddFailure("Expected a document in request, got none");
         } else if(request.HasDocument && _expectedRequestDoc != null && _expectedRequestDoc != request.ToDocument()) {
             AddFailure("Content:\r\nExpected: {0}\r\nGot:      {1}", _expectedRequestDoc.ToString(), request.ToText());
         }
     } else {
         if(!request.HasDocument) {
             AddFailure("Expected a document in request, got none for callback");
         } else if(request.HasDocument && !_expectedRequestDocCallback(request.ToDocument())) {
             AddFailure("Request document'{0}', failed callback check", request.ToDocument());
         }
     }
     if(_expectedRequestHeaders.Count > 0) {
         Dictionary<string, string> headers = new Dictionary<string, string>();
         foreach(KeyValuePair<string, string> header in request.Headers) {
             if(_expectedRequestHeaders.ContainsKey(header.Key) && _expectedRequestHeaders[header.Key] != header.Value) {
                 AddFailure("Expected header '{0}:\r\nExpected: {1}\r\nGot:      {2}", header.Key, _expectedRequestHeaders[header.Key], header.Value);
             }
             headers[header.Key] = header.Value;
         }
         foreach(KeyValuePair<string, string> header in _expectedRequestHeaders) {
             if(!headers.ContainsKey(header.Key)) {
                 AddFailure("Expected header '{0}', got none", header.Key);
             }
         }
     }
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:54,代码来源:MockPlug.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: DispatchCompletion_Helper

        private void DispatchCompletion_Helper(DispatchItem destination, DreamMessage response, Result<bool> result)
        {
            PubSubSubscriptionSet set;
            lock(_subscriptionsByOwner) {
                if(!_subscriptionByLocation.TryGetValue(destination.Location, out set)) {
                    _log.DebugFormat("the subscription at location '{0}' no longer exists, dropping event '{1}' ", destination.Location, destination.Event.Id);
                    result.Return(true);
                    return;
                }
            }
            if(set.UsesFailureDuration) {
                if(response.IsSuccessful || response.Status == DreamStatus.NotModified) {
                    result.Return(true);
                    return;
                }
                var queue = _queueRepository[set];
                if(queue == null) {
                    _log.DebugFormat("the dispatch queue for subscription at location '{0}' no longer exists, dropping event '{1}' ", destination.Location, destination.Event.Id);
                    result.Return(true);
                    return;
                }
                if(queue.FailureWindow > set.MaxFailureDuration) {
                    _log.DebugFormat("the destination has failed continously for {0} and had an expiration failure window of {1}. The subscription at location '{2}' has been dropped, as has event '{3}'",
                        queue.FailureWindow,
                        set.MaxFailureDuration,
                        destination.Location,
                        destination.Event.Id
                    );
                    RemoveSet(set.Location);
                    result.Return(true);
                    return;
                }
                result.Return(false);
                return;
            }
            if(response.IsSuccessful || response.Status == DreamStatus.NotModified) {
                // if the post was a success, or didn't affect a change, clear any failure count
                lock(_dispatchFailuresByLocation) {
                    if(_log.IsDebugEnabled) {
                        if(_dispatchFailuresByLocation.ContainsKey(destination.Location)) {
                            _log.Debug("zeroing out existing error count");
                        }
                    }
                    _dispatchFailuresByLocation.Remove(destination.Location);
                }
            } else {

                // post was a failure, increase consecutive failures
                if(_log.IsWarnEnabled) {
                    _log.WarnFormat("event dispatch to '{0}' failed: {1} - {2}", destination, response.Status, response.ToText());
                }
                lock(_dispatchFailuresByLocation) {

                    // NOTE (arnec): using ContainsKey instead of TryGetValue, since we're incrementing a value type in place
                    if(!_dispatchFailuresByLocation.ContainsKey(destination.Location)) {
                        _dispatchFailuresByLocation.Add(destination.Location, 1);
                    } else {
                        _dispatchFailuresByLocation[destination.Location]++;
                    }
                    var failures = _dispatchFailuresByLocation[destination.Location];
                    _log.DebugFormat("failure {0} out of {1} for set at location {2}", failures, set.MaxFailures, destination.Location);

                    // kick out a subscription set if one of its subscriptions fails too many times
                    if(failures > set.MaxFailures) {
                        _log.DebugFormat("exceeded max failures, kicking set at '{0}'", set.Location);
                        RemoveSet(destination.Location);
                    }
                }
            }

            // Note (arnec): max-failure sets always "succeed" at dispatch since their queues are not kept around
            result.Return(true);
        }
开发者ID:sdether,项目名称:DReAM,代码行数:73,代码来源:Dispatcher.cs


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