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


C# Response.Finish方法代码示例

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


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

示例1: Call

        public static AppAction Call(AppAction app)
        {
            return (env, fault, result) => {
                Action<Exception, Action<ArraySegment<byte>>> writeErrorPageBody = (ex, write) => {
                    write("<h1>Server Error</h1>".ToBytes());
                    write("<p>".ToBytes());
                    write(ex.Message.ToBytes()); //TODO: htmlencode, etc
                    write("</p>".ToBytes());
                };

                Action<Exception> sendErrorPageResponse = ex => {
                    var response = new Response(result) {Status = 500, ContentType = "text/html"};
                    writeErrorPageBody(ex, value => response.Write(value));
                    response.Finish();
                };

                try {
                    // intercept app-fault with sendErrorPageResponse, which is the full error page response
                    // intercept body-error with writeErrorPageBody, which adds the error text to the output and completes the response
                    app(env, sendErrorPageResponse, (status, headers, body) =>
                        result(status, headers, body.Filter((subscribe, next, error, complete) =>
                            subscribe(next, ex => {
                                writeErrorPageBody(ex, data => next.InvokeSync(data));
                                complete();
                            }, complete))));
                }
                catch (Exception ex) {
                    sendErrorPageResponse(ex);
                }
            };
        }
开发者ID:loudej,项目名称:taco,代码行数:31,代码来源:ShowExceptions.cs

示例2: Create

        public static AppAction Create()
        {
            return (env, fault, result) => {
                var request = new Request(env);
                var response = new Response(result) {
                    Status = 200,
                    ContentType = "text/html"
                };

                response.Write("<h1>Sample1</h1>");
                response.Write("<p>Hello world</p>");
                response.Write("<p>This part is being added to the response helper's buffer. The result callback has not been invoked yet.</p>");

                response.Finish(() => {
                    response.Write("<p>The result callback has been invoked. This part is going out live, but you can no longer change http response status or headers.</p>");

                    response.Write("<p>request.PathInfo=").Write(request.PathInfo).Write("</p>");
                    response.Write("<p>request.ScriptName=").Write(request.ScriptName).Write("</p>");

                    response.Write("<p> see also <a href='wilson'>Wilson</a> and <a href='wilsonasync'>WilsonAsync</a></p>");

                    response.Write(new byte[] {65, 66, 67, 68});

                    response.Write("<p>And now for something completely different.");
                    throw new ApplicationException("Something completely different");
                });
            };
        }
开发者ID:loudej,项目名称:taco,代码行数:28,代码来源:RawApp.cs

示例3: Call

        public dynamic[] Call(IDictionary<string, dynamic> environment)
        {
            var request = new Request(environment);
            string lobster;
            string href;

            if (request.GET.ContainsKey("flip") && request.GET["flip"] == "left")
            {
                lobster = string.Join("\n", LobsterString.Split('\n').Select(line => new string(line.PadRight(42).Reverse().ToArray())));
                href = "?flip=right";
            }
            else if (request.GET.ContainsKey("flip") && request.GET["flip"] == "crash")
            {
                throw new InvalidOperationException("Lobster crashed!");
            }
            else
            {
                lobster = LobsterString;
                href = "?flip=left";
            }

            var response = new Response();
            response.Write("<title>Lobstericious!</title>");
            response.Write("<pre>");
            response.Write(lobster);
            response.Write("</pre>");
            response.Write("<p><a href='" + href + "'>flip!</a></p>");
            response.Write("<p><a href='?flip=crash'>crash!</a></p>");

            return response.Finish();
        }
开发者ID:kevinswiber,项目名称:NRack,代码行数:31,代码来源:Lobster.cs

示例4: App

        public static FnApp App()
        {
            return (env, fault, result) => {
                var request = new Request(env);
                var response = new Response(result);
                var wilson = "left - right\r\n123456789012\r\nhello world!\r\n";

                var href = "?flip=left";
                if (request.GET["flip"] == "left") {
                    wilson = wilson.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
                        .Select(line => new string(line.Reverse().ToArray()))
                        .Aggregate("", (agg, line) => agg + line + Environment.NewLine);
                    href = "?flip=right";
                }

                response.Write("<title>Hutchtastic</title>");
                response.Write("<pre>");
                response.Write(wilson);
                response.Write("</pre>");
                if (request.GET["flip"] == "crash") {
                    throw new ApplicationException("Wilson crashed!");
                }
                response.Write("<p><a href='" + href + "'>flip!</a></p>");
                response.Write("<p><a href='?flip=crash'>crash!</a></p>");
                response.Finish();
            };
        }
开发者ID:loudej,项目名称:taco,代码行数:27,代码来源:Wilson.cs

示例5: Something

 public async Task Something(Request req, Response res, string echo)
 {
     await res.Start();
     await res.Write("SomeOtherController.Something");
     await res.Write("\n" + echo);
     await res.Finish();
 }
开发者ID:shz,项目名称:pointy,代码行数:7,代码来源:Program.cs

示例6: Index

 public async Task Index(Request req, Response res)
 {
     await res.Start();
     await res.Write("SomeController.Index");
     throw new Exception("bad news everyone");
     await res.Finish();
 }
开发者ID:shz,项目名称:pointy,代码行数:7,代码来源:Program.cs

示例7: Should_Have_Sensible_Default_Values

        public void Should_Have_Sensible_Default_Values()
        {
            var response = new Response();
            var res = response.Finish();
            var status = res[0];
            var header = res[1];
            var body = (IIterable)res[2];

            Assert.AreEqual(200, status);
            CollectionAssert.AreEquivalent(new Hash { { "Content-Type", "text/html" } }, header);
            body.Each(part => Assert.AreEqual(string.Empty, part));
        }
开发者ID:kevinswiber,项目名称:NRack,代码行数:12,代码来源:Response_Specs.cs

示例8: Finish_will_call_result_delegate_with_current_status_and_headers

        public void Finish_will_call_result_delegate_with_current_status_and_headers()
        {
            var response = new Response(Result)
            {
                Status = "200 Blah",
                ContentType = "text/blah",
            };

            Assert.That(_status, Is.Null);
            response.Finish();
            Assert.That(_status, Is.EqualTo("200 Blah"));
            Assert.That(_headers["Content-Type"], Is.EqualTo("text/blah"));
        }
开发者ID:bvanderveen,项目名称:gate,代码行数:13,代码来源:ResponseTests.cs

示例9: ShowEnvironment

 public static AppDelegate ShowEnvironment()
 {
     return (env, result, fault) =>
     {
         var response = new Response(result) {Status = "200 OK", ContentType = "text/xml"};
         response.Finish((error, complete) =>
         {
             var detail = env.Select(kv => new XElement(kv.Key, kv.Value));
             var xml = new XElement("xml", detail.OfType<object>().ToArray());
             response.Write(xml.ToString());
             complete();
         });
     };
 }
开发者ID:bvanderveen,项目名称:gate,代码行数:14,代码来源:AppUtils.cs

示例10: Should_Not_Add_Or_Change_Content_Length_When_Finishing

        public void Should_Not_Add_Or_Change_Content_Length_When_Finishing()
        {
            var response = new Response();
            response.Status = 200;
            response.Finish();
            Assert.IsFalse(response.Headers.ContainsKey("Content-Length"));

            response = new Response();
            response.Status = 200;
            response.Headers["Content-Length"] = "10";
            response.Finish();

            Assert.AreEqual("10", response.Headers["Content-Length"]);
        }
开发者ID:kevinswiber,项目名称:NRack,代码行数:14,代码来源:Response_Specs.cs

示例11: Can_Be_Written_To

        public void Can_Be_Written_To()
        {
            var response = new Response();

            var body = response.Finish(_ =>
            {
                response.Write("foo");
                response.Write("bar");
                response.Write("baz");
            })[2];
            var parts = new List<string>();
            ((IIterable)body).Each(part => parts.Add(part));

            CollectionAssert.AreEquivalent(new List<string> { "foo", "bar", "baz" }, parts);
        }
开发者ID:kevinswiber,项目名称:NRack,代码行数:15,代码来源:Response_Specs.cs

示例12: Create

        public static AppAction Create()
        {
            return (env, fault, result) => {
                var request = new Request(env);

                if (request.RequestMethod == "GET") {
                    new Response(result) {Status = 200, ContentType = "text/html"}
                        .Write(@"
            <form method='post'>
            <input type='text' name='hello'/>
            <input type='submit' name='ok' value='ok'/>
            </form>")
                        .Finish();
                }
                else if (request.RequestMethod == "POST") {
                    // stream request body
                    var body = new MemoryStream();

                    request.Body.Subscribe(
                        data => body.Write(data.Result.Array, data.Result.Offset, data.Result.Count),
                        fault,
                        () => {
                            // completion continues
                            var response = new Response(result) {
                                Status = 200,
                                ContentType = "text/html"
                            };
                            response.Finish(() => {
                                response.Write("<p>You posted ");
                                response.Write(body.Length);
                                response.Write(" bytes of form data<p>");

                                var form = ParamDictionary.Parse(Encoding.Default.GetString(body.ToArray()));
                                response.Write("<ul>");
                                foreach (var kv in form) {
                                    response.Write("<li>").Write(kv.Key).Write(": ").Write(kv.Value).Write("</li>");
                                }
                                response.Write("</ul>");
                            });
                        });
                }
                else {
                    new Response(result) {Status = 404}.Finish();
                }
            };
        }
开发者ID:loudej,项目名称:taco,代码行数:46,代码来源:BodyStreaming.cs

示例13: executeRoute

        private static void executeRoute(RouteData routeData, Response response, OwinRequestBody request)
        {
            var arguments = new OwinServiceArguments(routeData, request, response);
            var invoker = routeData.RouteHandler.As<FubuRouteHandler>().Invoker;

            try
            {
                invoker.Invoke(arguments, routeData.Values);
            }
            catch (Exception ex)
            {
                write500(response, ex);
            }
            finally
            {
                response.Finish();
            }
        }
开发者ID:ghosthamlet,项目名称:fubumvc,代码行数:18,代码来源:FubuOwinHost.cs

示例14: AppAsync

        public static FnApp AppAsync()
        {
            return (env, fault, result) => {
                var request = new Request(env);
                var response = new Response(result);
                var wilson = "left - right\r\n123456789012\r\nhello world!\r\n";

                ThreadPool.QueueUserWorkItem(_ => {
                    try {
                        var href = "?flip=left";
                        if (request.GET["flip"] == "left") {
                            wilson = wilson.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
                                .Select(line => new string(line.Reverse().ToArray()))
                                .Aggregate("", (agg, line) => agg + line + Environment.NewLine);
                            href = "?flip=right";
                        }

                        response.Finish((fault2, complete) => TimerLoop(350, fault2,
                            () => response.Write("<title>Hutchtastic</title>"),
                            () => response.Write("<pre>"),
                            () => response.Write(wilson),
                            () => response.Write("</pre>"),
                            () => {
                                if (request.GET["flip"] == "crash") {
                                    throw new ApplicationException("Wilson crashed!");
                                }
                            },
                            () => response.Write("<p><a href='" + href + "'>flip!</a></p>"),
                            () => response.Write("<p><a href='?flip=crash'>crash!</a></p>"),
                            complete));
                    }
                    catch (Exception ex) {
                        fault(ex);
                    }
                });
            };
        }
开发者ID:loudej,项目名称:taco,代码行数:37,代码来源:Wilson.cs

示例15: Some2

 public async Task Some2(Request req, Response res)
 {
     await res.Start();
     await res.Write("SomeController.Index");
     await res.Finish();
 }
开发者ID:shz,项目名称:pointy,代码行数:6,代码来源:Program.cs


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