From 397e764561976ae48f6e99aea72210aac2720718 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Sun, 3 Mar 2019 07:44:51 +0100 Subject: [PATCH] Exposed thrown exception for exceptions If --- .../Binders/CatchExceptionActivityBinder.cs | 8 +-- .../ConditionalExceptionActivityBinder.cs | 8 +-- .../Binders/ExceptionActivityBinder.cs | 4 +- .../StateMachineExceptionCondition.cs | 49 +++++++++++++++++++ 4 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 src/Automatonymous/StateMachineExceptionCondition.cs diff --git a/src/Automatonymous/Binders/CatchExceptionActivityBinder.cs b/src/Automatonymous/Binders/CatchExceptionActivityBinder.cs index 2de0860..5b3e0e6 100644 --- a/src/Automatonymous/Binders/CatchExceptionActivityBinder.cs +++ b/src/Automatonymous/Binders/CatchExceptionActivityBinder.cs @@ -74,7 +74,8 @@ public ExceptionActivityBinder Catch( return new CatchExceptionActivityBinder(_machine, _event, _activities, activityBinder); } - public ExceptionActivityBinder If(StateMachineCondition condition, + public ExceptionActivityBinder If( + StateMachineExceptionCondition condition, Func, ExceptionActivityBinder> activityCallback) { ExceptionActivityBinder binder = new CatchExceptionActivityBinder(_machine, _event); @@ -154,9 +155,8 @@ public ExceptionActivityBinder Catch( return new CatchExceptionActivityBinder(_machine, _event, _activities, activityBinder); } - public ExceptionActivityBinder If(StateMachineCondition condition, - Func, ExceptionActivityBinder> - activityCallback) + public ExceptionActivityBinder If(StateMachineExceptionCondition condition, + Func, ExceptionActivityBinder> activityCallback) { ExceptionActivityBinder binder = new CatchExceptionActivityBinder(_machine, _event); diff --git a/src/Automatonymous/Binders/ConditionalExceptionActivityBinder.cs b/src/Automatonymous/Binders/ConditionalExceptionActivityBinder.cs index 643e9a5..3df49fc 100644 --- a/src/Automatonymous/Binders/ConditionalExceptionActivityBinder.cs +++ b/src/Automatonymous/Binders/ConditionalExceptionActivityBinder.cs @@ -23,10 +23,10 @@ public class ConditionalExceptionActivityBinder : where TException : Exception { readonly EventActivities _activities; - readonly StateMachineCondition _condition; + readonly StateMachineExceptionCondition _condition; readonly Event _event; - public ConditionalExceptionActivityBinder(Event @event, StateMachineCondition condition, EventActivities activities) + public ConditionalExceptionActivityBinder(Event @event, StateMachineExceptionCondition condition, EventActivities activities) { _activities = activities; _condition = condition; @@ -75,10 +75,10 @@ public class ConditionalExceptionActivityBinder : where TException : Exception { readonly EventActivities _activities; - readonly StateMachineCondition _condition; + readonly StateMachineExceptionCondition _condition; readonly Event _event; - public ConditionalExceptionActivityBinder(Event @event, StateMachineCondition condition, + public ConditionalExceptionActivityBinder(Event @event, StateMachineExceptionCondition condition, EventActivities activities) { _activities = activities; diff --git a/src/Automatonymous/Binders/ExceptionActivityBinder.cs b/src/Automatonymous/Binders/ExceptionActivityBinder.cs index 9520e8e..a0b7155 100644 --- a/src/Automatonymous/Binders/ExceptionActivityBinder.cs +++ b/src/Automatonymous/Binders/ExceptionActivityBinder.cs @@ -42,7 +42,7 @@ ExceptionActivityBinder Catch( /// /// /// - ExceptionActivityBinder If(StateMachineCondition condition, + ExceptionActivityBinder If(StateMachineExceptionCondition condition, Func, ExceptionActivityBinder> activityCallback); } @@ -76,7 +76,7 @@ ExceptionActivityBinder Catch( /// /// /// - ExceptionActivityBinder If(StateMachineCondition condition, + ExceptionActivityBinder If(StateMachineExceptionCondition condition, Func, ExceptionActivityBinder> activityCallback); } diff --git a/src/Automatonymous/StateMachineExceptionCondition.cs b/src/Automatonymous/StateMachineExceptionCondition.cs new file mode 100644 index 0000000..5344798 --- /dev/null +++ b/src/Automatonymous/StateMachineExceptionCondition.cs @@ -0,0 +1,49 @@ +// Copyright 2011-2019 Chris Patterson, Dru Sellers +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +// Copyright 2011-2019 Chris Patterson, Dru Sellers +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +namespace Automatonymous +{ + using System; + + + /// + /// Filters activities based on the conditional statement + /// + /// + /// + /// + /// + public delegate bool StateMachineExceptionCondition(BehaviorExceptionContext context) + where TException : Exception; + + + /// + /// Filters activities based on the conditional statement + /// + /// + /// + /// + public delegate bool StateMachineExceptionCondition(BehaviorExceptionContext context) + where TException : Exception; +} \ No newline at end of file