Skip to content
Snippets Groups Projects
Commit 2255ae40 authored by Tobias's avatar Tobias
Browse files

Component goes into Aborting if any exception passes to OperationModeBase

parent 10cde167
No related branches found
No related tags found
No related merge requests found
......@@ -182,7 +182,7 @@ namespace ControlComponents.Core
// TODO it is also possible to Deselect here and then Select new opmode?
if (this.operationMode != null)
{
throw new InvalidOperationException("There is already an operation mode selected");
throw new InvalidOperationException($"There is already {OpModeName} selected");
}
else
{
......
......@@ -80,7 +80,7 @@ namespace ControlComponents.Core
runningOutputs.Add(role, outputs[role].SelectOperationMode(operationMode));
}
protected virtual void Selected() {}
protected virtual void Selected() { }
protected virtual Task Deselected() { return Task.CompletedTask; }
public async Task Select(IExecution execution, IDictionary<string, IOrderOutput> orderOutputs)
......@@ -105,18 +105,21 @@ namespace ControlComponents.Core
while (!mainTokenSource.IsCancellationRequested)
{
executionTokenSource = new CancellationTokenSource();
logger.Debug($"{execution.ComponentName} Invoke {execution.EXST} action");
await stateActions[execution.EXST].Invoke(executionTokenSource.Token);
try
{
executionTokenSource = new CancellationTokenSource();
logger.Debug($"{execution.ComponentName} Invoke {execution.EXST} action");
await stateActions[execution.EXST].Invoke(executionTokenSource.Token);
}
catch (System.Exception e)
{
// TODO how to handle error in Aborting state => right now setState will throw ex, but if it is handled we get a infinite error loop
logger.Error(e, $"{this.execution.ComponentName}: {OpModeName} failed in {execution.EXST}");
this.execution.SetState(ExecutionState.ABORTING);
}
}
execution.ExecutionStateChanged -= OnExecutionStateChanged;
}
catch (System.Exception e)
{
// TODO go to ABORTING?
logger.Error(e);
throw e;
}
finally
{
// TODO what should happen with not STOPPED outputs, that are ABORTED for example?
......@@ -181,7 +184,7 @@ namespace ControlComponents.Core
await Starting(token);
if (!token.IsCancellationRequested)
{
execution.SetState(ExecutionState.EXECUTE);
}
}
......@@ -191,7 +194,7 @@ namespace ControlComponents.Core
await Stopping(token);
if (!token.IsCancellationRequested)
{
execution.SetState(ExecutionState.STOPPED);
}
}
......@@ -201,7 +204,7 @@ namespace ControlComponents.Core
await Aborting(token);
if (!token.IsCancellationRequested)
{
execution.SetState(ExecutionState.ABORTED);
}
}
......@@ -258,7 +261,7 @@ namespace ControlComponents.Core
private async Task Execute_(CancellationToken token)
{
await Execute(token);
if (!token.IsCancellationRequested)
{
......
......@@ -149,17 +149,6 @@ namespace ControlComponents.Core.Tests
externalCCOutput.IsSet.Should().BeFalse();
}
[Test]
[Ignore("Cases where an output can not be set exist")]
// TODO how can a missing output be simulated?
public async Task Given_MissingOutput_When_SelectOperationMode_Then_Abort()
{
sut.ClearOutput(ROLE);
running = sut.SelectOperationMode(NormalOpMode);
await sut.WaitForAborted();
sut.EXST.Should().Be(ExecutionState.ABORTED);
}
[Test]
public void When_Created_Then_CorrectHierarchyConfiguration()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment