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
|
|
|
|
{
|
2017-11-16 04:20:09 +00:00
|
|
|
|
readonly Element element;
|
|
|
|
|
readonly string title;
|
2017-11-10 05:00:15 +00:00
|
|
|
|
|
2017-11-16 04:20:09 +00:00
|
|
|
|
public ElementResult (Element element, string title = "")
|
2017-11-10 03:34:37 +00:00
|
|
|
|
{
|
2017-11-16 04:20:09 +00:00
|
|
|
|
this.element = element;
|
|
|
|
|
this.title = title;
|
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);
|
2017-11-16 04:20:09 +00:00
|
|
|
|
var html = UI.RenderTemplate (WebSocketHandler.WebSocketPath + "?id=" + sessionId, title: title);
|
|
|
|
|
var htmlBytes = Encoding.UTF8.GetBytes (html);
|
|
|
|
|
response.ContentLength = htmlBytes.Length;
|
2017-11-10 03:34:37 +00:00
|
|
|
|
using (var s = response.Body) {
|
2017-11-16 04:20:09 +00:00
|
|
|
|
await s.WriteAsync (htmlBytes, 0, htmlBytes.Length).ConfigureAwait (false);
|
2017-11-10 03:34:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|