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


C# DreamMessage.ToDocument方法代码示例

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


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

示例1: 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

示例2: SyncMessage

 public DreamMessage SyncMessage(DreamMessage request)
 {
     return Response(request.ToDocument());
 }
开发者ID:aaronmars,项目名称:DReAM,代码行数:4,代码来源:DreamFeatureTests.cs

示例3: PostEntries

        internal Yield PostEntries(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            if(request.ToDocument().Name != "entry") {
                throw new DreamBadRequestException("invalid format");
            }

            // prepare entry
            XAtomEntry entry = new XAtomEntry(request.ToDocument());
            int number = System.Threading.Interlocked.Increment(ref _counter);
            XUri link = Self.At(number.ToString());
            entry.Id = link;
            entry.AddLink(link, XAtomBase.LinkRelation.Edit, null, 0, null);

            // update feed
            XAtomFeed feed = _feed;
            if(feed != null) {
                lock(feed) {
                    feed.Add(entry);
                }
            } else {
                throw new DreamBadRequestException("not initialized");
            }

            // schedule entry deletion
            double seconds = context.GetParam<double>("ttl", _defaultTTL);
            if(seconds > 0) {
                TimerFactory.New(TimeSpan.FromSeconds(seconds), AutoDeletePost, number, TaskEnv.Clone());
            }

            // return updated entry
            response.Return(DreamMessage.Created(link, entry));
            yield break;
        }
开发者ID:maximmass,项目名称:DReAM,代码行数:33,代码来源:atomservice.cs

示例4: PutEntry

        internal Yield PutEntry(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            if(request.ToDocument().Name != "entry") {
                throw new DreamBadRequestException("invalid format");
            }
            string id = context.GetParam("id");

            // prepare entry
            XAtomEntry entry = new XAtomEntry(request.ToDocument());
            XUri link = Self.At(id);
            entry.Id = link;
            entry.AddLink(link, XAtomBase.LinkRelation.Edit, null, 0, null);

            // update feed
            XAtomFeed feed = _feed;
            XAtomEntry oldEntry;
            if(feed != null) {
                lock(feed) {
                    oldEntry = new XAtomEntry(feed[string.Format("entry[id='{0}']", link)]);
                    if(!oldEntry.IsEmpty) {
                        oldEntry.Replace(entry);
                    }
                }
            } else {
                throw new DreamBadRequestException("not initialized");
            }
            if(oldEntry.IsEmpty) {
                response.Return(DreamMessage.NotFound("entry not found"));
            } else {
                response.Return(DreamMessage.Ok(MimeType.ATOM, entry));
            }
            yield break;
        }
开发者ID:maximmass,项目名称:DReAM,代码行数:33,代码来源:atomservice.cs

示例5: GetMatchScore

 //--- Methods ---
 private int GetMatchScore(string verb, XUri uri, DreamMessage request)
 {
     var score = 0;
     if(verb.EqualsInvariantIgnoreCase(_verb)) {
         score = 1;
     } else if(_verb != "*") {
         return 0;
     }
     var path = _matchTrailingSlashes ? _uri.Path : _uri.WithoutTrailingSlash().Path;
     var incomingPath = _matchTrailingSlashes ? uri.Path : uri.WithoutTrailingSlash().Path;
     if(!incomingPath.EqualsInvariantIgnoreCase(path)) {
         return 0;
     }
     score++;
     if(_uri.Params != null) {
         foreach(var param in _uri.Params) {
             var v = uri.GetParam(param.Key);
             if(v == null || !v.EndsWithInvariantIgnoreCase(param.Value)) {
                 return 0;
             }
             score++;
         }
     }
     foreach(var matcher in _queryMatchers) {
         var v = uri.GetParam(matcher.Item1);
         if(v == null || !matcher.Item2(v)) {
             return 0;
         }
         score++;
     }
     foreach(var matcher in _headerMatchers) {
         var v = request.Headers[matcher.Item1];
         if(string.IsNullOrEmpty(v) || !matcher.Item2(v)) {
             return 0;
         }
         score++;
     }
     foreach(var header in _headers) {
         var v = request.Headers[header.Key];
         if(string.IsNullOrEmpty(v) || !v.EqualsInvariant(header.Value)) {
             return 0;
         }
         score++;
     }
     if(_requestCallback != null) {
         if(!_requestCallback(request)) {
             return 0;
         }
     } else if(_request != null && (!request.HasDocument || _request != request.ToDocument())) {
         return 0;
     }
     score++;
     return score;
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:55,代码来源:MockPlug.cs

示例6: 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

示例7: CreateSubscriptionSet

        internal Yield CreateSubscriptionSet(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            var subscriptionSet = request.ToDocument();
            var location = request.Headers["X-Set-Location-Key"] ?? StringUtil.CreateAlphaNumericKey(8);
            var accessKey = request.Headers["X-Set-Access-Key"] ?? StringUtil.CreateAlphaNumericKey(8);
            var set = _dispatcher.RegisterSet(location, subscriptionSet, accessKey);
            var locationUri = Self.At("subscribers", set.Item1.Location).Uri.AsPublicUri();
            DreamMessage msg = null;
            if(set.Item2) {

                // existing subs cause a Conflict with ContentLocation of the sub
                msg = DreamMessage.Conflict("The specified owner or location already has a registered subscription set");
                msg.Headers.ContentLocation = locationUri;
            } else {

                // new subs cause a Created with Location of the sub, plus XDoc containing the location
                var responseDoc = new XDoc("subscription-set")
                    .Elem("uri.location", locationUri)
                    .Elem("access-key", set.Item1.AccessKey);
                msg = DreamMessage.Created(locationUri, responseDoc);
                msg.Headers.Location = locationUri.With("access-key", set.Item1.AccessKey);
            }
            response.Return(msg);
            yield break;
        }
开发者ID:sdether,项目名称:DReAM,代码行数:25,代码来源:PubSubService.cs

示例8: PutRecord

        public Yield PutRecord(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            DirectoryRecord record = new DirectoryRecord();
            record.Name = context.GetSuffix(0, UriPathFormat.Normalized);
            record.Value = request.ToDocument();
            int ttl = context.GetParam<int>(TIME_TO_LIVE, -1);
            if(ttl >= 0) {
                record.Expiration = DateTime.UtcNow.AddSeconds(ttl);
            }

            // add value to directory
            InsertRecord(record);
            response.Return(DreamMessage.Ok());
            yield break;
        }
开发者ID:sdether,项目名称:DReAM,代码行数:15,代码来源:directoryservice.cs

示例9: CheckResponse

 private void CheckResponse(DreamMessage message)
 {
     if(message.IsSuccessful) {
         return;
     }
     Assert.Fail(message.ToDocument()["message"].AsText);
 }
开发者ID:heran,项目名称:DReAM,代码行数:7,代码来源:ContainerTests.cs

示例10: ReplaceSubscribeSet

 protected Yield ReplaceSubscribeSet(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     DreamMessage responseMsg = null;
     try {
         var location = context.GetParam("location");
         if(!string.IsNullOrEmpty(request.Headers.DreamEventId)) {
             _log.DebugFormat("'{0}' update is event: {1} - {2}", location, request.Headers.DreamEventChannel, request.Headers.DreamEventId);
         }
         var subscriptionDocument = request.ToDocument();
         var accessKey = request.Headers["X-Set-Access-Key"];
         var set = _dispatcher.ReplaceSet(location, subscriptionDocument, accessKey);
         _log.DebugFormat("Trying to update set {0}", location);
         if(set != null) {
             var version = subscriptionDocument["@version"].AsLong;
             if(version.HasValue && version.Value <= set.Version) {
                 _log.DebugFormat("set not modified: {0}", location);
                 responseMsg = DreamMessage.NotModified();
             } else {
                 if(version.HasValue) {
                     _log.DebugFormat("Updating set '{0}' from version {1} to {2}", location, set.Version, version);
                 } else {
                     _log.DebugFormat("Updating set '{0}'", location);
                 }
                 responseMsg = DreamMessage.Ok();
             }
         } else {
             _log.DebugFormat("no such set: {0}", location);
             responseMsg = DreamMessage.NotFound("There is no subscription set at this location");
         }
     } catch(ArgumentException e) {
         responseMsg = DreamMessage.Forbidden(e.Message);
     }
     response.Return(responseMsg);
     yield break;
 }
开发者ID:sdether,项目名称:DReAM,代码行数:35,代码来源:PubSubService.cs

示例11: CreateSubscriptionSet

        internal Yield CreateSubscriptionSet(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            XDoc subscriptionSet = request.ToDocument();
            Tuplet<PubSubSubscriptionSet, bool> set = _dispatcher.RegisterSet(subscriptionSet);
            XUri locationUri = Self.At("subscribers", set.Item1.Location).Uri.AsPublicUri();
            DreamMessage msg = null;
            if(set.Item2) {

                // existing subs cause a Conflict with ContentLocation of the sub
                msg = DreamMessage.Conflict("The specified owner already has a registered subscription set");
                msg.Headers.ContentLocation = locationUri;
            } else {

                // new subs cause a Created with Location of the sub, plus XDoc containing the location
                XDoc responseDoc = new XDoc("subscription-set")
                    .Elem("uri.location", locationUri)
                    .Elem("access-key", set.Item1.AccessKey);
                msg = DreamMessage.Created(locationUri, responseDoc);
                msg.Headers.Location = locationUri.With("access-key", set.Item1.AccessKey);
            }
            response.Return(msg);
            yield break;
        }
开发者ID:yurigorokhov,项目名称:DReAM,代码行数:23,代码来源:PubSubService.cs

示例12: ReplaceSubscribeSet

 protected Yield ReplaceSubscribeSet(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     try {
         string setId = context.GetParam("id");
         _log.DebugFormat("Updating set {0}", setId);
         if(!string.IsNullOrEmpty(request.Headers.DreamEventId)) {
             _log.DebugFormat("'{0}' update is event: {1} - {2}", setId, request.Headers.DreamEventChannel, request.Headers.DreamEventId);
         }
         XDoc subscriptionDocument = request.ToDocument();
         PubSubSubscriptionSet set = _dispatcher.ReplaceSet(setId, subscriptionDocument);
         if(set != null) {
             long? version = subscriptionDocument["@version"].AsLong;
             if(version.HasValue && version.Value <= set.Version) {
                 _log.DebugFormat("set not modified: {0}", setId);
                 response.Return(DreamMessage.NotModified());
             } else {
                 if(version.HasValue) {
                     _log.DebugFormat("Updating set '{0}' from version {1} to {2}", setId, set.Version, version);
                 } else {
                     _log.DebugFormat("Updating set '{0}'", setId);
                 }
                 response.Return(DreamMessage.Ok());
             }
         } else {
             _log.DebugFormat("no such set: {0}", setId);
             response.Return(DreamMessage.NotFound("There is no subscription set at this location"));
         }
     } catch(ArgumentException e) {
         response.Return(DreamMessage.Forbidden(e.Message));
     }
     yield break;
 }
开发者ID:yurigorokhov,项目名称:DReAM,代码行数:32,代码来源:PubSubService.cs

示例13: Update

 public Yield Update(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     XDoc update = request.ToDocument();
     switch(update.Name.ToLowerInvariant()) {
     case "insert":
         DirectoryRecord record = new DirectoryRecord();
         record.Name = update["@name"].Contents;
         record.Expiration = update["@expire"].AsDate ?? DateTime.MaxValue;
         record.Value = update[0];
         InsertRecord(record);
         break;
     case "delete":
         string name = update["@name"].Contents;
         DeleteRecord(name);
         break;
     }
     response.Return(DreamMessage.Ok());
     yield break;
 }
开发者ID:sdether,项目名称:DReAM,代码行数:19,代码来源:directoryservice.cs

示例14: ConfigureSmtp

        internal Yield ConfigureSmtp(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            var configuration = context.GetParam("configuration");
            var settingsDoc = request.ToDocument();
            _log.DebugFormat("configuring settings for configuration '{0}'", configuration);
            var host = settingsDoc["smtp-host"].AsText;
            var apikey = settingsDoc["apikey"].AsText;
            if(string.IsNullOrEmpty(host) && string.IsNullOrEmpty(apikey)) {
                response.Return(DreamMessage.BadRequest("must specify either new smtp config with a host or specify an apikey"));
                yield break;
            }
            SmtpSettings settings;
            if(string.IsNullOrEmpty(host)) {
                settings = new SmtpSettings() {
                    Host = _defaultSettings.Host,
                    Apikey = apikey,
                    AuthPassword = _defaultSettings.AuthPassword,
                    AuthUser = _defaultSettings.AuthUser,
                    EnableSsl = _defaultSettings.EnableSsl,
                    Port = _defaultSettings.Port,
                };
            } else {
                _log.DebugFormat("Smtp Host: {0}", host);
                settings = new SmtpSettings {
                    Host = host,
                    AuthUser = settingsDoc["smtp-auth-user"].AsText,
                    AuthPassword = settingsDoc["smtp-auth-password"].AsText,
                    Apikey = apikey,

                    // Note (arnec): ssl requires mono 2.0 and likely root certificate import via 'mozroots --import --ask-remove --machine'
                    EnableSsl = settingsDoc["use-ssl"].AsBool ?? false
                };
                if(settingsDoc["smtp-port"].AsInt.HasValue) {
                    settings.Port = settingsDoc["smtp-port"].AsInt.Value;
                }
            }
                lock(_smtpSettings) {
                    _smtpSettings[configuration] = settings;
                }
            response.Return(DreamMessage.Ok());
            yield break;
        }
开发者ID:aaronmars,项目名称:DReAM,代码行数:42,代码来源:EmailService.cs

示例15: Invoke

 private void Invoke(Dream.Plug plug, string verb, XUri uri, DreamMessage request, Result<DreamMessage> response)
 {
     lock(this) {
         if(_failed) {
             _log.DebugFormat("we've already failed, no point checking more expectations");
             response.Return(DreamMessage.InternalError());
             return;
         }
         _log.DebugFormat("{0}={1}", verb, uri);
         XDoc requestDoc = request.HasDocument ? request.ToDocument() : null;
         if(_expectations.Count == _current) {
             _log.DebugFormat("excess");
             ExcessInterception excess = new ExcessInterception();
             _excess.Add(excess);
             ;
             response.Return(excess.Call(verb, uri, requestDoc));
             return;
         }
         AutoMockInvokeExpectation expectation = _expectations[_current];
         expectation.Call(verb, uri, request);
         if(!expectation.Verify()) {
             AddFailure(_expectations[_current].VerificationFailure);
             _log.DebugFormat("got failure, setting reset event ({0})", _current);
             _failed = true;
             _resetEvent.Set();
             response.Return(DreamMessage.BadRequest("expectation failure"));
             return;
         }
         _current++;
         _log.DebugFormat("expected");
         if(_expectations.Count == _current) {
             _log.DebugFormat("setting reset event");
             _resetEvent.Set();
         }
         response.Return(expectation.GetResponse());
     }
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:37,代码来源:MockPlug.cs


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