-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathHttpContextWrapper.cs
More file actions
61 lines (49 loc) · 2.65 KB
/
Copy pathHttpContextWrapper.cs
File metadata and controls
61 lines (49 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using Microsoft.AspNetCore.Http;
using OneScript.Contexts;
using OneScript.StandardLibrary.Collections;
using OneScript.Web.Server.WebSockets;
using ScriptEngine.Machine.Contexts;
using OneScript.Types;
namespace OneScript.Web.Server
{
[ContextClass("HTTPКонтекст", "HTTPContext")]
public class HttpContextWrapper : AutoContext<HttpContextWrapper>
{
private readonly ITypeManager _typeManager;
private readonly HttpContext _context;
private readonly PropertyWrappersCollection _wrappers = new();
public HttpContextWrapper(ITypeManager typeManager, HttpContext context)
{
_typeManager = typeManager;
_context = context;
}
[ContextProperty("Запрос", "Request", CanWrite = false)]
public HttpRequestWrapper Request =>
_wrappers.Get(nameof(Request), () => new HttpRequestWrapper(_context.Request));
[ContextProperty("Ответ", "Response", CanWrite = false)]
public HttpResponseWrapper Response =>
_wrappers.Get(nameof(Response), () => new HttpResponseWrapper(_context.Response));
[ContextProperty("Соединение", "Connection", CanWrite = false)]
public ConnectionInfoWrapper Connection =>
_wrappers.Get(nameof(Connection), () => new ConnectionInfoWrapper(_context.Connection));
[ContextProperty("ИдентификаторТрассировки", "TraceIdentifier", CanWrite = false)]
public string TraceIdentifier => _context.TraceIdentifier;
[ContextProperty("ЗапросПрерван", "RequestAborted", CanWrite = false)]
public bool RequestAborted => _context.RequestAborted.IsCancellationRequested;
[ContextProperty("Данные", "Data", CanWrite = false)]
public AutoCollectionContext<MapImpl, KeyAndValueImpl> Data => _wrappers.Get(nameof(Data), () =>
MapWrapper<object, object>.Create(_typeManager, _context.Items));
[ContextProperty("ВебСокеты", "WebSockets", CanWrite = false)]
public WebSocketsManagerWrapper WebSockets => _wrappers.Get(nameof(WebSockets), () =>
new WebSocketsManagerWrapper(_context.WebSockets));
[ContextMethod("Прервать", "Abort")]
public void Abort() => _context.Abort();
internal HttpContext GetContext() => _context;
}
}