Skip to content

Commit 52d6c1f

Browse files
committed
Removed report from operation interrupt behaviour
1 parent 1d0226b commit 52d6c1f

File tree

17 files changed

+58
-160
lines changed

17 files changed

+58
-160
lines changed

docs/migrations/v8_to_v10.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ These feature were infrequently used and has been removed to simplify the codeba
6464

6565
- Moryx.Tools.FunctionResult: Moved to Moryx.Tools
6666
- Moryx.AbstractionLayer namespace: All classes have been moved to more specific domain namespaces e.g. Moryx.AbstractionLayer.Resources, Moryx.AbstractionLayer.Products, Moryx.AbstractionLayer.Processes etc.
67+
68+
## Modules-Orders
69+
70+
- Removed report from interrupt of an operation. Reporting during an interruption doesn't add any value. The quantity for the report can only be predicted and will be inaccurate if something goes wrong or is reworked during the interruption.

src/Moryx.Orders.Endpoints/OrderManagementController.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public async Task OperationStream(CancellationToken cancelToken)
6868
var updateEventHandler = new EventHandler<OperationChangedEventArgs>((_, eventArgs) =>
6969
{
7070
var json = JsonConvert.SerializeObject(Converter.ToModel(eventArgs.Operation), _serializerSettings);
71-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Update.ToString(), json));
71+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Update), json));
7272
});
7373
_orderManagement.OperationUpdated += updateEventHandler;
7474

@@ -80,7 +80,7 @@ public async Task OperationStream(CancellationToken cancelToken)
8080
Advice = Converter.ToModel(eventArgs.Advice)
8181
};
8282
var json = JsonConvert.SerializeObject(advicedOperation, _serializerSettings);
83-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Advice.ToString(), json));
83+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Advice), json));
8484
});
8585
_orderManagement.OperationAdviced += adviceEventHandler;
8686

@@ -92,19 +92,14 @@ public async Task OperationStream(CancellationToken cancelToken)
9292
Report = Converter.ToModel(eventArgs.Report)
9393
};
9494
var json = JsonConvert.SerializeObject(reportedOperation, _serializerSettings);
95-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Report.ToString(), json));
95+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Report), json));
9696
});
9797
_orderManagement.OperationPartialReport += reportEventHandler;
9898

99-
var interruptedEventHandler = new EventHandler<OperationReportEventArgs>((_, eventArgs) =>
99+
var interruptedEventHandler = new EventHandler<OperationChangedEventArgs>((_, eventArgs) =>
100100
{
101-
var interruptedOperation = new OperationReportedModel
102-
{
103-
OperationModel = Converter.ToModel(eventArgs.Operation),
104-
Report = Converter.ToModel(eventArgs.Report)
105-
};
106-
var json = JsonConvert.SerializeObject(interruptedOperation, _serializerSettings);
107-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Interrupted.ToString(), json));
101+
var json = JsonConvert.SerializeObject(Converter.ToModel(eventArgs.Operation), _serializerSettings);
102+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Interrupted), json));
108103
});
109104
_orderManagement.OperationInterrupted += interruptedEventHandler;
110105

@@ -116,7 +111,7 @@ public async Task OperationStream(CancellationToken cancelToken)
116111
Report = Converter.ToModel(eventArgs.Report)
117112
};
118113
var json = JsonConvert.SerializeObject(completedOperation, _serializerSettings);
119-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Completed.ToString(), json));
114+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Completed), json));
120115
});
121116
_orderManagement.OperationCompleted += completedEventHandler;
122117

@@ -128,14 +123,14 @@ public async Task OperationStream(CancellationToken cancelToken)
128123
UserId = eventArgs.User.Identifier
129124
};
130125
var json = JsonConvert.SerializeObject(startedOperation, _serializerSettings);
131-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Start.ToString(), json));
126+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Start), json));
132127
});
133128
_orderManagement.OperationStarted += startedEventHandler;
134129

135130
var changedEventHandler = new EventHandler<OperationChangedEventArgs>((_, eventArgs) =>
136131
{
137132
var json = JsonConvert.SerializeObject(Converter.ToModel(eventArgs.Operation), _serializerSettings);
138-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Progress.ToString(), json));
133+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Progress), json));
139134
});
140135
_orderManagement.OperationProgressChanged += changedEventHandler;
141136

@@ -424,13 +419,13 @@ public ActionResult ReportOperation(Guid guid, ReportModel report)
424419
[ProducesResponseType(typeof(MoryxExceptionResponse), StatusCodes.Status404NotFound)]
425420
[Route("{guid}/interrupt")]
426421
[Authorize(Policy = OrderPermissions.CanInterrupt)]
427-
public ActionResult InterruptOperation(Guid guid, ReportModel report)
422+
public ActionResult InterruptOperation(Guid guid)
428423
{
429424
var operation = _orderManagement.GetOperation(guid);
430425
if (operation == null)
431426
return NotFound(new MoryxExceptionResponse { Title = Strings.OrderManagementController_OperationNotFound });
432427

433-
_orderManagement.InterruptOperation(operation, Converter.FromModel(report, _userManagement));
428+
_orderManagement.InterruptOperation(operation);
434429
return Ok();
435430
}
436431

src/Moryx.Orders.Management/Components/IOperationData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ internal interface IOperationData
139139
/// <summary>
140140
/// Disables an operation which leads to complete all jobs
141141
/// </summary>
142-
void Interrupt(OperationReport report);
142+
void Interrupt();
143143

144144
/// <summary>
145145
/// Will do a report for the operation.
@@ -195,7 +195,7 @@ internal interface IOperationData
195195
/// <summary>
196196
/// Raised if the operation was interrupted
197197
/// </summary>
198-
event EventHandler<ReportEventArgs> Interrupted;
198+
event EventHandler<OperationEventArgs> Interrupted;
199199

200200
/// <summary>
201201
/// Raised if the operation was completed

src/Moryx.Orders.Management/Facade/OrderManagementFacade.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ private void OnOperationStarted(object sender, StartedEventArgs e)
6666
OperationStarted?.Invoke(this, new OperationStartedEventArgs(e.OperationData.Operation, e.User));
6767
}
6868

69-
private void OnOperationInterrupted(object sender, ReportEventArgs e)
69+
private void OnOperationInterrupted(object sender, OperationEventArgs e)
7070
{
71-
OperationInterrupted?.Invoke(this, new OperationReportEventArgs(e.OperationData.Operation, e.Report));
71+
OperationInterrupted?.Invoke(this, new OperationChangedEventArgs(e.OperationData.Operation));
7272
}
7373

7474
private void OnOperationCompleted(object sender, ReportEventArgs e)
@@ -257,15 +257,12 @@ public ReportContext GetInterruptContext(Operation operation)
257257
return OperationManager.GetInterruptContext(operationData);
258258
}
259259

260-
public void InterruptOperation(Operation operation, OperationReport report)
260+
public void InterruptOperation(Operation operation)
261261
{
262262
ValidateHealthState();
263263

264-
// Get default user if there is no in the report
265-
report.User ??= UserManagement.DefaultUser;
266-
267264
var operationData = GetOperationDataSave(operation);
268-
OperationManager.Interrupt(operationData, report);
265+
OperationManager.Interrupt(operationData);
269266
}
270267

271268
private IOperationData GetOperationDataSave(Operation operation)
@@ -332,7 +329,7 @@ public Task<IReadOnlyList<IProductRecipe>> GetAssignableRecipes(ProductIdentity
332329

333330
public event EventHandler<OperationReportEventArgs> OperationCompleted;
334331

335-
public event EventHandler<OperationReportEventArgs> OperationInterrupted;
332+
public event EventHandler<OperationChangedEventArgs> OperationInterrupted;
336333

337334
public event EventHandler<OperationReportEventArgs> OperationPartialReport;
338335

src/Moryx.Orders.Management/Implementation/OperationData/OperationData.cs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -421,41 +421,32 @@ internal void HandleStarted(User user)
421421
}
422422

423423
/// <inheritdoc cref="IOperationData"/>
424-
public void Interrupt(OperationReport report)
424+
public void Interrupt()
425425
{
426-
Log(LogLevel.Debug, "Operation will be interrupted with SuccessCount {0} and FailureCount {1} by user {2}",
427-
report.SuccessCount, report.FailureCount, report.User.Identifier);
426+
Log(LogLevel.Debug, "Operation will be interrupted");
428427

429428
lock (_stateLock)
430-
_state.Interrupt(report);
429+
_state.Interrupt();
431430
}
432431

433432
/// <summary>
434433
/// Will complete all jobs and executes a partial report
435434
/// </summary>
436-
internal void HandleManualInterrupting(OperationReport report)
435+
internal void HandleManualInterrupting()
437436
{
438437
JobHandler.Complete(this);
439-
HandlePartialReport(report);
440438
}
441439

442440
/// <summary>
443441
/// Will handle manual interrupts. The interrupt was triggered by the user.
444442
/// Will throw the <see cref="Interrupted"/> event
445443
/// </summary>
446-
internal void HandleManualInterrupted(OperationReport report)
444+
internal void HandleManualInterrupted()
447445
{
448446
Operation.TargetAmount = ReachableAmount;
449447

450-
lock (_reports)
451-
{
452-
_reports.Add(report);
453-
Operation.Reports = _reports.ToArray();
454-
455-
}
456-
457448
Updated?.Invoke(this, new OperationEventArgs(this));
458-
Interrupted?.Invoke(this, new ReportEventArgs(this, report));
449+
Interrupted?.Invoke(this, new OperationEventArgs(this));
459450
}
460451

461452
/// <summary>
@@ -466,19 +457,8 @@ internal void HandleInterrupted()
466457
{
467458
Operation.TargetAmount = ReachableAmount;
468459

469-
// Add report for interrupted with user which have started the interruption
470-
OperationReport report;
471-
lock (_reports)
472-
{
473-
var lastReportUser = Operation.Reports.Last().User;
474-
report = new OperationReport(ConfirmationType.Partial, 0, 0, lastReportUser);
475-
476-
_reports.Add(report);
477-
Operation.Reports = _reports.ToArray();
478-
}
479-
480460
Updated?.Invoke(this, new OperationEventArgs(this));
481-
Interrupted?.Invoke(this, new ReportEventArgs(this, report));
461+
Interrupted?.Invoke(this, new OperationEventArgs(this));
482462
}
483463

484464
/// <inheritdoc cref="IOperationData"/>
@@ -757,7 +737,7 @@ private TInfo GetOperationInfo<TInfo>()
757737
public event EventHandler<StartedEventArgs> Started;
758738

759739
/// <inheritdoc cref="IOperationData.Interrupted"/>
760-
public event EventHandler<ReportEventArgs> Interrupted;
740+
public event EventHandler<OperationEventArgs> Interrupted;
761741

762742
/// <inheritdoc cref="IOperationData.Completed"/>
763743
public event EventHandler<ReportEventArgs> Completed;

src/Moryx.Orders.Management/Implementation/OperationData/States/AmountReachedState.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,10 @@ public override void IncreaseTargetBy(int amount, User user)
5454
Context.HandleIncreaseTargetBy(amount);
5555
}
5656

57-
public override void Interrupt(OperationReport report)
57+
public override void Interrupt()
5858
{
59-
switch (report.ConfirmationType)
60-
{
61-
case ConfirmationType.Final:
62-
NextState(StateCompleted);
63-
Context.HandleCompleted(report);
64-
break;
65-
case ConfirmationType.Partial:
66-
NextState(StateInterrupted);
67-
Context.HandleManualInterrupted(report);
68-
break;
69-
default:
70-
throw new ArgumentOutOfRangeException(nameof(report.ConfirmationType), report.ConfirmationType, null);
71-
}
59+
NextState(StateInterrupted);
60+
Context.HandleManualInterrupted();
7261
}
7362

7463
public override ReportContext GetReportContext()

src/Moryx.Orders.Management/Implementation/OperationData/States/OperationDataStateBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public virtual AdviceContext GetAdviceContext()
7272
return null;
7373
}
7474

75-
public virtual void Interrupt(OperationReport report) => InvalidState();
75+
public virtual void Interrupt() => InvalidState();
7676

7777
public virtual void Report(OperationReport report) => InvalidState();
7878

src/Moryx.Orders.Management/Implementation/OperationData/States/RunningState.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,10 @@ public override void IncreaseTargetBy(int amount, User user)
3434
public override void DecreaseTargetBy(int amount, User user)
3535
=> Context.HandleDecreaseTargetBy(amount);
3636

37-
public override void Interrupt(OperationReport report)
37+
public override void Interrupt()
3838
{
39-
switch (report.ConfirmationType)
40-
{
41-
case ConfirmationType.Partial:
42-
NextState(StateInterrupting);
43-
Context.HandleManualInterrupting(report);
44-
break;
45-
case ConfirmationType.Final:
46-
// ReSharper disable once ExplicitCallerInfoArgument
47-
InvalidState(nameof(Report) + "(final)");
48-
break;
49-
default:
50-
throw new ArgumentOutOfRangeException();
51-
}
39+
NextState(StateInterrupting);
40+
Context.HandleManualInterrupting();
5241
}
5342

5443
public override ReportContext GetReportContext()

src/Moryx.Orders.Management/Implementation/OperationManager/IOperationManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal interface IOperationManager
4545
/// <summary>
4646
/// Interrupts the given operation
4747
/// </summary>
48-
void Interrupt(IOperationData operationData, OperationReport report);
48+
void Interrupt(IOperationData operationData);
4949

5050
/// <summary>
5151
/// Aborts the given operation

src/Moryx.Orders.Management/Implementation/OperationManager/OperationManager.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,9 @@ public void Report(IOperationData operationData, OperationReport report)
155155
}
156156

157157
/// <inheritdoc />
158-
public void Interrupt(IOperationData operationData, OperationReport report)
158+
public void Interrupt(IOperationData operationData)
159159
{
160-
if (!report.User.SignedIn)
161-
throw new InvalidOperationException("User for the interrupt of the operation was not signed in.");
162-
163-
operationData.Interrupt(report);
160+
operationData.Interrupt();
164161
}
165162

166163
/// <inheritdoc />

0 commit comments

Comments
 (0)