本文整理汇总了C#中System.Action.TryInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# Action.TryInvoke方法的具体用法?C# Action.TryInvoke怎么用?C# Action.TryInvoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Action
的用法示例。
在下文中一共展示了Action.TryInvoke方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformRequest
/// <summary>
/// Performs a request against the host application using the specified HTTP method.
/// </summary>
/// <param name="method">The HTTP method that should be used.</param>
/// <param name="path">The path that is being requested.</param>
/// <param name="overrides">A configuration object for providing the HTTP payload for the request.</param>
/// <returns>A <see cref="ClientResponse"/> instance of the executed request.</returns>
public virtual ClientResponse PerformRequest(string method, string path, Action<HttpPayload> overrides = null)
{
Ensure.NotNull(method, "method");
Ensure.NotNull(path, "path");
var payload = new HttpPayload(method);
if (defaults != null)
{
defaults.ApplyTo(payload);
}
path = path.RemoveLeadingSlash();
path = payload.ExtractQueryString(path);
overrides.TryInvoke(payload);
CrowbarContext.Reset();
var request = new CrowbarHttpRequestCapture(new CrowbarHttpRequest(path, payload));
var response = new CrowbarHttpResponse();
using (var handle = CreateRequestWaitHandle())
{
var worker = new CrowbarHttpWorker(request, response, handle);
HttpRuntime.ProcessRequest(worker);
handle.Wait();
return CreateResponse(request, response);
}
}
示例2: ShouldBeHtml
/// <summary>
/// Asserts that the response content type is of the MIME-type 'text/html'.
/// </summary>
/// <param name="response">The <see cref="ClientResponse"/> that the assert should be made on.</param>
/// <param name="assertions">Additional assertions on the CQ object.</param>
/// <returns>The CQ object.</returns>
public static CQ ShouldBeHtml(this ClientResponse response, Action<CQ> assertions = null)
{
response.ShouldHaveContentType("text/html");
CQ document;
try
{
document = response.AsCsQuery();
}
catch (Exception exception)
{
throw AssertException.Create(response, "Failed to convert response body into a CQ object.", exception);
}
assertions.TryInvoke(document);
return document;
}
示例3: ShouldBeHtml
/// <summary>
/// Asserts that the response content type is of the MIME-type 'text/html'.
/// </summary>
/// <param name="response">The <see cref="BrowserResponse"/> that the assert should be made on.</param>
/// <param name="assertions">Additional assertions on the CQ object.</param>
/// <returns>The CQ object.</returns>
public static CQ ShouldBeHtml(this BrowserResponse response, Action<CQ> assertions = null)
{
response.AssertStatusCode(HttpStatusCode.OK);
response.AssertContentType("text/html");
CQ document;
try
{
document = response.AsCsQuery();
}
catch (Exception exception)
{
throw new AssertException("Failed to convert response body into a CQ object.", exception);
}
assertions.TryInvoke(document);
return document;
}
示例4: PerformRequest
/// <summary>
/// Performs a request against the host application using the specified HTTP method.
/// </summary>
/// <param name="method">The HTTP method that should be used.</param>
/// <param name="path">The path that is being requested.</param>
/// <param name="overrides">A configuration object for providing the browser context for the request.</param>
/// <returns>A <see cref="BrowserResponse"/> instance of the executed request.</returns>
public BrowserResponse PerformRequest(string method, string path, Action<BrowserContext> overrides = null)
{
Ensure.NotNull(method, "method");
Ensure.NotNull(path, "path");
var context = new BrowserContext(mvcMajorVersion, method);
path = path.RemoveLeadingSlash();
path = context.ExtractQueryString(path);
defaults.TryInvoke(context);
overrides.TryInvoke(context);
CrowbarContext.Reset();
var output = new StringWriter();
var workerRequest = new SimulatedWorkerRequest(path, context, output);
HttpRuntime.ProcessRequest(workerRequest);
string rawHttpRequest = workerRequest.GetRawHttpRequest();
return CreateResponse(output, rawHttpRequest);
}
示例5: ShouldBeXml
/// <summary>
/// Asserts that the response content type is of the MIME-type 'application/xml' or the specified override.
/// </summary>
/// <param name="response">The <see cref="ClientResponse"/> that the assert should be made on.</param>
/// <param name="assertions">Additional assertions on the XML object.</param>
/// <param name="contentType">The expected content type.</param>
/// <returns>An XElement.</returns>
public static XElement ShouldBeXml(this ClientResponse response, Action<XElement> assertions = null, string contentType = "application/xml")
{
response.ShouldHaveContentType(contentType);
XElement xml;
try
{
xml = response.AsXml();
}
catch (Exception exception)
{
throw AssertException.Create(response, "Failed to convert response body into XML.", exception);
}
assertions.TryInvoke(xml);
return xml;
}
示例6: RabbitMQChannelBase
protected RabbitMQChannelBase(ChannelManagerBase channelManager, Action<ICommunicationObject> communicationObjectCreatedCallback)
: base(channelManager)
{
communicationObjectCreatedCallback.TryInvoke(this);
}
示例7: Write
public override bool Write(byte[] chunk, int index, int count, Action dataWrittenCallback = null)
{
if (this.IsDisposed)
return false;
var args = new SocketAsyncEventArgs();
args.SetBuffer(chunk, index, count);
args.Completed += (sender, e) =>
{
this.BytesWritten += e.BytesTransferred;
dataWrittenCallback.TryInvoke();
};
return this._socket.SendAsync(args);
}
示例8: ShouldBeXml
/// <summary>
/// Asserts that the response content type is of the MIME-type 'application/xml' or the specified override.
/// </summary>
/// <param name="response">The <see cref="BrowserResponse"/> that the assert should be made on.</param>
/// <param name="assertions">Additional assertions on the XML object.</param>
/// <param name="contentType">The expected content type.</param>
/// <returns>An XElement.</returns>
public static XElement ShouldBeXml(this BrowserResponse response, Action<XElement> assertions = null, string contentType = "application/xml")
{
response.AssertStatusCode(HttpStatusCode.OK);
response.AssertContentType(contentType);
XElement xml;
try
{
xml = response.AsXml();
}
catch (Exception exception)
{
throw new AssertException("Failed to convert response body into XML.", exception);
}
assertions.TryInvoke(xml);
return xml;
}