-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntryPointFacade.cs
80 lines (65 loc) · 2.73 KB
/
EntryPointFacade.cs
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
69
70
71
72
73
74
75
76
77
78
79
80
using ShtrihM.DemoServer.Processing.Api.Common.Dtos.DemoObject;
using ShtrihM.DemoServer.Processing.Api.Common.Dtos.DemoObject.Update;
using ShtrihM.DemoServer.Processing.Common;
using ShtrihM.DemoServer.Processing.Model.DomainObjects.DemoObject;
using ShtrihM.DemoServer.Processing.Model.Interfaces;
using ShtrihM.Wattle3.DomainObjects.Interfaces;
using System.Threading;
using System.Threading.Tasks;
namespace ShtrihM.DemoServer.Processing.Model.Implements;
public class EntryPointFacade : IEntryPointFacade
{
private readonly ICustomEntryPoint m_entryPoint;
// ReSharper disable once ConvertToPrimaryConstructor
public EntryPointFacade(ICustomEntryPoint entryPoint)
{
m_entryPoint = entryPoint;
}
public async ValueTask<DemoObjectInfo> DemoObjectReadAsync(
long id,
CancellationToken cancellationToken = default)
{
var unitOfWork = m_entryPoint.CurrentUnitOfWork;
var registerDemoObject = unitOfWork.Registers.GetRegister(WellknownDomainObjects.DemoObject);
var demoObject = await registerDemoObject
.FindAsync<IDomainObjectDemoObject>(id, cancellationToken)
.ConfigureAwait(false);
if (demoObject == null)
{
var workflowException = m_entryPoint.WorkflowExceptionPolicy.CreateDemoObjectNotFound(id);
throw workflowException;
}
var result = demoObject.GetInfo();
return result;
}
public async ValueTask<DemoObjectInfo> DemoObjectUpdateAsync(
DemoObjectUpdate parameters,
CancellationToken cancellationToken = default)
{
var registerDemoObject = m_entryPoint.CurrentUnitOfWork.Registers.GetRegister(WellknownDomainObjects.DemoObject);
var demoObject = await registerDemoObject
.LockRegister(parameters.Id)
.FindAsync<IDomainObjectDemoObject>(parameters.Id, cancellationToken)
.ConfigureAwait(false);
if (demoObject == null)
{
var workflowException = m_entryPoint.WorkflowExceptionPolicy.CreateDemoObjectNotFound(parameters.Id);
throw workflowException;
}
await demoObject.UpdateAsync(parameters, cancellationToken).ConfigureAwait(false);
var result = demoObject.GetInfo();
return result;
}
public async ValueTask<DemoObjectInfo> DemoObjectCreateAsync(
DemoObjectCreate parameters,
CancellationToken cancellationToken = default)
{
var demoObject = await new DomainObjectDemoObject.Template(
parameters.Name,
parameters.Enabled)
.NewAsync(m_entryPoint, cancellationToken)
.ConfigureAwait(false);
var result = demoObject.GetInfo();
return result;
}
}