public void Remove(ReactionInfoCollection reactions) { if (reactions != null) { Remove(reactions.ToArray()); } }
/// <summary> /// Locates the reaction infos for performing the specified action with the specified type by looking at the interfaces of the provided type. /// </summary> /// <param name="action">The action that is to be performed by the reaction.</param> /// <param name="type">The type that is involved in the action.</param> /// <returns>The reaction info for the specified scenario.</returns> public ReactionInfo[] LocateFromInterfaces(string action, Type type) { ReactionInfoCollection reactionInfos = new ReactionInfoCollection(); // Logging commented out to boost performance //using (LogGroup logGroup = LogGroup.StartDebug("Locating a reaction by checking the interfaces of the provided type.")) //{ Type[] interfaceTypes = type.GetInterfaces(); // Loop backwards through the interface types for (int i = interfaceTypes.Length - 1; i >= 0; i--) { Type interfaceType = interfaceTypes[i]; //using (LogGroup logGroup2 = LogGroup.StartDebug("Checking interface: " + interfaceType.FullName)) //{ string key = Reactions.GetReactionsKey(action, interfaceType.Name); //LogWriter.Debug("Key: " + key); if (Reactions.ReactionExists(key)) { reactionInfos.AddRange(Reactions[key]); //LogWriter.Debug("Reactions found: " + reactionInfos.Count.ToString()); } //else //LogWriter.Debug("No reaction found for that key."); //} } //} return(reactionInfos.ToArray()); }
public void AddRange(ReactionInfoCollection reactions) { if (reactions != null) { foreach (ReactionInfo reaction in reactions.ToArray()) { Add(reaction); } } }
/// <summary> /// Locates the reaction info for performing the specified action with the specified type by looking at the base types of the provided type. /// </summary> /// <param name="action">The action that is to be performed by the reaction.</param> /// <param name="type">The type that is involved in the action.</param> /// <returns>The reaction info for the specified scenario.</returns> public ReactionInfo[] LocateFromBaseTypes(string action, Type type) { ReactionInfoCollection reactionInfos = new ReactionInfoCollection(); // Logging commented out to boost performance //using (LogGroup logGroup = LogGroup.StartDebug("Locating reaction via the base types of the '" + (type != null ? type.FullName : "[null]") + "' type.")) //{ if (action == null) { throw new ArgumentNullException("action"); } if (action == String.Empty) { throw new ArgumentException("An action must be specified."); } if (type == null) { throw new ArgumentNullException("type"); } TypeNavigator navigator = new TypeNavigator(type); while (navigator.HasNext) { Type nextType = navigator.Next(); if (nextType != null) { //using (LogGroup logGroup2 = LogGroup.StartDebug("Checking base type: " + nextType.FullName)) //{ string key = Reactions.GetReactionsKey(action, nextType.Name); //LogWriter.Debug("Key: " + key); // If a reaction exists for the base type then use it if (Reactions.ReactionExists(key)) { if (Reactions.ContainsKey(key)) { reactionInfos.AddRange(Reactions[key]); } //LogWriter.Debug("Reactions found: " + reactionInfos.Count.ToString()); } //} } } //} return(reactionInfos.ToArray()); }
/// <summary> /// Locates the reaction infos for performing the specified action with the specified type by looking at the base types and interfaces of the provided type. /// </summary> /// <param name="action">The action that is to be performed by the reaction.</param> /// <param name="type">The type that is involved in the action.</param> /// <returns>The reaction info for the specified scenario.</returns> public ReactionInfo[] LocateFromHeirarchy(string action, Type type) { ReactionInfoCollection reactionInfos = new ReactionInfoCollection(); // Logging commented out to boost performance //using (LogGroup logGroup = LogGroup.StartDebug("Locating a reaction by navigating the hierarchy of the provided type.")) //{ reactionInfos.AddRange(LocateFromInterfaces(action, type)); reactionInfos.AddRange(LocateFromBaseTypes(action, type)); //} return(reactionInfos.ToArray()); }
/// <summary> /// Finds all the strategies in the available assemblies. /// </summary> /// <param name="includeTestReactions"></param> /// <returns>An array of info about the strategies found.</returns> public ReactionInfo[] FindReactions(bool includeTestReactions) { ReactionInfoCollection strategies = new ReactionInfoCollection(); //using (LogGroup logGroup = LogGroup.Start("Finding strategies by scanning the attributes of the available type.", NLog.LogLevel.Debug)) //{ foreach (string assemblyPath in AssemblyPaths) { Assembly assembly = Assembly.LoadFrom(assemblyPath); if (ContainsReactions(assembly, includeTestReactions)) { foreach (Type type in assembly.GetTypes()) { if (IsReaction(type)) { //LogWriter.Debug("Found reaction type: " + type.ToString()); ReactionInfo reactionInfo = new ReactionInfo(type); if (reactionInfo.TypeName != null && reactionInfo.TypeName != String.Empty && reactionInfo.Action != null && reactionInfo.Action != String.Empty) { //LogWriter.Debug("Found match."); //LogWriter.Debug("Type name: " + reactionInfo.TypeName); //LogWriter.Debug("Action: " + reactionInfo.Action); strategies.Add(reactionInfo); } } } } } //} return(strategies.ToArray()); }