From a4a0beb6f23d38151d0b8eb4f2bdd409b9774dc9 Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Thu, 15 Sep 2016 11:07:20 -0700 Subject: [PATCH] Added probe support for diagnostics --- .../AsyncActivity_Specs.cs | 5 +++++ src/Automatonymous.Tests/Dependency_Specs.cs | 5 +++++ src/Automatonymous.Tests/Request_Specs.cs | 5 +++++ .../Accessors/DefaultInstanceStateAccessor.cs | 6 +++++ .../Accessors/InitialIfNullStateAccessor.cs | 6 +++++ .../Accessors/IntStateAccessor.cs | 6 +++++ .../Accessors/RawStateAccessor.cs | 6 +++++ .../Accessors/StringStateAccessor.cs | 6 +++++ .../Activities/ActionActivity.cs | 19 +++++++++++++--- .../Activities/AsyncActivity.cs | 13 ++++++++++- .../Activities/AsyncFactoryActivity.cs | 11 ++++++++++ .../Activities/CatchFaultActivity.cs | 10 ++++++++- .../Activities/CompositeEventActivity.cs | 8 +++++++ .../Activities/ConditionalEventActivity.cs | 8 +++++++ .../Activities/DataConverterActivity.cs | 8 ++++++- .../Activities/ExceptionBehavior.cs | 13 ++++++++++- .../Activities/ExecuteOnFaultedActivity.cs | 8 ++++++- .../Activities/FactoryActivity.cs | 19 +++++++++++++--- .../Activities/FaultedActionActivity.cs | 11 ++++++++++ src/Automatonymous/Activities/SlimActivity.cs | 6 +++++ .../Activities/TransitionActivity.cs | 7 ++++++ .../AutomatonymousStateMachine.cs | 20 +++++++++++++++++ .../Behaviors/ActivityBehavior.cs | 7 ++++++ src/Automatonymous/Behaviors/DataBehavior.cs | 6 +++++ src/Automatonymous/Behaviors/EmptyBehavior.cs | 9 ++++++++ .../Behaviors/ExceptionBehavior.cs | 11 ++++++++++ src/Automatonymous/Behaviors/LastBehavior.cs | 7 ++++++ .../Behaviors/LastFaultedBehavior.cs | 8 ++++++- src/Automatonymous/Behaviors/WidenBehavior.cs | 6 +++++ src/Automatonymous/Events/TriggerEvent.cs | 13 +++++++++-- src/Automatonymous/StateAccessor.cs | 12 +++++----- .../States/StateMachineState.cs | 22 +++++++++++++++++++ src/Automatonymous/Visitable.cs | 6 ++++- 33 files changed, 293 insertions(+), 20 deletions(-) diff --git a/src/Automatonymous.Tests/AsyncActivity_Specs.cs b/src/Automatonymous.Tests/AsyncActivity_Specs.cs index 47936c5..abff079 100644 --- a/src/Automatonymous.Tests/AsyncActivity_Specs.cs +++ b/src/Automatonymous.Tests/AsyncActivity_Specs.cs @@ -14,6 +14,7 @@ namespace Automatonymous.Tests { using System; using System.Threading.Tasks; + using GreenPipes; using NUnit.Framework; @@ -45,6 +46,10 @@ void Visitable.Accept(StateMachineVisitor visitor) { visitor.Visit(this); } + + public void Probe(ProbeContext context) + { + } } diff --git a/src/Automatonymous.Tests/Dependency_Specs.cs b/src/Automatonymous.Tests/Dependency_Specs.cs index 80e52b0..7b62e55 100644 --- a/src/Automatonymous.Tests/Dependency_Specs.cs +++ b/src/Automatonymous.Tests/Dependency_Specs.cs @@ -15,6 +15,7 @@ namespace Automatonymous.Tests using System; using System.Threading.Tasks; using Activities; + using GreenPipes; using NUnit.Framework; @@ -76,6 +77,10 @@ public void Accept(StateMachineVisitor visitor) { visitor.Visit(this); } + + public void Probe(ProbeContext context) + { + } } diff --git a/src/Automatonymous.Tests/Request_Specs.cs b/src/Automatonymous.Tests/Request_Specs.cs index 33adb8a..e231e06 100644 --- a/src/Automatonymous.Tests/Request_Specs.cs +++ b/src/Automatonymous.Tests/Request_Specs.cs @@ -19,6 +19,7 @@ namespace Request_Specs using System.Reflection; using System.Threading.Tasks; using Binders; + using GreenPipes; using NUnit.Framework; @@ -363,6 +364,10 @@ public Task Faulted(BehaviorExceptionContext @@ -82,5 +83,10 @@ StateAccessor CreateDefaultAccessor() return new InitialIfNullStateAccessor(_initialState, new RawStateAccessor(_machine, expression, _observer)); } + + public void Probe(ProbeContext context) + { + _accessor.Value.Probe(context); + } } } \ No newline at end of file diff --git a/src/Automatonymous/Accessors/InitialIfNullStateAccessor.cs b/src/Automatonymous/Accessors/InitialIfNullStateAccessor.cs index 7f5509a..9d50b20 100644 --- a/src/Automatonymous/Accessors/InitialIfNullStateAccessor.cs +++ b/src/Automatonymous/Accessors/InitialIfNullStateAccessor.cs @@ -16,6 +16,7 @@ namespace Automatonymous.Accessors using Activities; using Behaviors; using Contexts; + using GreenPipes; public class InitialIfNullStateAccessor : @@ -51,5 +52,10 @@ Task StateAccessor.Set(InstanceContext context, State GetCurrentStateProperty(Expression(propertyInfo); } + + public void Probe(ProbeContext context) + { + context.Add("currentStateProperty", _property.Property.Name); + } } } \ No newline at end of file diff --git a/src/Automatonymous/Accessors/RawStateAccessor.cs b/src/Automatonymous/Accessors/RawStateAccessor.cs index b7c8d78..d02e5d4 100644 --- a/src/Automatonymous/Accessors/RawStateAccessor.cs +++ b/src/Automatonymous/Accessors/RawStateAccessor.cs @@ -16,6 +16,7 @@ namespace Automatonymous.Accessors using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; + using GreenPipes; using GreenPipes.Internals.Extensions; using GreenPipes.Internals.Reflection; using GreenPipes.Util; @@ -65,6 +66,11 @@ Task StateAccessor.Set(InstanceContext context, State GetCurrentStateProperty(Expression> currentStateExpression) { PropertyInfo propertyInfo = currentStateExpression.GetPropertyInfo(); diff --git a/src/Automatonymous/Accessors/StringStateAccessor.cs b/src/Automatonymous/Accessors/StringStateAccessor.cs index faa4033..ca64146 100644 --- a/src/Automatonymous/Accessors/StringStateAccessor.cs +++ b/src/Automatonymous/Accessors/StringStateAccessor.cs @@ -16,6 +16,7 @@ namespace Automatonymous.Accessors using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; + using GreenPipes; using GreenPipes.Internals.Extensions; using GreenPipes.Internals.Reflection; using GreenPipes.Util; @@ -75,5 +76,10 @@ static ReadWriteProperty GetCurrentStateProperty(Expression(propertyInfo); } + + public void Probe(ProbeContext context) + { + context.Add("currentStateProperty", _property.Property.Name); + } } } \ No newline at end of file diff --git a/src/Automatonymous/Activities/ActionActivity.cs b/src/Automatonymous/Activities/ActionActivity.cs index 8942de6..54e6096 100644 --- a/src/Automatonymous/Activities/ActionActivity.cs +++ b/src/Automatonymous/Activities/ActionActivity.cs @@ -1,4 +1,4 @@ -// Copyright 2011-2014 Chris Patterson, Dru Sellers +// Copyright 2011-2016 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 @@ -14,6 +14,7 @@ namespace Automatonymous.Activities { using System; using System.Threading.Tasks; + using GreenPipes; public class ActionActivity : @@ -31,6 +32,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("action"); + } + async Task Activity.Execute(BehaviorContext context, Behavior next) { _action(context); @@ -50,7 +56,8 @@ Task Activity.Faulted(BehaviorExceptionContext.Faulted(BehaviorExceptionContext context, Behavior next) + Task Activity.Faulted(BehaviorExceptionContext context, + Behavior next) { return next.Faulted(context); } @@ -72,6 +79,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("action"); + } + async Task Activity.Execute(BehaviorContext context, Behavior next) { _action(context); @@ -79,7 +91,8 @@ async Task Activity.Execute(BehaviorContext await next.Execute(context).ConfigureAwait(false); } - Task Activity.Faulted(BehaviorExceptionContext context, Behavior next) + Task Activity.Faulted(BehaviorExceptionContext context, + Behavior next) { return next.Faulted(context); } diff --git a/src/Automatonymous/Activities/AsyncActivity.cs b/src/Automatonymous/Activities/AsyncActivity.cs index f003e69..4e3d91c 100644 --- a/src/Automatonymous/Activities/AsyncActivity.cs +++ b/src/Automatonymous/Activities/AsyncActivity.cs @@ -1,4 +1,4 @@ -// Copyright 2011-2015 Chris Patterson, Dru Sellers +// Copyright 2011-2016 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 @@ -14,6 +14,7 @@ namespace Automatonymous.Activities { using System; using System.Threading.Tasks; + using GreenPipes; public class AsyncActivity : @@ -31,6 +32,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("action"); + } + async Task Activity.Execute(BehaviorContext context, Behavior next) { await _asyncAction(context).ConfigureAwait(false); @@ -73,6 +79,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("action"); + } + async Task Activity.Execute(BehaviorContext context, Behavior next) { await _asyncAction(context).ConfigureAwait(false); diff --git a/src/Automatonymous/Activities/AsyncFactoryActivity.cs b/src/Automatonymous/Activities/AsyncFactoryActivity.cs index 06d703a..88209a7 100644 --- a/src/Automatonymous/Activities/AsyncFactoryActivity.cs +++ b/src/Automatonymous/Activities/AsyncFactoryActivity.cs @@ -15,6 +15,7 @@ namespace Automatonymous.Activities using System; using System.Threading.Tasks; using Behaviors; + using GreenPipes; public class AsyncFactoryActivity : @@ -32,6 +33,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("activityFactory"); + } + async Task Activity.Execute(BehaviorContext context, Behavior next) { Activity activity = await _activityFactory(context).ConfigureAwait(false); @@ -62,6 +68,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("activityFactory"); + } + async Task Activity.Execute(BehaviorContext context, Behavior next) { Activity activity = await _activityFactory(context).ConfigureAwait(false); diff --git a/src/Automatonymous/Activities/CatchFaultActivity.cs b/src/Automatonymous/Activities/CatchFaultActivity.cs index e456ab8..f934f64 100644 --- a/src/Automatonymous/Activities/CatchFaultActivity.cs +++ b/src/Automatonymous/Activities/CatchFaultActivity.cs @@ -1,4 +1,4 @@ -// Copyright 2011-2015 Chris Patterson, Dru Sellers +// Copyright 2011-2016 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 @@ -14,6 +14,7 @@ namespace Automatonymous.Activities { using System; using System.Threading.Tasks; + using GreenPipes; /// @@ -38,6 +39,13 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this, x => _behavior.Accept(visitor)); } + public void Probe(ProbeContext context) + { + var scope = context.CreateScope("catchFault"); + + _behavior.Probe(scope); + } + Task Activity.Execute(BehaviorContext context, Behavior next) { return next.Execute(context); diff --git a/src/Automatonymous/Activities/CompositeEventActivity.cs b/src/Automatonymous/Activities/CompositeEventActivity.cs index e7892e5..d9fd753 100644 --- a/src/Automatonymous/Activities/CompositeEventActivity.cs +++ b/src/Automatonymous/Activities/CompositeEventActivity.cs @@ -14,6 +14,7 @@ namespace Automatonymous.Activities { using System.Threading.Tasks; using Accessors; + using GreenPipes; using GreenPipes.Util; @@ -41,6 +42,13 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + var scope = context.CreateScope("compositeEvent"); + scope.Add("event", _event.Name); + scope.Add("flag", _flag.ToString("X8")); + } + async Task Activity.Execute(BehaviorContext context, Behavior next) { await Execute(context).ConfigureAwait(false); diff --git a/src/Automatonymous/Activities/ConditionalEventActivity.cs b/src/Automatonymous/Activities/ConditionalEventActivity.cs index 5950e04..59b4f15 100644 --- a/src/Automatonymous/Activities/ConditionalEventActivity.cs +++ b/src/Automatonymous/Activities/ConditionalEventActivity.cs @@ -13,6 +13,7 @@ namespace Automatonymous.Activities { using System.Threading.Tasks; + using GreenPipes; /// @@ -37,6 +38,13 @@ public void Accept(StateMachineVisitor visitor) visitor.Visit(this, x => _activity.Accept(visitor)); } + public void Probe(ProbeContext context) + { + var scope = context.CreateScope("conditional"); + + _activity.Probe(scope); + } + Task Activity.Execute(BehaviorContext context, Behavior next) { if (_filter(context)) diff --git a/src/Automatonymous/Activities/DataConverterActivity.cs b/src/Automatonymous/Activities/DataConverterActivity.cs index ca33e5b..dba9449 100644 --- a/src/Automatonymous/Activities/DataConverterActivity.cs +++ b/src/Automatonymous/Activities/DataConverterActivity.cs @@ -1,4 +1,4 @@ -// Copyright 2011-2015 Chris Patterson, Dru Sellers +// Copyright 2011-2016 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 @@ -13,6 +13,7 @@ namespace Automatonymous.Activities { using System.Threading.Tasks; + using GreenPipes; public class DataConverterActivity : @@ -30,6 +31,11 @@ public void Accept(StateMachineVisitor visitor) visitor.Visit(this, x => _activity.Accept(visitor)); } + public void Probe(ProbeContext context) + { + _activity.Probe(context); + } + Task Activity.Execute(BehaviorContext context, Behavior next) { throw new AutomatonymousException("This activity requires a body with the event, but no body was specified."); diff --git a/src/Automatonymous/Activities/ExceptionBehavior.cs b/src/Automatonymous/Activities/ExceptionBehavior.cs index 3ae1989..1f2c98b 100644 --- a/src/Automatonymous/Activities/ExceptionBehavior.cs +++ b/src/Automatonymous/Activities/ExceptionBehavior.cs @@ -1,4 +1,4 @@ -// Copyright 2011-2015 Chris Patterson, Dru Sellers +// Copyright 2011-2016 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 @@ -14,6 +14,7 @@ namespace Automatonymous.Activities { using System; using System.Threading.Tasks; + using GreenPipes; public class ExceptionBehavior : @@ -34,6 +35,11 @@ void Visitable.Accept(StateMachineVisitor visitor) _next.Accept(visitor); } + public void Probe(ProbeContext context) + { + _next.Probe(context); + } + Task Behavior.Execute(BehaviorContext context) { return _next.Faulted(_context); @@ -74,6 +80,11 @@ void Visitable.Accept(StateMachineVisitor visitor) _next.Accept(visitor); } + public void Probe(ProbeContext context) + { + _next.Probe(context); + } + Task Behavior.Execute(BehaviorContext context) { return _next.Faulted(_context); diff --git a/src/Automatonymous/Activities/ExecuteOnFaultedActivity.cs b/src/Automatonymous/Activities/ExecuteOnFaultedActivity.cs index d766b0b..bf9d79d 100644 --- a/src/Automatonymous/Activities/ExecuteOnFaultedActivity.cs +++ b/src/Automatonymous/Activities/ExecuteOnFaultedActivity.cs @@ -1,4 +1,4 @@ -// Copyright 2011-2015 Chris Patterson, Dru Sellers +// Copyright 2011-2016 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 @@ -14,6 +14,7 @@ namespace Automatonymous.Activities { using System; using System.Threading.Tasks; + using GreenPipes; public class ExecuteOnFaultedActivity : @@ -31,6 +32,11 @@ public void Accept(StateMachineVisitor visitor) _activity.Accept(visitor); } + public void Probe(ProbeContext context) + { + _activity.Probe(context); + } + public Task Execute(BehaviorContext context, Behavior next) { return next.Execute(context); diff --git a/src/Automatonymous/Activities/FactoryActivity.cs b/src/Automatonymous/Activities/FactoryActivity.cs index 20b6d28..0f1223f 100644 --- a/src/Automatonymous/Activities/FactoryActivity.cs +++ b/src/Automatonymous/Activities/FactoryActivity.cs @@ -1,4 +1,4 @@ -// Copyright 2011-2015 Chris Patterson, Dru Sellers +// Copyright 2011-2016 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 @@ -15,6 +15,7 @@ namespace Automatonymous.Activities using System; using System.Threading.Tasks; using Behaviors; + using GreenPipes; public class FactoryActivity : @@ -32,6 +33,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("factory"); + } + Task Activity.Execute(BehaviorContext context, Behavior next) { Activity activity = _activityFactory(context); @@ -53,7 +59,8 @@ Task Activity.Faulted(BehaviorExceptionContext.Faulted(BehaviorExceptionContext context, Behavior next) + Task Activity.Faulted(BehaviorExceptionContext context, + Behavior next) { return next.Faulted(context); } @@ -75,6 +82,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("factory"); + } + Task Activity.Execute(BehaviorContext context, Behavior next) { Activity activity = _activityFactory(context); @@ -82,7 +94,8 @@ Task Activity.Execute(BehaviorContext contex return activity.Execute(context, next); } - Task Activity.Faulted(BehaviorExceptionContext context, Behavior next) + Task Activity.Faulted(BehaviorExceptionContext context, + Behavior next) { return next.Faulted(context); } diff --git a/src/Automatonymous/Activities/FaultedActionActivity.cs b/src/Automatonymous/Activities/FaultedActionActivity.cs index 5486597..cf44eb6 100644 --- a/src/Automatonymous/Activities/FaultedActionActivity.cs +++ b/src/Automatonymous/Activities/FaultedActionActivity.cs @@ -14,6 +14,7 @@ namespace Automatonymous.Activities { using System; using System.Threading.Tasks; + using GreenPipes; public class FaultedActionActivity : @@ -32,6 +33,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("faultedAction"); + } + Task Activity.Execute(BehaviorContext context, Behavior next) { return next.Execute(context); @@ -80,6 +86,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("faultedAction"); + } + Task Activity.Execute(BehaviorContext context, Behavior next) { return next.Execute(context); diff --git a/src/Automatonymous/Activities/SlimActivity.cs b/src/Automatonymous/Activities/SlimActivity.cs index fd19e28..beae4c9 100644 --- a/src/Automatonymous/Activities/SlimActivity.cs +++ b/src/Automatonymous/Activities/SlimActivity.cs @@ -14,6 +14,7 @@ namespace Automatonymous.Activities { using System.Threading.Tasks; using Behaviors; + using GreenPipes; /// @@ -36,6 +37,11 @@ void Visitable.Accept(StateMachineVisitor visitor) _activity.Accept(visitor); } + public void Probe(ProbeContext context) + { + _activity.Probe(context); + } + Task Activity.Execute(BehaviorContext context, Behavior behavior) { var upconvert = new WidenBehavior(behavior, context); diff --git a/src/Automatonymous/Activities/TransitionActivity.cs b/src/Automatonymous/Activities/TransitionActivity.cs index ca74d3a..bbfd7d3 100644 --- a/src/Automatonymous/Activities/TransitionActivity.cs +++ b/src/Automatonymous/Activities/TransitionActivity.cs @@ -13,6 +13,7 @@ namespace Automatonymous.Activities { using System.Threading.Tasks; + using GreenPipes; public class TransitionActivity : @@ -35,6 +36,12 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + var scope = context.CreateScope("transition"); + scope.Add("toState", _toState.Name); + } + async Task Activity.Execute(BehaviorContext context, Behavior next) { await Transition(context).ConfigureAwait(false); diff --git a/src/Automatonymous/AutomatonymousStateMachine.cs b/src/Automatonymous/AutomatonymousStateMachine.cs index 97d79f4..9fb37bf 100644 --- a/src/Automatonymous/AutomatonymousStateMachine.cs +++ b/src/Automatonymous/AutomatonymousStateMachine.cs @@ -23,6 +23,7 @@ namespace Automatonymous using Binders; using Contexts; using Events; + using GreenPipes; using GreenPipes.Internals.Extensions; using Observers; using States; @@ -153,6 +154,25 @@ void Visitable.Accept(StateMachineVisitor visitor) Final.Accept(visitor); } + public void Probe(ProbeContext context) + { + var scope = context.CreateScope("stateMachine"); + scope.Add("type", TypeNameCache.GetShortName(GetType())); + + Initial.Probe(scope); + + foreach (var state in _stateCache.Values) + { + if (Equals(state, Initial) || Equals(state, Final)) + continue; + + state.Probe(scope); + } + + Final.Probe(scope); + } + + IDisposable StateMachine.ConnectEventObserver(EventObserver observer) { var eventObserver = new NonTransitionEventObserver(_eventCache, observer); diff --git a/src/Automatonymous/Behaviors/ActivityBehavior.cs b/src/Automatonymous/Behaviors/ActivityBehavior.cs index ea820bb..a1a5e26 100644 --- a/src/Automatonymous/Behaviors/ActivityBehavior.cs +++ b/src/Automatonymous/Behaviors/ActivityBehavior.cs @@ -14,6 +14,7 @@ namespace Automatonymous.Behaviors { using System; using System.Threading.Tasks; + using GreenPipes; public class ActivityBehavior : @@ -37,6 +38,12 @@ void Visitable.Accept(StateMachineVisitor visitor) }); } + public void Probe(ProbeContext context) + { + _activity.Probe(context); + _next.Probe(context); + } + async Task Behavior.Execute(BehaviorContext context) { try diff --git a/src/Automatonymous/Behaviors/DataBehavior.cs b/src/Automatonymous/Behaviors/DataBehavior.cs index 8797f60..9144da2 100644 --- a/src/Automatonymous/Behaviors/DataBehavior.cs +++ b/src/Automatonymous/Behaviors/DataBehavior.cs @@ -13,6 +13,7 @@ namespace Automatonymous.Behaviors { using System.Threading.Tasks; + using GreenPipes; /// @@ -35,6 +36,11 @@ void Visitable.Accept(StateMachineVisitor visitor) _behavior.Accept(visitor); } + public void Probe(ProbeContext context) + { + _behavior.Probe(context); + } + Task Behavior.Execute(BehaviorContext context) { return _behavior.Execute(context); diff --git a/src/Automatonymous/Behaviors/EmptyBehavior.cs b/src/Automatonymous/Behaviors/EmptyBehavior.cs index 1ea1d17..671eb2a 100644 --- a/src/Automatonymous/Behaviors/EmptyBehavior.cs +++ b/src/Automatonymous/Behaviors/EmptyBehavior.cs @@ -13,6 +13,7 @@ namespace Automatonymous.Behaviors { using System.Threading.Tasks; + using GreenPipes; using GreenPipes.Util; @@ -24,6 +25,10 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + } + Task Behavior.Execute(BehaviorContext context) { return TaskUtil.Completed; @@ -54,6 +59,10 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + } + Task Behavior.Execute(BehaviorContext context) { return TaskUtil.Completed; diff --git a/src/Automatonymous/Behaviors/ExceptionBehavior.cs b/src/Automatonymous/Behaviors/ExceptionBehavior.cs index 606d632..da1181d 100644 --- a/src/Automatonymous/Behaviors/ExceptionBehavior.cs +++ b/src/Automatonymous/Behaviors/ExceptionBehavior.cs @@ -13,6 +13,7 @@ namespace Automatonymous.Behaviors { using System.Threading.Tasks; + using GreenPipes; using GreenPipes.Util; @@ -24,6 +25,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("exception"); + } + Task Behavior.Execute(BehaviorContext context) { return TaskUtil.Completed; @@ -54,6 +60,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + context.CreateScope("exception"); + } + Task Behavior.Execute(BehaviorContext context) { return TaskUtil.Completed; diff --git a/src/Automatonymous/Behaviors/LastBehavior.cs b/src/Automatonymous/Behaviors/LastBehavior.cs index 04b9495..0c87f12 100644 --- a/src/Automatonymous/Behaviors/LastBehavior.cs +++ b/src/Automatonymous/Behaviors/LastBehavior.cs @@ -13,6 +13,8 @@ namespace Automatonymous.Behaviors { using System.Threading.Tasks; + using GreenPipes; + /// /// The last behavior either completes the last activity in the behavior or @@ -34,6 +36,11 @@ void Visitable.Accept(StateMachineVisitor visitor) _activity.Accept(visitor); } + public void Probe(ProbeContext context) + { + _activity.Probe(context); + } + Task Behavior.Execute(BehaviorContext context) { return _activity.Execute(context, Behavior.Empty()); diff --git a/src/Automatonymous/Behaviors/LastFaultedBehavior.cs b/src/Automatonymous/Behaviors/LastFaultedBehavior.cs index b5beb5e..eada3ca 100644 --- a/src/Automatonymous/Behaviors/LastFaultedBehavior.cs +++ b/src/Automatonymous/Behaviors/LastFaultedBehavior.cs @@ -1,4 +1,4 @@ -// Copyright 2011-2015 Chris Patterson, Dru Sellers +// Copyright 2011-2016 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 @@ -13,6 +13,7 @@ namespace Automatonymous.Behaviors { using System.Threading.Tasks; + using GreenPipes; /// @@ -35,6 +36,11 @@ void Visitable.Accept(StateMachineVisitor visitor) _activity.Accept(visitor); } + public void Probe(ProbeContext context) + { + _activity.Probe(context); + } + Task Behavior.Execute(BehaviorContext context) { return _activity.Execute(context, Behavior.Empty()); diff --git a/src/Automatonymous/Behaviors/WidenBehavior.cs b/src/Automatonymous/Behaviors/WidenBehavior.cs index d0b04c9..8b3a130 100644 --- a/src/Automatonymous/Behaviors/WidenBehavior.cs +++ b/src/Automatonymous/Behaviors/WidenBehavior.cs @@ -13,6 +13,7 @@ namespace Automatonymous.Behaviors { using System.Threading.Tasks; + using GreenPipes; public class WidenBehavior : @@ -34,6 +35,11 @@ void Visitable.Accept(StateMachineVisitor visitor) visitor.Visit(this); } + public void Probe(ProbeContext context) + { + _next.Probe(context); + } + Task Behavior.Execute(BehaviorContext context) { BehaviorContext nextContext = context.GetProxy(_event, _data); diff --git a/src/Automatonymous/Events/TriggerEvent.cs b/src/Automatonymous/Events/TriggerEvent.cs index 9643769..58dcb5a 100644 --- a/src/Automatonymous/Events/TriggerEvent.cs +++ b/src/Automatonymous/Events/TriggerEvent.cs @@ -1,4 +1,4 @@ -// Copyright 2011-2014 Chris Patterson, Dru Sellers +// Copyright 2011-2016 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 @@ -13,6 +13,7 @@ namespace Automatonymous.Events { using System; + using GreenPipes; public class TriggerEvent : @@ -29,7 +30,15 @@ public TriggerEvent(string name) public virtual void Accept(StateMachineVisitor visitor) { - visitor.Visit(this, x => { }); + visitor.Visit(this, x => + { + }); + } + + public void Probe(ProbeContext context) + { + var scope = context.CreateScope("event"); + scope.Add("name", _name); } public int CompareTo(Event other) diff --git a/src/Automatonymous/StateAccessor.cs b/src/Automatonymous/StateAccessor.cs index 8418aef..c3dc632 100644 --- a/src/Automatonymous/StateAccessor.cs +++ b/src/Automatonymous/StateAccessor.cs @@ -1,21 +1,23 @@ -// Copyright 2007-2014 Chris Patterson, Dru Sellers, Travis Smith, et. al. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// Copyright 2011-2016 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 +// 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.Threading.Tasks; + using GreenPipes; - public interface StateAccessor + public interface StateAccessor : + IProbeSite { Task> Get(InstanceContext context); diff --git a/src/Automatonymous/States/StateMachineState.cs b/src/Automatonymous/States/StateMachineState.cs index f7715c9..e1d8277 100644 --- a/src/Automatonymous/States/StateMachineState.cs +++ b/src/Automatonymous/States/StateMachineState.cs @@ -19,6 +19,7 @@ namespace Automatonymous.States using Behaviors; using Contexts; using Events; + using GreenPipes; public class StateMachineState : @@ -89,6 +90,27 @@ public void Accept(StateMachineVisitor visitor) }); } + public void Probe(ProbeContext context) + { + var scope = context.CreateScope("state"); + scope.Add("name", _name); + + foreach (var behavior in _behaviors) + { + var behaviorScope = scope.CreateScope(behavior.Key.Name); + behavior.Value.Behavior.Probe(behaviorScope); + } + + if (_ignoredEvents.Any()) + { + var ignoredScope = scope.CreateScope("ignored"); + foreach (var ignoredEvent in _ignoredEvents) + { + ignoredEvent.Key.Probe(ignoredScope); + } + } + } + async Task State.Raise(EventContext context) { ActivityBehaviorBuilder activities; diff --git a/src/Automatonymous/Visitable.cs b/src/Automatonymous/Visitable.cs index 35e3d57..e2cc0e4 100644 --- a/src/Automatonymous/Visitable.cs +++ b/src/Automatonymous/Visitable.cs @@ -12,10 +12,14 @@ // specific language governing permissions and limitations under the License. namespace Automatonymous { + using GreenPipes; + + /// /// Used to visit the state machine structure, so it can be displayed, etc. /// - public interface Visitable + public interface Visitable : + IProbeSite { /// /// A visitable site can accept the visitor and pass control to internal elements