Skip to content

Commit

Permalink
Added probe support for diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
phatboyg committed Sep 15, 2016
1 parent 93f54de commit a4a0beb
Show file tree
Hide file tree
Showing 33 changed files with 293 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/Automatonymous.Tests/AsyncActivity_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Automatonymous.Tests
{
using System;
using System.Threading.Tasks;
using GreenPipes;
using NUnit.Framework;


Expand Down Expand Up @@ -45,6 +46,10 @@ void Visitable.Accept(StateMachineVisitor visitor)
{
visitor.Visit(this);
}

public void Probe(ProbeContext context)
{
}
}


Expand Down
5 changes: 5 additions & 0 deletions src/Automatonymous.Tests/Dependency_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Automatonymous.Tests
using System;
using System.Threading.Tasks;
using Activities;
using GreenPipes;
using NUnit.Framework;


Expand Down Expand Up @@ -76,6 +77,10 @@ public void Accept(StateMachineVisitor visitor)
{
visitor.Visit(this);
}

public void Probe(ProbeContext context)
{
}
}


Expand Down
5 changes: 5 additions & 0 deletions src/Automatonymous.Tests/Request_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Request_Specs
using System.Reflection;
using System.Threading.Tasks;
using Binders;
using GreenPipes;
using NUnit.Framework;


Expand Down Expand Up @@ -363,6 +364,10 @@ public Task Faulted<TException>(BehaviorExceptionContext<TInstance, TData, TExce
{
return next.Faulted(context);
}

public void Probe(ProbeContext context)
{
}
}


Expand Down
6 changes: 6 additions & 0 deletions src/Automatonymous/Accessors/DefaultInstanceStateAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Automatonymous.Accessors
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using GreenPipes;


/// <summary>
Expand Down Expand Up @@ -82,5 +83,10 @@ StateAccessor<TInstance> CreateDefaultAccessor()

return new InitialIfNullStateAccessor<TInstance>(_initialState, new RawStateAccessor<TInstance>(_machine, expression, _observer));
}

public void Probe(ProbeContext context)
{
_accessor.Value.Probe(context);
}
}
}
6 changes: 6 additions & 0 deletions src/Automatonymous/Accessors/InitialIfNullStateAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Automatonymous.Accessors
using Activities;
using Behaviors;
using Contexts;
using GreenPipes;


public class InitialIfNullStateAccessor<TInstance> :
Expand Down Expand Up @@ -51,5 +52,10 @@ Task StateAccessor<TInstance>.Set(InstanceContext<TInstance> context, State<TIns
{
return _stateAccessor.Set(context, state);
}

public void Probe(ProbeContext context)
{
_stateAccessor.Probe(context);
}
}
}
6 changes: 6 additions & 0 deletions src/Automatonymous/Accessors/IntStateAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,5 +75,10 @@ static ReadWriteProperty<TInstance, int> GetCurrentStateProperty(Expression<Func

return new ReadWriteProperty<TInstance, int>(propertyInfo);
}

public void Probe(ProbeContext context)
{
context.Add("currentStateProperty", _property.Property.Name);
}
}
}
6 changes: 6 additions & 0 deletions src/Automatonymous/Accessors/RawStateAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,6 +66,11 @@ Task StateAccessor<TInstance>.Set(InstanceContext<TInstance> context, State<TIns
return _observer.StateChanged(context, state, previousState);
}

public void Probe(ProbeContext context)
{
context.Add("currentStateProperty", _property.Property.Name);
}

static ReadWriteProperty<TInstance, State> GetCurrentStateProperty(Expression<Func<TInstance, State>> currentStateExpression)
{
PropertyInfo propertyInfo = currentStateExpression.GetPropertyInfo();
Expand Down
6 changes: 6 additions & 0 deletions src/Automatonymous/Accessors/StringStateAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,5 +76,10 @@ static ReadWriteProperty<TInstance, string> GetCurrentStateProperty(Expression<F

return new ReadWriteProperty<TInstance, string>(propertyInfo);
}

public void Probe(ProbeContext context)
{
context.Add("currentStateProperty", _property.Property.Name);
}
}
}
19 changes: 16 additions & 3 deletions src/Automatonymous/Activities/ActionActivity.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +14,7 @@ namespace Automatonymous.Activities
{
using System;
using System.Threading.Tasks;
using GreenPipes;


public class ActionActivity<TInstance> :
Expand All @@ -31,6 +32,11 @@ void Visitable.Accept(StateMachineVisitor visitor)
visitor.Visit(this);
}

public void Probe(ProbeContext context)
{
context.CreateScope("action");
}

async Task Activity<TInstance>.Execute(BehaviorContext<TInstance> context, Behavior<TInstance> next)
{
_action(context);
Expand All @@ -50,7 +56,8 @@ Task Activity<TInstance>.Faulted<TException>(BehaviorExceptionContext<TInstance,
return next.Faulted(context);
}

Task Activity<TInstance>.Faulted<T, TException>(BehaviorExceptionContext<TInstance, T, TException> context, Behavior<TInstance, T> next)
Task Activity<TInstance>.Faulted<T, TException>(BehaviorExceptionContext<TInstance, T, TException> context,
Behavior<TInstance, T> next)
{
return next.Faulted(context);
}
Expand All @@ -72,14 +79,20 @@ void Visitable.Accept(StateMachineVisitor visitor)
visitor.Visit(this);
}

public void Probe(ProbeContext context)
{
context.CreateScope("action");
}

async Task Activity<TInstance, TData>.Execute(BehaviorContext<TInstance, TData> context, Behavior<TInstance, TData> next)
{
_action(context);

await next.Execute(context).ConfigureAwait(false);
}

Task Activity<TInstance, TData>.Faulted<TException>(BehaviorExceptionContext<TInstance, TData, TException> context, Behavior<TInstance, TData> next)
Task Activity<TInstance, TData>.Faulted<TException>(BehaviorExceptionContext<TInstance, TData, TException> context,
Behavior<TInstance, TData> next)
{
return next.Faulted(context);
}
Expand Down
13 changes: 12 additions & 1 deletion src/Automatonymous/Activities/AsyncActivity.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +14,7 @@ namespace Automatonymous.Activities
{
using System;
using System.Threading.Tasks;
using GreenPipes;


public class AsyncActivity<TInstance> :
Expand All @@ -31,6 +32,11 @@ void Visitable.Accept(StateMachineVisitor visitor)
visitor.Visit(this);
}

public void Probe(ProbeContext context)
{
context.CreateScope("action");
}

async Task Activity<TInstance>.Execute(BehaviorContext<TInstance> context, Behavior<TInstance> next)
{
await _asyncAction(context).ConfigureAwait(false);
Expand Down Expand Up @@ -73,6 +79,11 @@ void Visitable.Accept(StateMachineVisitor visitor)
visitor.Visit(this);
}

public void Probe(ProbeContext context)
{
context.CreateScope("action");
}

async Task Activity<TInstance, TData>.Execute(BehaviorContext<TInstance, TData> context, Behavior<TInstance, TData> next)
{
await _asyncAction(context).ConfigureAwait(false);
Expand Down
11 changes: 11 additions & 0 deletions src/Automatonymous/Activities/AsyncFactoryActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Automatonymous.Activities
using System;
using System.Threading.Tasks;
using Behaviors;
using GreenPipes;


public class AsyncFactoryActivity<TInstance, TData> :
Expand All @@ -32,6 +33,11 @@ void Visitable.Accept(StateMachineVisitor visitor)
visitor.Visit(this);
}

public void Probe(ProbeContext context)
{
context.CreateScope("activityFactory");
}

async Task Activity<TInstance, TData>.Execute(BehaviorContext<TInstance, TData> context, Behavior<TInstance, TData> next)
{
Activity<TInstance, TData> activity = await _activityFactory(context).ConfigureAwait(false);
Expand Down Expand Up @@ -62,6 +68,11 @@ void Visitable.Accept(StateMachineVisitor visitor)
visitor.Visit(this);
}

public void Probe(ProbeContext context)
{
context.CreateScope("activityFactory");
}

async Task Activity<TInstance>.Execute(BehaviorContext<TInstance> context, Behavior<TInstance> next)
{
Activity<TInstance> activity = await _activityFactory(context).ConfigureAwait(false);
Expand Down
10 changes: 9 additions & 1 deletion src/Automatonymous/Activities/CatchFaultActivity.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +14,7 @@ namespace Automatonymous.Activities
{
using System;
using System.Threading.Tasks;
using GreenPipes;


/// <summary>
Expand All @@ -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<TInstance>.Execute(BehaviorContext<TInstance> context, Behavior<TInstance> next)
{
return next.Execute(context);
Expand Down
8 changes: 8 additions & 0 deletions src/Automatonymous/Activities/CompositeEventActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Automatonymous.Activities
{
using System.Threading.Tasks;
using Accessors;
using GreenPipes;
using GreenPipes.Util;


Expand Down Expand Up @@ -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<TInstance>.Execute(BehaviorContext<TInstance> context, Behavior<TInstance> next)
{
await Execute(context).ConfigureAwait(false);
Expand Down
8 changes: 8 additions & 0 deletions src/Automatonymous/Activities/ConditionalEventActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Automatonymous.Activities
{
using System.Threading.Tasks;
using GreenPipes;


/// <summary>
Expand All @@ -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<TInstance, TData>.Execute(BehaviorContext<TInstance, TData> context, Behavior<TInstance, TData> next)
{
if (_filter(context))
Expand Down
8 changes: 7 additions & 1 deletion src/Automatonymous/Activities/DataConverterActivity.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,6 +13,7 @@
namespace Automatonymous.Activities
{
using System.Threading.Tasks;
using GreenPipes;


public class DataConverterActivity<TInstance, TData> :
Expand All @@ -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<TInstance>.Execute(BehaviorContext<TInstance> context, Behavior<TInstance> next)
{
throw new AutomatonymousException("This activity requires a body with the event, but no body was specified.");
Expand Down
Loading

0 comments on commit a4a0beb

Please sign in to comment.