-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRequestHandlerWrapper.cs
More file actions
68 lines (57 loc) · 2.45 KB
/
Copy pathRequestHandlerWrapper.cs
File metadata and controls
68 lines (57 loc) · 2.45 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
62
63
64
65
66
67
68
using System.Xml.Linq;
using OneScript.Contexts;
using OneScript.StandardLibrary.Collections;
using OneSwiss.Server.Services.CrServerProxy;
using ScriptEngine.Machine;
using ScriptEngine.Machine.Contexts;
namespace OneSwiss.Server.Oscript;
[ContextClass("КонтекстОбработчикаЗапроса", "RequestHandlerContext")]
public class RequestHandlerWrapper(
CrServerRequestsHandler requestsHandler,
CrServerConnection connection,
HttpContext context,
string location,
string repository,
string comment,
string requestFile,
ILogger<CrServerRequestsHandler> logger) : AutoContext<RequestHandlerWrapper>
{
[ContextProperty("АдресПубликации", "Location", CanWrite = false)]
public string Location => location;
[ContextProperty("Хранилище", "Repository", CanWrite = false)]
public string Repository => repository;
[ContextProperty("Комментарий", "Comment", CanWrite = false)]
public string Comment { get; set; } = comment;
[ContextProperty("ДополнительныеПараметры", "AdditionalParameters", CanWrite = false)]
public MapImpl AdditionalParameters { get; set; } = new();
[ContextMethod("ПередатьЗапрос", "PostRequest")]
public void PostRequest()
{
HandleAggregateException(() => requestsHandler.Send(repository, connection, context, requestFile, CancellationToken.None).Wait(),
"Ошибка отправки запроса серверу хранилищ");
}
[ContextMethod("ВызватьИсключение", "RaiseException")]
public void RaiseException(string message)
{
HandleAggregateException(() => CrServerRequestsHandler.RaiseException(context, message).Wait(),
"Ошибка отправки исключения конфигуратору");
}
private void HandleAggregateException(Action action, string errorText)
{
try
{
action.Invoke();
}
catch (AggregateException e)
{
foreach (var eInnerException in e.InnerExceptions)
logger.LogError(eInnerException, errorText);
throw;
}
}
internal void SetAdditionalParameters(Dictionary<string, string> parameters)
{
AdditionalParameters = new MapImpl(parameters
.Select(c => new KeyAndValueImpl(ValueFactory.Create(c.Key), ValueFactory.Create(c.Value))).ToArray());
}
}