本文整理汇总了C#中MindTouch.Dream.Plug.InvokeEx方法的典型用法代码示例。如果您正苦于以下问题:C# Plug.InvokeEx方法的具体用法?C# Plug.InvokeEx怎么用?C# Plug.InvokeEx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MindTouch.Dream.Plug
的用法示例。
在下文中一共展示了Plug.InvokeEx方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: InvokeEx
/// <summary>
/// Invoke the plug, but leave the stream unread so that the returned <see cref="DreamMessage"/> can be streamed.
/// </summary>
/// <param name="verb">Request verb.</param>
/// <param name="request">Request message.</param>
/// <param name="result">The <see cref="Result{DreamMessage}"/>instance to be returned by this method.</param>
/// <returns>Synchronization handle.</returns>
public Result<DreamMessage> InvokeEx(string verb, DreamMessage request, Result<DreamMessage> result) {
if(verb == null) {
throw new ArgumentNullException("verb");
}
if(request == null) {
throw new ArgumentNullException("request");
}
if(request.Status != DreamStatus.Ok) {
throw new ArgumentException("request status must be 200 (Ok)");
}
if(result == null) {
throw new ArgumentNullException("response");
}
// determine which factory has the best match
IPlugEndpoint match;
XUri normalizedUri;
FindPlugEndpoint(Uri, out match, out normalizedUri);
// check if we found a match
if(match == null) {
request.Close();
result.Return(new DreamMessage(DreamStatus.NoEndpointFound, null, XDoc.Empty));
return result;
}
// add matching cookies from service or from global cookie jar
DreamCookieJar cookies = CookieJar;
// prepare request
try {
request = PreProcess(verb, Uri, normalizedUri, _headers, cookies, request);
// check if custom pre-processing handlers are registered
if(_preHandlers != null) {
foreach(var handler in _preHandlers) {
request = handler(verb, Uri, normalizedUri, request) ?? new DreamMessage(DreamStatus.RequestIsNull, null, XDoc.Empty);
if(request.Status != DreamStatus.Ok) {
result.Return(request);
return result;
}
}
}
} catch(Exception e) {
request.Close();
result.Return(new DreamMessage(DreamStatus.RequestFailed, null, new XException(e)));
return result;
}
// Note (arnec): Plug never throws, so we usurp the passed result if it has a timeout
// setting the result timeout on inner result manually
var outerTimeout = result.Timeout;
if(outerTimeout != TimeSpan.MaxValue) {
result.Timeout = TimeSpan.MaxValue;
}
// if the governing result has a shorter timeout than the plug, it superceeds the plug timeout
var timeout = outerTimeout < Timeout ? outerTimeout : Timeout;
// prepare response handler
var inner = new Result<DreamMessage>(timeout, TaskEnv.None).WhenDone(
v => {
try {
var message = PostProcess(verb, Uri, normalizedUri, _headers, cookies, v);
// check if custom post-processing handlers are registered
if((message.Status == DreamStatus.MovedPermanently ||
message.Status == DreamStatus.Found ||
message.Status == DreamStatus.TemporaryRedirect) &&
AutoRedirect &&
request.IsCloneable
) {
var redirectPlug = new Plug(message.Headers.Location, Timeout, Headers, null, null, null, CookieJar, (ushort)(MaxAutoRedirects - 1));
var redirectMessage = request.Clone();
request.Close();
redirectPlug.InvokeEx(verb, redirectMessage, new Result<DreamMessage>()).WhenDone(result.Return);
} else {
request.Close();
if(_postHandlers != null) {
foreach(var handler in _postHandlers) {
message = handler(verb, Uri, normalizedUri, message) ?? new DreamMessage(DreamStatus.ResponseIsNull, null, XDoc.Empty);
}
}
result.Return(message);
}
} catch(Exception e) {
request.Close();
result.Return(new DreamMessage(DreamStatus.ResponseFailed, null, new XException(e)));
}
},
e => {
// an exception occurred somewhere during processing (not expected, but it could happen)
//.........这里部分代码省略.........