Created
September 15, 2011 02:04
-
-
Save jmarnold/1218341 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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