-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathPersonDataSvc.cs
More file actions
323 lines (277 loc) · 14.2 KB
/
Copy pathPersonDataSvc.cs
File metadata and controls
323 lines (277 loc) · 14.2 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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
* This file is automatically generated; any changes will be lost.
*/
#nullable enable
#pragma warning disable
namespace Beef.Demo.Business.DataSvc;
/// <summary>
/// Provides the <see cref="Person"/> data repository services.
/// </summary>
public partial class PersonDataSvc : IPersonDataSvc
{
private readonly IPersonData _data;
private readonly IEventPublisher _events;
private readonly IRequestCache _cache;
#region Extensions
private Func<Person, Task>? _createOnAfterAsync;
private Func<Guid, Task>? _deleteOnAfterAsync;
private Func<Person?, Guid, Task>? _getExOnAfterAsync;
private Func<Person, Task>? _updateWithRollbackOnAfterAsync;
private Func<PersonCollectionResult, PagingArgs?, Task>? _getAllOnAfterAsync;
private Func<PersonCollectionResult, Task>? _getAll2OnAfterAsync;
private Func<PersonCollectionResult, PersonArgs?, PagingArgs?, Task>? _getByArgsOnAfterAsync;
private Func<PersonDetailCollectionResult, PersonArgs?, PagingArgs?, Task>? _getDetailByArgsOnAfterAsync;
private Func<Person, Guid, Guid, Task>? _mergeOnAfterAsync;
private Func<Task>? _markOnAfterAsync;
private Func<MapCoordinates, MapArgs?, Task>? _mapOnAfterAsync;
private Func<Person?, Task>? _getNoArgsOnAfterAsync;
private Func<PersonDetail?, Guid, Task>? _getDetailOnAfterAsync;
private Func<PersonDetail, Task>? _updateDetailOnAfterAsync;
private Func<Task>? _add2OnAfterAsync;
private Func<Task>? _add3OnAfterAsync;
private Func<int, Task>? _dataSvcCustomOnAfterAsync;
private Func<Person?, string?, List<string>?, Task>? _getNullOnAfterAsync;
private Func<PersonCollectionResult, PersonArgs?, PagingArgs?, Task>? _getByArgsWithEfOnAfterAsync;
private Func<Task>? _throwErrorOnAfterAsync;
private Func<string, Guid, Task>? _invokeApiViaAgentOnAfterAsync;
private Func<Person?, Guid, Task>? _getWithEfOnAfterAsync;
private Func<Person, Task>? _createWithEfOnAfterAsync;
private Func<Person, Task>? _updateWithEfOnAfterAsync;
private Func<Guid, Task>? _deleteWithEfOnAfterAsync;
private Func<FileContentResult, Guid, Task>? _getDocumentationOnAfterAsync;
private Func<string?, Guid, Task<Result>>? _simulateWorkOnAfterAsync;
private Func<string?, string?, Task<Result>>? _extendResponseOnAfterAsync;
#endregion
/// <summary>
/// Initializes a new instance of the <see cref="PersonDataSvc"/> class.
/// </summary>
/// <param name="data">The <see cref="IPersonData"/>.</param>
/// <param name="events">The <see cref="IEventPublisher"/>.</param>
/// <param name="cache">The <see cref="IRequestCache"/>.</param>
public PersonDataSvc(IPersonData data, IEventPublisher events, IRequestCache cache)
{ _data = data.ThrowIfNull(); _events = events.ThrowIfNull(); _cache = cache.ThrowIfNull(); PersonDataSvcCtor(); }
partial void PersonDataSvcCtor(); // Enables additional functionality to be added to the constructor.
/// <inheritdoc/>
public Task<Person> CreateAsync(Person value) => DataSvcInvoker.Current.InvokeAsync(this, async (_, __) =>
{
var r = await _data.CreateAsync(value).ConfigureAwait(false);
await Invoker.InvokeAsync(_createOnAfterAsync?.Invoke(r)).ConfigureAwait(false);
_events.PublishValueEvent(r, new Uri($"/person/{r.Id}", UriKind.Relative), $"Demo.Person", "Create");
return _cache.SetValue(r);
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task DeleteAsync(Guid id) => DataSvcInvoker.Current.InvokeAsync(this, async (_, __) =>
{
_cache.Remove<Person>(id);
await _data.DeleteAsync(id).ConfigureAwait(false);
await Invoker.InvokeAsync(_deleteOnAfterAsync?.Invoke(id)).ConfigureAwait(false);
_events.PublishValueEvent(new Person { Id = id }, new Uri($"/person/{id}", UriKind.Relative), $"Demo.Person", "Delete");
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task<Person?> GetAsync(Guid id) => _cache.GetOrAddAsync(id, () => _data.GetAsync(id));
/// <inheritdoc/>
public async Task<Person?> GetExAsync(Guid id)
{
if (_cache.TryGetValue(id, out Person? __val))
return __val;
var r = await _data.GetExAsync(id).ConfigureAwait(false);
await Invoker.InvokeAsync(_getExOnAfterAsync?.Invoke(r, id)).ConfigureAwait(false);
return _cache.SetValue(r);
}
/// <inheritdoc/>
public Task<Person> UpdateAsync(Person value) => DataSvcInvoker.Current.InvokeAsync(this, async (_, __) =>
{
var r = await _data.UpdateAsync(value).ConfigureAwait(false);
_events.PublishValueEvent(r, new Uri($"/person/{r.Id}", UriKind.Relative), $"Demo.Person", "Update");
return _cache.SetValue(r);
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task<Person> UpdateWithRollbackAsync(Person value) => DataSvcInvoker.Current.InvokeAsync(this, async (_, __) =>
{
var r = await _data.UpdateWithRollbackAsync(value).ConfigureAwait(false);
await Invoker.InvokeAsync(_updateWithRollbackOnAfterAsync?.Invoke(r)).ConfigureAwait(false);
_events.PublishValueEvent(r, new Uri($"/person/{r.Id}", UriKind.Relative), $"Demo.Person", "Update");
return _cache.SetValue(r);
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public async Task<PersonCollectionResult> GetAllAsync(PagingArgs? paging)
{
var r = await _data.GetAllAsync(paging).ConfigureAwait(false);
await Invoker.InvokeAsync(_getAllOnAfterAsync?.Invoke(r, paging)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public async Task<PersonCollectionResult> GetAll2Async()
{
var r = await _data.GetAll2Async().ConfigureAwait(false);
await Invoker.InvokeAsync(_getAll2OnAfterAsync?.Invoke(r)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public async Task<PersonCollectionResult> GetByArgsAsync(PersonArgs? args, PagingArgs? paging)
{
var r = await _data.GetByArgsAsync(args, paging).ConfigureAwait(false);
await Invoker.InvokeAsync(_getByArgsOnAfterAsync?.Invoke(r, args, paging)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public async Task<PersonDetailCollectionResult> GetDetailByArgsAsync(PersonArgs? args, PagingArgs? paging)
{
var r = await _data.GetDetailByArgsAsync(args, paging).ConfigureAwait(false);
await Invoker.InvokeAsync(_getDetailByArgsOnAfterAsync?.Invoke(r, args, paging)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public Task<Person> MergeAsync(Guid fromId, Guid toId) => DataSvcInvoker.Current.InvokeAsync(this, async (_, __) =>
{
var r = await _data.MergeAsync(fromId, toId).ConfigureAwait(false);
await Invoker.InvokeAsync(_mergeOnAfterAsync?.Invoke(r, fromId, toId)).ConfigureAwait(false);
_events.Publish(
_events.CreateValueEvent(r, new Uri($"/person/", UriKind.Relative), $"Demo.Person.{fromId}", "MergeFrom"),
_events.CreateValueEvent(r, new Uri($"/person/", UriKind.Relative), $"Demo.Person.{toId}", "MergeTo"));
return r;
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task MarkAsync() => DataSvcInvoker.Current.InvokeAsync(this, async (_, __) =>
{
await _data.MarkAsync().ConfigureAwait(false);
await Invoker.InvokeAsync(_markOnAfterAsync?.Invoke()).ConfigureAwait(false);
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public async Task<MapCoordinates> MapAsync(MapArgs? args)
{
var r = await _data.MapAsync(args).ConfigureAwait(false);
await Invoker.InvokeAsync(_mapOnAfterAsync?.Invoke(r, args)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public async Task<Person?> GetNoArgsAsync()
{
if (_cache.TryGetValue(new CompositeKey(), out Person? __val))
return __val;
var r = await _data.GetNoArgsAsync().ConfigureAwait(false);
await Invoker.InvokeAsync(_getNoArgsOnAfterAsync?.Invoke(r)).ConfigureAwait(false);
return _cache.SetValue(r);
}
/// <inheritdoc/>
public async Task<PersonDetail?> GetDetailAsync(Guid id)
{
if (_cache.TryGetValue(id, out PersonDetail? __val))
return __val;
var r = await _data.GetDetailAsync(id).ConfigureAwait(false);
await Invoker.InvokeAsync(_getDetailOnAfterAsync?.Invoke(r, id)).ConfigureAwait(false);
return _cache.SetValue(r);
}
/// <inheritdoc/>
public Task<PersonDetail> UpdateDetailAsync(PersonDetail value) => DataSvcInvoker.Current.InvokeAsync(this, async (_, __) =>
{
var r = await _data.UpdateDetailAsync(value).ConfigureAwait(false);
await Invoker.InvokeAsync(_updateDetailOnAfterAsync?.Invoke(r)).ConfigureAwait(false);
_events.PublishValueEvent(r, new Uri($"/person/{r.Id}", UriKind.Relative), $"Demo.Person", "Update");
return _cache.SetValue(r);
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public async Task Add2Async(Person person)
{
await _data.Add2Async(person).ConfigureAwait(false);
await Invoker.InvokeAsync(_add2OnAfterAsync?.Invoke()).ConfigureAwait(false);
}
/// <inheritdoc/>
public async Task Add3Async(Person value)
{
await _data.Add3Async(value).ConfigureAwait(false);
await Invoker.InvokeAsync(_add3OnAfterAsync?.Invoke()).ConfigureAwait(false);
}
/// <inheritdoc/>
public async Task<int> DataSvcCustomAsync()
{
var r = await DataSvcCustomOnImplementationAsync().ConfigureAwait(false);
await Invoker.InvokeAsync(_dataSvcCustomOnAfterAsync?.Invoke(r)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public async Task<Person?> GetNullAsync(string? name, List<string>? names)
{
var r = await _data.GetNullAsync(name, names).ConfigureAwait(false);
await Invoker.InvokeAsync(_getNullOnAfterAsync?.Invoke(r, name, names)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public Task<Person> EventPublishNoSendAsync(Person value) => EventPublishNoSendOnImplementationAsync(value);
/// <inheritdoc/>
public async Task<PersonCollectionResult> GetByArgsWithEfAsync(PersonArgs? args, PagingArgs? paging)
{
var r = await _data.GetByArgsWithEfAsync(args, paging).ConfigureAwait(false);
await Invoker.InvokeAsync(_getByArgsWithEfOnAfterAsync?.Invoke(r, args, paging)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public async Task ThrowErrorAsync()
{
await _data.ThrowErrorAsync().ConfigureAwait(false);
await Invoker.InvokeAsync(_throwErrorOnAfterAsync?.Invoke()).ConfigureAwait(false);
}
/// <inheritdoc/>
public async Task<string> InvokeApiViaAgentAsync(Guid id)
{
var r = await _data.InvokeApiViaAgentAsync(id).ConfigureAwait(false);
await Invoker.InvokeAsync(_invokeApiViaAgentOnAfterAsync?.Invoke(r, id)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public Task ParamCollAsync(AddressCollection? addresses) => ParamCollOnImplementationAsync(addresses);
/// <inheritdoc/>
public async Task<Person?> GetWithEfAsync(Guid id)
{
if (_cache.TryGetValue(id, out Person? __val))
return __val;
var r = await _data.GetWithEfAsync(id).ConfigureAwait(false);
await Invoker.InvokeAsync(_getWithEfOnAfterAsync?.Invoke(r, id)).ConfigureAwait(false);
return _cache.SetValue(r);
}
/// <inheritdoc/>
public async Task<Person> CreateWithEfAsync(Person value)
{
var r = await _data.CreateWithEfAsync(value).ConfigureAwait(false);
await Invoker.InvokeAsync(_createWithEfOnAfterAsync?.Invoke(r)).ConfigureAwait(false);
return _cache.SetValue(r);
}
/// <inheritdoc/>
public Task<Person> UpdateWithEfAsync(Person value) => DataSvcInvoker.Current.InvokeAsync(this, async (_, __) =>
{
var r = await _data.UpdateWithEfAsync(value).ConfigureAwait(false);
await Invoker.InvokeAsync(_updateWithEfOnAfterAsync?.Invoke(r)).ConfigureAwait(false);
_events.PublishValueEvent(r, new Uri($"/person/{r.Id}", UriKind.Relative), $"Demo.Person", "Update");
return _cache.SetValue(r);
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task DeleteWithEfAsync(Guid id) => DataSvcInvoker.Current.InvokeAsync(this, async (_, __) =>
{
_cache.Remove<Person>(id);
await _data.DeleteWithEfAsync(id).ConfigureAwait(false);
await Invoker.InvokeAsync(_deleteWithEfOnAfterAsync?.Invoke(id)).ConfigureAwait(false);
_events.PublishValueEvent(new Person { Id = id }, new Uri($"/person/{id}", UriKind.Relative), $"Demo.Person.{id}", "Delete");
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public async Task<FileContentResult> GetDocumentationAsync(Guid id)
{
var r = await _data.GetDocumentationAsync(id).ConfigureAwait(false);
await Invoker.InvokeAsync(_getDocumentationOnAfterAsync?.Invoke(r, id)).ConfigureAwait(false);
return r;
}
/// <inheritdoc/>
public Task<Result<string?>> SimulateWorkAsync(Guid id) => DataSvcInvoker.Current.InvokeAsync(this, (_, __) =>
{
return Result.GoAsync(_data.SimulateWorkAsync(id))
.ThenAsync(r => _simulateWorkOnAfterAsync?.Invoke(r, id) ?? Result.SuccessTask)
.Then(r => _events.PublishValueEvent("WorkIt", new Uri($"/person/", UriKind.Relative), $"Work", "Simulated"));
}, new InvokerArgs { IncludeTransactionScope = true, EventPublisher = _events });
/// <inheritdoc/>
public Task<Result<string?>> ExtendResponseAsync(string? name)
{
return Result.GoAsync(_data.ExtendResponseAsync(name))
.ThenAsync(r => _extendResponseOnAfterAsync?.Invoke(r, name) ?? Result.SuccessTask);
}
}
#pragma warning restore
#nullable restore