WriteAsync() public méthode

public WriteAsync ( byte buffer ) : Task
buffer byte
Résultat Task
        public Task Invoke(IDictionary<string, object> environment)
        {
            var request = new OwinRequest(environment);
            if (string.IsNullOrEmpty(_options.Path) || string.Equals(request.Path, _options.Path, StringComparison.OrdinalIgnoreCase))
            {
                // TODO: Make it pretty
                OwinResponse response = new OwinResponse(environment);
                response.ContentType = "text/html";

                StringBuilder builder = new StringBuilder();
                builder.AppendLine("<html>")

                .AppendLine("<head>")
                .AppendLine("<title>")
                .AppendLine("Welcome")
                .AppendLine("</title>")
                .AppendLine("</head>")

                .AppendLine("<body>")
                .AppendLine("<H1>Welcome</H1>")
                .AppendLine("<p>You have reached the default application page.</p>")
                .AppendLine("<H4>Additional Resources:</H4>")
                .AppendLine("<ul>")
                .AppendLine("<li><a href=\"http://katanaproject.codeplex.com/\">Katana Project</a>")
                .AppendLine("<li><a href=\"http://www.owin.org/\">owin.org</a>")
                .AppendLine("</ul>")
                .AppendLine("</body>")
                .AppendLine("</html>");
                return response.WriteAsync(builder.ToString());
            }
            return _next(environment);
        }
 private static Task InvokeHandler(OwinResponse res, Func<OwinRequest, object> routeHandler, OwinRequest req)
 {
     var result = routeHandler(req);
     var flaskyResponse = result as IResponse;
     if(flaskyResponse != null)
     {
         return flaskyResponse.Write(res);
     }
     res.ContentType = "text/plain";
     return res.WriteAsync(result.ToString());
 }
 public Task Invoke(IDictionary<string, object> environment)
 {
     var request = new OwinRequest(environment);
     if (string.IsNullOrEmpty(_options.Path) || string.Equals(request.Path, _options.Path, StringComparison.OrdinalIgnoreCase))
     {
         // TODO: Make it pretty
         OwinResponse response = new OwinResponse(environment);
         response.ContentType = "text/plain";
         return response.WriteAsync("Welcome to Katana");
     }
     return _next(environment);
 }
        public Task Invoke(IDictionary<string, object> environment)
        {
            OwinRequest request = new OwinRequest(environment);
            OwinResponse response = new OwinResponse(environment);

            response.ContentType = "text/plain";

            string responseText = request.GetHeader("breadcrumbs") + "\r\n"
                + "PathBase: " + request.PathBase + "\r\n"
                + "Path: " + request.Path + "\r\n";

            return response.WriteAsync(responseText);
        }
Exemple #5
0
            public async Task Invoke(IDictionary<string, object> env) {

                OwinRequest request = new OwinRequest(env);
                if (request.Path == "/raw") {

                    OwinResponse response = new OwinResponse(request);
                    response.ContentType = "text/plain";
                    await response.WriteAsync("Hello from OWIN!");
                }
                else {

                    await _nextFunc(env);
                }
            }
        private static async Task SendFileToResponse(OwinResponse response, CrossAppDomainResponseFile file) {
            if(response.CanSendFile)
            {
                await response.SendFileAsync(file.Path, file.Length, file.Offset, CancellationToken.None);
                return;
            }

            var buffer = new byte[file.Length - file.Offset];
            using (var stream = File.OpenRead(file.Path)) {
                stream.Seek(file.Offset, SeekOrigin.Begin);
                await stream.ReadAsync(buffer, 0, (int)file.Length);
            }
            await response.WriteAsync(buffer);
        }
        private static Task RequestDump(OwinRequest request, OwinResponse response)
        {
            var builder = new StringBuilder();
            builder.AppendLine("<h1>Katana demo op TechDays</h1>");
            builder.AppendLine("<h2>request.Dictionary</h2>");

            builder.Append("<table>");
            foreach (var item in request.Dictionary)
            {
                builder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>",
                    item.Key, item.Value);
            }
            builder.Append("</table>");

            response.ContentType = "text/html";
            return response.WriteAsync(builder.ToString());
        }
        public async Task UpdateWithResponseData(IDictionary<string, object> environment, CrossAppDomainResponseData responseData) {
            var response = new OwinResponse(environment);
            response.StatusCode = responseData.StatusCode;
            response.ReasonPhrase = responseData.StatusDescription;

            foreach (var pair in responseData.Headers) {
                response.Headers.Add(pair.Key, new[] { pair.Value });
            }

            foreach (var data in responseData.Body) {
                await response.WriteAsync(data);
            }

            foreach (var file in responseData.Files) {
                await SendFileToResponse(response, file);
            }
        }
 // Invoked once per request.
 public Task Invoke(OwinRequest request, OwinResponse response)
 {
     response.ContentType = "text/plain";
     return response.WriteAsync("Hello World");
 }
 public async Task DownloadLargeAsyncWrite(IDictionary<string, object> environment)
 {
     OwinResponse response = new OwinResponse(environment);
     await response.WriteAsync(new byte[0x1FFFFFF]); // One bit larger than the max data frame size of 0xFFFFFF
 }
 public async Task DownloadMultipleWrites(IDictionary<string, object> environment)
 {
     OwinResponse response = new OwinResponse(environment);
     await response.WriteAsync("Hello World");
     await response.WriteAsync("Hello World");
     await response.WriteAsync("Hello World");
 }
 public async Task ExceptionAfterFirstWrite(IDictionary<string, object> environment)
 {
     OwinResponse response = new OwinResponse(environment);
     await response.WriteAsync("Hello World");
     await Task.Delay(500); // Make sure the headers get received.
     throw new NotImplementedException();
 }