Guest User

Untitled

a guest
Jan 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. public class AddBehaviorChainNotificationPolicy : INotificationPolicy
  2. {
  3. private readonly BehaviorGraph _graph;
  4.  
  5. public AddBehaviorChainNotificationPolicy(BehaviorGraph graph)
  6. {
  7. _graph = graph;
  8. }
  9.  
  10. public bool Applies()
  11. {
  12. return !nonDiagnosticsChains().Any();
  13. }
  14.  
  15. public INotificationModel Build()
  16. {
  17. return new AddBehaviorChainNotification();
  18. }
  19.  
  20. private IEnumerable<BehaviorChain> nonDiagnosticsChains()
  21. {
  22. return _graph
  23. .Behaviors
  24. .Where(chain => !isDiagnosticsChain(chain));
  25. }
  26.  
  27. private bool isDiagnosticsChain(BehaviorChain chain)
  28. {
  29. var assembly = GetType().Assembly;
  30. var call = chain.FirstCall();
  31.  
  32. // First we'll try to grab the action call
  33. if (call == null)
  34. {
  35. // No action calls. Check for partials, too
  36. var output = chain.InputType();
  37. if (output == null)
  38. {
  39. // No action calls and no partials? You need some suggeestions
  40. return false;
  41. }
  42.  
  43. return output.Assembly.Equals(assembly) || output.Assembly.Equals(typeof(ActionCall).Assembly);
  44. }
  45.  
  46. // Make sure the ActionCall is coming from a custom assembly
  47. return call.IsDiagnosticsCall() || call.IsInternalFubuAction() || call.HandlerType.Assembly.Equals(assembly);
  48. }
  49. }
Add Comment
Please, Sign In to add comment