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


C# Plug.WithHeader方法代码示例

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


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

示例1: Invoke

        public Yield Invoke(Plug plug, string verb, XUri uri, DreamMessage request, Result<DreamMessage> response)
        {
            // NOTE (steveb): we convert 'xri://@name/path?params' into 'http://xri.net/@name/path?params'

            // prepend segments with authority
            List<string> segments = new List<string>();
            segments.Add(uri.Authority);
            if(uri.Segments != null) {
                segments.AddRange(uri.Segments);
            }

            // build new plug
            List<PlugHandler> preHandlers = (plug.PreHandlers != null) ? new List<PlugHandler>(plug.PreHandlers) : null;
            List<PlugHandler> postHandlers = (plug.PostHandlers != null) ? new List<PlugHandler>(plug.PostHandlers) : null;
            Plug xri = new Plug(new XUri("http", null, null, "xri.net", 80, segments.ToArray(), uri.TrailingSlash, uri.Params, uri.Fragment), plug.Timeout, request.Headers, preHandlers, postHandlers, plug.Credentials, plug.CookieJar, plug.MaxAutoRedirects);

            // add 'Accept' header for 'application/xrds+xml' mime-type
            if((xri.Headers == null) || (xri.Headers.Accept == null)) {
                xri = xri.WithHeader(DreamHeaders.ACCEPT, MimeType.RenderAcceptHeader(MimeType.XRDS));
            }

            // BUGBUGBUG (steveb): this will probably fail in some cases since we may exit this coroutine before the call has completed!

            xri.InvokeEx(verb, request, response);
            yield break;
        }
开发者ID:maximmass,项目名称:DReAM,代码行数:26,代码来源:XriPlugEndpoint.cs

示例2: AuthenticateImportUser

 private IEnumerator<IYield> AuthenticateImportUser(Plug api, string wikiId, string apikey, Result<Plug> result) {
     XDoc settings = null;
     yield return api.At("site", "settings").With("apikey", apikey).GetAsync().Set(x => settings = x.ToDocument());
     var username = settings["packageupdater/username"].AsText ?? settings["security/admin-user-for-impersonation"].AsText;
     string authToken = null;
     if(string.IsNullOrEmpty(username)) {
         _log.DebugFormat("[{0}] no user in 'packageupdater/username' config key, trying 'admin'", wikiId);
         username = "admin";
         yield return Coroutine.Invoke(Authenticate, api, username, apikey, new Result<string>()).Set(x => authToken = x);
         if(string.IsNullOrEmpty(authToken)) {
             _log.DebugFormat("[{0}] 'admin' didn't authenticate, trying 'sysop'", wikiId);
             username = "sysop";
         }
     }
     if(string.IsNullOrEmpty(authToken)) {
         _log.DebugFormat("[{0}] authenticating as '{1}'", wikiId, username);
         yield return Coroutine.Invoke(Authenticate, api, username, apikey, new Result<string>()).Set(x => authToken = x);
     }
     if(string.IsNullOrEmpty(authToken)) {
         throw new UnauthorizedAccessException(string.Format("Unable to authenticate as '{0}'", username));
     }
     result.Return(api.WithHeader(DekiWikiService.AUTHTOKEN_HEADERNAME, authToken));
 }
开发者ID:heran,项目名称:DekiWiki,代码行数:23,代码来源:PackageUpdater.cs

示例3: SubscribeIndexer

        private Yield SubscribeIndexer(Plug pubsubPlug, Result result) {
            _log.DebugFormat("subscribing indexer to pubsub {0}", pubsubPlug.Uri.ToString());
            var subscriptionSet = new XDoc("subscription-set")
                 .Elem("uri.owner", Self.Uri)
                 .Start("subscription")
                     .Add(DreamCookie.NewSetCookie("service-key", InternalAccessKey, Self.Uri).AsSetCookieDocument)
                     .Elem("channel", "event://*/deki/pages/noop")
                     .Elem("channel", "event://*/deki/pages/create")
                     .Elem("channel", "event://*/deki/pages/move")
                     .Elem("channel", "event://*/deki/pages/update")
                     .Elem("channel", "event://*/deki/pages/delete")
                     .Elem("channel", "event://*/deki/pages/revert")
                     .Elem("channel", "event://*/deki/pages/rated")
                     .Elem("channel", "event://*/deki/pages/createalias")
                     .Elem("channel", "event://*/deki/pages/tags/update")
                     .Elem("channel", "event://*/deki/pages/dependentschanged/properties/*")
                     .Elem("channel", "event://*/deki/files/noop")
                     .Elem("channel", "event://*/deki/files/create")
                     .Elem("channel", "event://*/deki/files/update")
                     .Elem("channel", "event://*/deki/files/delete")
                     .Elem("channel", "event://*/deki/files/move")
                     .Elem("channel", "event://*/deki/files/restore")
                     .Elem("channel", "event://*/deki/comments/noop")
                     .Elem("channel", "event://*/deki/comments/create")
                     .Elem("channel", "event://*/deki/comments/update")
                     .Elem("channel", "event://*/deki/comments/delete")
                     .Elem("channel", "event://*/deki/users/dependentschanged/properties/*")
                     .Elem("channel", "event://*/deki/users/create")
                     .Elem("channel", "event://*/deki/users/update")
                     .Elem("channel", "event://*/deki/users/login")
                     .Start("recipient")
                         .Attr("authtoken", _apikey)
                         .Elem("uri", Self.Uri.At("queue"))
                     .End()
                 .End();
            if(_usePersistentSubscription) {
                var locationKey = StringUtil.ComputeHashString(pubsubPlug.Uri.AsPublicUri().WithoutQuery() + InternalAccessKey);
                var accessKey = StringUtil.ComputeHashString(InternalAccessKey);
                subscriptionSet.Attr("max-failure-duration", _subscriptionMaxFailureDuration);
                pubsubPlug = pubsubPlug.WithHeader("X-Set-Access-Key", accessKey).WithHeader("X-Set-Location-Key", locationKey);
            }
            DreamMessage subscription = null;
            yield return pubsubPlug.At("subscribers").PostAsync(subscriptionSet).Set(x => subscription = x);

            // only care about created responses, but log other failures
            switch(subscription.Status) {
            case DreamStatus.Created: {
                    var accessKey = subscription.ToDocument()["access-key"].AsText;
                    var location = subscription.Headers.Location;
                    Cookies.Update(DreamCookie.NewSetCookie("access-key", accessKey, location), null);
                    _subscriptionLocation = location.AsLocalUri().WithoutQuery();
                    _log.DebugFormat("subscribed indexer for events at {0}", _subscriptionLocation);
                    break;
                }
            case DreamStatus.Conflict:
                _log.DebugFormat("didn't subscribe, since we already had a subscription in place");
                break;
            default:
                _log.WarnFormat("subscribe to {0} failed: {1}", pubsubPlug.Uri.ToString(), subscription.Status);
                break;
            }
            result.Return();
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:63,代码来源:LuceneService.cs


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