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


C# Action.TryInvoke方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:mrydengren,项目名称:crowbar,代码行数:37,代码来源:Client.cs

示例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;
        }
开发者ID:mrydengren,项目名称:crowbar,代码行数:25,代码来源:ClientResponseAssertExtensions.cs

示例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;
        }
开发者ID:marcusoftnet,项目名称:crowbar,代码行数:26,代码来源:BrowserResponseAssertExtensions.cs

示例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);
        }
开发者ID:marcusoftnet,项目名称:crowbar,代码行数:30,代码来源:Browser.cs

示例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;
        }
开发者ID:mrydengren,项目名称:crowbar,代码行数:26,代码来源:ClientResponseAssertExtensions.cs

示例6: RabbitMQChannelBase

 protected RabbitMQChannelBase(ChannelManagerBase channelManager, Action<ICommunicationObject> communicationObjectCreatedCallback)
     : base(channelManager)
 {
     communicationObjectCreatedCallback.TryInvoke(this);
 }
开发者ID:hjb417,项目名称:rabbitmq-wcf-transports,代码行数:5,代码来源:RabbitMQChannelBase.cs

示例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);
        }
开发者ID:kthompson,项目名称:Bricks,代码行数:15,代码来源:TcpSocket.cs

示例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;
        }
开发者ID:marcusoftnet,项目名称:crowbar,代码行数:27,代码来源:BrowserResponseAssertExtensions.cs


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