Skip to content

Commit

Permalink
Exposed thrown exception for exceptions If
Browse files Browse the repository at this point in the history
  • Loading branch information
Greybird authored and phatboyg committed Mar 3, 2019
1 parent ab420d8 commit 397e764
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/Automatonymous/Binders/CatchExceptionActivityBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public ExceptionActivityBinder<TInstance, TException> Catch<T>(
return new CatchExceptionActivityBinder<TInstance, TException>(_machine, _event, _activities, activityBinder);
}

public ExceptionActivityBinder<TInstance, TException> If(StateMachineCondition<TInstance> condition,
public ExceptionActivityBinder<TInstance, TException> If(
StateMachineExceptionCondition<TInstance, TException> condition,
Func<ExceptionActivityBinder<TInstance, TException>, ExceptionActivityBinder<TInstance, TException>> activityCallback)
{
ExceptionActivityBinder<TInstance, TException> binder = new CatchExceptionActivityBinder<TInstance, TException>(_machine, _event);
Expand Down Expand Up @@ -154,9 +155,8 @@ public ExceptionActivityBinder<TInstance, TData, TException> Catch<T>(
return new CatchExceptionActivityBinder<TInstance, TData, TException>(_machine, _event, _activities, activityBinder);
}

public ExceptionActivityBinder<TInstance, TData, TException> If(StateMachineCondition<TInstance, TData> condition,
Func<ExceptionActivityBinder<TInstance, TData, TException>, ExceptionActivityBinder<TInstance, TData, TException>>
activityCallback)
public ExceptionActivityBinder<TInstance, TData, TException> If(StateMachineExceptionCondition<TInstance, TData, TException> condition,
Func<ExceptionActivityBinder<TInstance, TData, TException>, ExceptionActivityBinder<TInstance, TData, TException>> activityCallback)
{
ExceptionActivityBinder<TInstance, TData, TException> binder =
new CatchExceptionActivityBinder<TInstance, TData, TException>(_machine, _event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public class ConditionalExceptionActivityBinder<TInstance, TException> :
where TException : Exception
{
readonly EventActivities<TInstance> _activities;
readonly StateMachineCondition<TInstance> _condition;
readonly StateMachineExceptionCondition<TInstance, TException> _condition;
readonly Event _event;

public ConditionalExceptionActivityBinder(Event @event, StateMachineCondition<TInstance> condition, EventActivities<TInstance> activities)
public ConditionalExceptionActivityBinder(Event @event, StateMachineExceptionCondition<TInstance, TException> condition, EventActivities<TInstance> activities)
{
_activities = activities;
_condition = condition;
Expand Down Expand Up @@ -75,10 +75,10 @@ public class ConditionalExceptionActivityBinder<TInstance, TData, TException> :
where TException : Exception
{
readonly EventActivities<TInstance> _activities;
readonly StateMachineCondition<TInstance, TData> _condition;
readonly StateMachineExceptionCondition<TInstance, TData, TException> _condition;
readonly Event _event;

public ConditionalExceptionActivityBinder(Event @event, StateMachineCondition<TInstance, TData> condition,
public ConditionalExceptionActivityBinder(Event @event, StateMachineExceptionCondition<TInstance, TData, TException> condition,
EventActivities<TInstance> activities)
{
_activities = activities;
Expand Down
4 changes: 2 additions & 2 deletions src/Automatonymous/Binders/ExceptionActivityBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ExceptionActivityBinder<TInstance, TException> Catch<T>(
/// <param name="condition"></param>
/// <param name="activityCallback"></param>
/// <returns></returns>
ExceptionActivityBinder<TInstance, TException> If(StateMachineCondition<TInstance> condition,
ExceptionActivityBinder<TInstance, TException> If(StateMachineExceptionCondition<TInstance, TException> condition,
Func<ExceptionActivityBinder<TInstance, TException>, ExceptionActivityBinder<TInstance, TException>> activityCallback);
}

Expand Down Expand Up @@ -76,7 +76,7 @@ ExceptionActivityBinder<TInstance, TData, TException> Catch<T>(
/// <param name="condition"></param>
/// <param name="activityCallback"></param>
/// <returns></returns>
ExceptionActivityBinder<TInstance, TData, TException> If(StateMachineCondition<TInstance, TData> condition,
ExceptionActivityBinder<TInstance, TData, TException> If(StateMachineExceptionCondition<TInstance, TData, TException> condition,
Func<ExceptionActivityBinder<TInstance, TData, TException>, ExceptionActivityBinder<TInstance, TData, TException>>
activityCallback);
}
Expand Down
49 changes: 49 additions & 0 deletions src/Automatonymous/StateMachineExceptionCondition.cs
Original file line number Diff line number Diff line change
@@ -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;


/// <summary>
/// Filters activities based on the conditional statement
/// </summary>
/// <typeparam name="TInstance"></typeparam>
/// <typeparam name="TData"></typeparam>
/// <param name="context"></param>
/// <returns></returns>
public delegate bool StateMachineExceptionCondition<in TInstance, in TData, in TException>(BehaviorExceptionContext<TInstance, TData, TException> context)
where TException : Exception;


/// <summary>
/// Filters activities based on the conditional statement
/// </summary>
/// <typeparam name="TInstance"></typeparam>
/// <param name="context"></param>
/// <returns></returns>
public delegate bool StateMachineExceptionCondition<in TInstance, in TException>(BehaviorExceptionContext<TInstance, TException> context)
where TException : Exception;
}

0 comments on commit 397e764

Please sign in to comment.