Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created September 15, 2011 02:04
Show Gist options
  • Save jmarnold/1218341 to your computer and use it in GitHub Desktop.
Save jmarnold/1218341 to your computer and use it in GitHub Desktop.
public class AddBehaviorChainNotificationPolicy : INotificationPolicy
{
private readonly BehaviorGraph _graph;
public AddBehaviorChainNotificationPolicy(BehaviorGraph graph)
{
_graph = graph;
}
public bool Applies()
{
return !nonDiagnosticsChains().Any();
}
public INotificationModel Build()
{
return new AddBehaviorChainNotification();
}
private IEnumerable<BehaviorChain> nonDiagnosticsChains()
{
return _graph
.Behaviors
.Where(chain => !isDiagnosticsChain(chain));
}
private bool isDiagnosticsChain(BehaviorChain chain)
{
var assembly = GetType().Assembly;
var call = chain.FirstCall();
// First we'll try to grab the action call
if (call == null)
{
// No action calls. Check for partials, too
var output = chain.InputType();
if (output == null)
{
// No action calls and no partials? You need some suggeestions
return false;
}
return output.Assembly.Equals(assembly) || output.Assembly.Equals(typeof(ActionCall).Assembly);
}
// Make sure the ActionCall is coming from a custom assembly
return call.IsDiagnosticsCall() || call.IsInternalFubuAction() || call.HandlerType.Assembly.Equals(assembly);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment