-
Notifications
You must be signed in to change notification settings - Fork 0
/
DomainObjectDemoObjectX.cs
247 lines (209 loc) · 7.98 KB
/
DomainObjectDemoObjectX.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
using Microsoft.Extensions.Logging;
using ShtrihM.DemoServer.Processing.Api.Common;
using ShtrihM.DemoServer.Processing.Common;
using ShtrihM.DemoServer.Processing.Model.Interfaces;
using ShtrihM.Wattle3.DomainObjects.DomainObjects;
using ShtrihM.Wattle3.DomainObjects.Interfaces;
using ShtrihM.Wattle3.Mappers.Primitives.MutableFields;
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using ShtrihM.DemoServer.Processing.Generated.Interface;
using ShtrihM.Wattle3.DomainObjects;
using ShtrihM.Wattle3.DomainObjects.DomainObjectActivators;
using ShtrihM.DemoServer.Processing.Model.DomainObjects.Common;
using ShtrihM.Wattle3.DomainObjects.UnitOfWorkLocks;
using ShtrihM.Wattle3.Utils;
namespace ShtrihM.DemoServer.Processing.Model.DomainObjects.DemoObjectX;
[DomainObjectDataMapper(WellknownMappersAsText.DemoObjectX, DomainObjectDataTarget.Create, DomainObjectDataTarget.Update, DomainObjectDataTarget.Delete)]
// ReSharper disable once ClassNeverInstantiated.Global
public sealed class DomainObjectDemoObjectX : BaseDomainObjectMutable<DomainObjectDemoObjectX>, IDomainObjectDemoObjectX,
IDomainObjectActivatorPostCreate
{
#region Template
public class Template : IDomainObjectTemplate
{
public Template(
string name,
bool enabled,
Guid key1,
string key2,
long group)
{
Name = name;
Enabled = enabled;
Key1 = key1;
Key2 = key2;
Group = group;
Key2 = key2;
}
public readonly string Name;
public readonly bool Enabled;
public readonly Guid Key1;
public readonly string Key2;
public readonly long Group;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DemoObjectXIdentitiesService.AlternativeKey GetKey()
{
var result = new DemoObjectXIdentitiesService.AlternativeKey(Key1, Key2);
return result;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IDomainObjectDemoObjectX New(ICustomEntryPoint entryPoint)
{
return entryPoint.CurrentUnitOfWork.New<IDomainObjectDemoObjectX>(this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ValueTask<IDomainObjectDemoObjectX> NewAsync(ICustomEntryPoint entryPoint, CancellationToken cancellationToken = default)
{
return entryPoint.CurrentUnitOfWork.NewAsync<IDomainObjectDemoObjectX>(this, cancellationToken);
}
}
#endregion
private readonly IDomainObjectUnitOfWorkLockService m_lockUpdate;
[DomainObjectFieldValue(DomainObjectDataTarget.Create, DomainObjectDataTarget.Update, DtoFiledName = nameof(DemoObjectXDtoChanged.Enabled))]
private MutableField<bool> m_enabled;
[DomainObjectFieldValue(DomainObjectDataTarget.Create, DomainObjectDataTarget.Update, DtoFiledName = nameof(DemoObjectXDtoChanged.Name))]
private MutableFieldStringLimitedEx m_name;
// ReSharper disable once UnusedMember.Global
public DomainObjectDemoObjectX(
DemoObjectXDtoActual data,
ICustomEntryPoint entryPoint,
IDomainObjectUnitOfWorkLockService lockUpdate)
: base(entryPoint, data)
{
m_lockUpdate = lockUpdate;
CreateDate = data.CreateDate;
ModificationDate = data.ModificationDate;
m_name = new MutableFieldStringLimitedEx(FieldsConstants.DemoObjectXNameMaxLength, data.Name);
m_enabled = new MutableField<bool>(data.Enabled);
Key1 = data.Key1;
Key2 = data.Key2;
Group = data.Group;
}
// ReSharper disable once UnusedMember.Global
public DomainObjectDemoObjectX(
long identity,
Template template,
ICustomEntryPoint entryPoint,
IDomainObjectUnitOfWorkLockService lockUpdate)
: base(entryPoint, identity)
{
m_lockUpdate = lockUpdate;
CreateDate = m_entryPoint.TimeService.Now;
ModificationDate = CreateDate;
m_name = new MutableFieldStringLimitedEx(FieldsConstants.DemoObjectXNameMaxLength, template.Name);
m_enabled = new MutableField<bool>(template.Enabled);
Key1 = template.Key1;
Key2 = template.Key2;
Group = template.Group;
}
public override Guid TypeId => WellknownDomainObjects.DemoObjectX;
public bool Enabled
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => m_enabled.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
m_lockUpdate.Has(Identity);
m_enabled.SetValue(value);
if (m_enabled.Changed)
{
DoUpdateAsync().SafeGetResult();
}
}
}
public string Name
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => m_name.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
m_lockUpdate.Has(Identity);
m_name.SetValue(value);
if (m_name.Changed)
{
DoUpdateAsync().SafeGetResult();
}
}
}
[DomainObjectFieldValue(DomainObjectDataTarget.Create, DomainObjectDataTarget.Update)]
public DateTimeOffset CreateDate
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
[DomainObjectFieldValue(DomainObjectDataTarget.Create, DomainObjectDataTarget.Update)]
public Guid Key1
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
[DomainObjectFieldValue(DomainObjectDataTarget.Create, DomainObjectDataTarget.Update)]
public string Key2
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
[DomainObjectFieldValue(DomainObjectDataTarget.Create, DomainObjectDataTarget.Update)]
public long Group
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}
[DomainObjectFieldValue(DomainObjectDataTarget.Create, DomainObjectDataTarget.Update)]
public DateTimeOffset ModificationDate
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private set;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DemoObjectXIdentitiesService.AlternativeKey GetKey()
{
var result = new DemoObjectXIdentitiesService.AlternativeKey(Key1, Key2);
return result;
}
public void Delete()
{
m_entryPoint.CurrentUnitOfWork.AddDelete(this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostCreate()
{
var unitOfWork = m_entryPoint.CurrentUnitOfWork;
var domainBehaviour = unitOfWork.CreateDomainBehaviourWithСonfirmation();
unitOfWork.AddBehaviour(domainBehaviour);
var identity = Identity;
domainBehaviour.SetFailAll(
() =>
{
var logger = m_entryPoint.LoggerFactory.CreateLogger<DomainObjectDemoObjectX>();
var messgae = $"Не удалось создать объект X с идентификатором '{identity}'.";
logger.LogError(messgae);
Console.WriteLine(messgae);
});
domainBehaviour.SetSuccessfulAll(
() =>
{
var logger = m_entryPoint.LoggerFactory.CreateLogger<DomainObjectDemoObjectX>();
var messgae = $"Создан объект X с идентификатором '{identity}'.";
logger.LogError(messgae);
Console.WriteLine(messgae);
});
}
public ValueTask PostCreateAsync(CancellationToken cancellationToken)
{
PostCreate();
return ValueTask.CompletedTask;
}
protected override ValueTask DoUpdateAsync(CancellationToken cancellationToken = default)
{
ModificationDate = m_entryPoint.TimeService.Now;
return base.DoUpdateAsync(cancellationToken);
}
}