Ooui-tws-port/Ooui.AspNetCore/ElementResult.cs

31 lines
1004 B
C#
Raw Normal View History

2017-11-10 03:34:37 +00:00
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Ooui.AspNetCore
{
public class ElementResult : ActionResult
2017-11-10 05:00:15 +00:00
{
readonly Element element;
2017-11-10 03:34:37 +00:00
public ElementResult (Element element)
{
2017-11-10 05:00:15 +00:00
this.element = element;
2017-11-10 03:34:37 +00:00
}
public override async Task ExecuteResultAsync (ActionContext context)
{
var response = context.HttpContext.Response;
response.StatusCode = 200;
2017-11-10 05:00:15 +00:00
response.ContentType = "text/html; charset=utf-8";
var sessionId = WebSocketHandler.BeginSession (context.HttpContext, element);
var html = Encoding.UTF8.GetBytes (UI.RenderTemplate (WebSocketHandler.WebSocketPath + "?id=" + sessionId));
2017-11-10 03:34:37 +00:00
response.ContentLength = html.Length;
using (var s = response.Body) {
await s.WriteAsync (html, 0, html.Length).ConfigureAwait (false);
}
}
}
}