public void Add(SearchScope scope, SearchBy searchBy, Operator op, string searchText) { var searchPredicate = HookExtensions.FormatSearchClause <T>(searchBy, op, searchText); switch (scope) { case SearchScope.ExecutingAssembly: _hook.AddRange(Assembly.GetExecutingAssembly().GetHooks <T>(searchPredicate)); break; case SearchScope.EntryAssembly: _hook.AddRange(Assembly.GetEntryAssembly().GetHooks <T>(searchPredicate)); break; case SearchScope.CallingAssembly: _hook.AddRange(Assembly.GetCallingAssembly().GetHooks <T>(searchPredicate)); break; case SearchScope.CurrentDirectory: List <Assembly> assemblies = DirectoryExtensions.GetAssemblies(Environment.CurrentDirectory, "*.dll"); assemblies.AddRange(DirectoryExtensions.GetAssemblies(Environment.CurrentDirectory, "*.exe")); foreach (var item in assemblies) { _hook.AddRange(item.GetHooks(searchPredicate)); } break; default: throw new InvalidOperationException("Invalid SearchScope: " + scope); } }
public T[] Get(Func <T, bool> predicate) { List <T> hookForThisInstance = HookExtensions.GetHooksForCurrentMethod(this); List <T> hookObjects = new List <T>(); foreach (var hook in hookForThisInstance) { if (predicate.Invoke(hook)) { hookObjects.Add(hook); } } return(hookObjects.ToArray()); }
public int InvokeAllAsParallel(params object[] inputParams) { List <T> hookForThisInstance = HookExtensions.GetHooksForCurrentMethod(this); int count = 0; Parallel.ForEach(hookForThisInstance, hook => { hook.OnInvoke(inputParams); count++; }); return(count); }
public int InvokeAll(params object[] inputParams) { List <T> hookForThisInstance = HookExtensions.GetHooksForCurrentMethod(this); int count = 0; foreach (var hook in hookForThisInstance) { hook.OnInvoke(inputParams); count++; } return(count); }
public int InvokeWhenAsParallel(Func <bool> predicate, params object[] inputParams) { List <T> hookForThisInstance = HookExtensions.GetHooksForCurrentMethod(this); int count = 0; // If predicate evaluates to 'true' execute the OnInvoke method if (predicate.Invoke()) { Parallel.ForEach(hookForThisInstance, hook => { hook.OnInvoke(inputParams); count++; }); } return(count); }
public int InvokeWhere(Func <T, bool> predicate, params object[] inputParams) { List <T> hookForThisInstance = HookExtensions.GetHooksForCurrentMethod(this); int count = 0; foreach (var hook in hookForThisInstance) { // If predicate evaluates to 'true' execute the OnInvoke method if (predicate.Invoke(hook)) { hook.OnInvoke(inputParams); count++; } } return(count); }
public int InvokeWhereAsParallel(Func <T, bool> predicate, params object[] inputParams) { List <Lazy <T> > hookForThisInstance = HookExtensions.GetHooksForCurrentMethodLazy(this); int count = 0; Parallel.ForEach(hookForThisInstance, hook => { // If predicate evaluates to 'true' execute the OnInvoke method if (predicate.Invoke(hook.Value)) { hook.Value.OnInvoke(inputParams); count++; } }); return(count); }
public T[] Get(Type type) { if (type.GetInterface("IHook") == null) { throw new InvalidCastException("Only data types inheriting from IHook are permitted in this repository"); } List <T> hookForThisInstance = HookExtensions.GetHooksForCurrentMethod(this); List <T> hookObjects = new List <T>(); foreach (var hook in hookForThisInstance) { if (hook.GetType() == type) { hookObjects.Add(hook); } } return(hookObjects.ToArray()); }