Skip to content

Commit 401ee2b

Browse files
committed
Removed report from operation interrupt behaviour
1 parent 3ef9f50 commit 401ee2b

File tree

17 files changed

+58
-161
lines changed

17 files changed

+58
-161
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
## Moved classes and namespaces
6565

6666
- Moryx.Tools.FunctionResult: Moved to Moryx.Tools
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 & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using System.Net;
1414
using System.Threading.Channels;
1515
using Moryx.Orders.Endpoints.Models;
16-
using Moryx.Orders.Endpoints.Properties;
1716

1817
namespace Moryx.Orders.Endpoints
1918
{
@@ -69,7 +68,7 @@ public async Task OperationStream(CancellationToken cancelToken)
6968
var updateEventHandler = new EventHandler<OperationChangedEventArgs>((_, eventArgs) =>
7069
{
7170
var json = JsonConvert.SerializeObject(Converter.ToModel(eventArgs.Operation), _serializerSettings);
72-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Update.ToString(), json));
71+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Update), json));
7372
});
7473
_orderManagement.OperationUpdated += updateEventHandler;
7574

@@ -81,7 +80,7 @@ public async Task OperationStream(CancellationToken cancelToken)
8180
Advice = Converter.ToModel(eventArgs.Advice)
8281
};
8382
var json = JsonConvert.SerializeObject(advicedOperation, _serializerSettings);
84-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Advice.ToString(), json));
83+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Advice), json));
8584
});
8685
_orderManagement.OperationAdviced += adviceEventHandler;
8786

@@ -93,19 +92,14 @@ public async Task OperationStream(CancellationToken cancelToken)
9392
Report = Converter.ToModel(eventArgs.Report)
9493
};
9594
var json = JsonConvert.SerializeObject(reportedOperation, _serializerSettings);
96-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Report.ToString(), json));
95+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Report), json));
9796
});
9897
_orderManagement.OperationPartialReport += reportEventHandler;
9998

100-
var interruptedEventHandler = new EventHandler<OperationReportEventArgs>((_, eventArgs) =>
99+
var interruptedEventHandler = new EventHandler<OperationChangedEventArgs>((_, eventArgs) =>
101100
{
102-
var interruptedOperation = new OperationReportedModel
103-
{
104-
OperationModel = Converter.ToModel(eventArgs.Operation),
105-
Report = Converter.ToModel(eventArgs.Report)
106-
};
107-
var json = JsonConvert.SerializeObject(interruptedOperation, _serializerSettings);
108-
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));
109103
});
110104
_orderManagement.OperationInterrupted += interruptedEventHandler;
111105

@@ -117,7 +111,7 @@ public async Task OperationStream(CancellationToken cancelToken)
117111
Report = Converter.ToModel(eventArgs.Report)
118112
};
119113
var json = JsonConvert.SerializeObject(completedOperation, _serializerSettings);
120-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Completed.ToString(), json));
114+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Completed), json));
121115
});
122116
_orderManagement.OperationCompleted += completedEventHandler;
123117

@@ -129,14 +123,14 @@ public async Task OperationStream(CancellationToken cancelToken)
129123
UserId = eventArgs.User.Identifier
130124
};
131125
var json = JsonConvert.SerializeObject(startedOperation, _serializerSettings);
132-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Start.ToString(), json));
126+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Start), json));
133127
});
134128
_orderManagement.OperationStarted += startedEventHandler;
135129

136130
var changedEventHandler = new EventHandler<OperationChangedEventArgs>((_, eventArgs) =>
137131
{
138132
var json = JsonConvert.SerializeObject(Converter.ToModel(eventArgs.Operation), _serializerSettings);
139-
operationsChannel.Writer.TryWrite(new Tuple<string, string>(OperationTypes.Progress.ToString(), json));
133+
operationsChannel.Writer.TryWrite(new Tuple<string, string>(nameof(OperationTypes.Progress), json));
140134
});
141135
_orderManagement.OperationProgressChanged += changedEventHandler;
142136

@@ -425,13 +419,13 @@ public ActionResult ReportOperation(Guid guid, ReportModel report)
425419
[ProducesResponseType(typeof(MoryxExceptionResponse), StatusCodes.Status404NotFound)]
426420
[Route("{guid}/interrupt")]
427421
[Authorize(Policy = OrderPermissions.CanInterrupt)]
428-
public ActionResult InterruptOperation(Guid guid, ReportModel report)
422+
public ActionResult InterruptOperation(Guid guid)
429423
{
430424
var operation = _orderManagement.GetOperation(guid);
431425
if (operation == null)
432426
return NotFound(new MoryxExceptionResponse { Title = Strings.OrderManagementController_OperationNotFound });
433427

434-
_orderManagement.InterruptOperation(operation, Converter.FromModel(report, _userManagement));
428+
_orderManagement.InterruptOperation(operation);
435429
return Ok();
436430
}
437431

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)