Ejemplo n.º 1
0
        /// <summary>
        /// Sets the reaction with the provided action and type.
        /// </summary>
        /// <param name="action">The action that the reaction performs.</param>
        /// <param name="type">The type of entity involved in the reaction</param>
        /// <param name="reaction">The reaction that corresponds with the specified action and type.</param>
        public void SetReaction(string action, string type, ReactionInfo reaction)
        {
            ReactionInfoCollection reactions = new ReactionInfoCollection();

            reactions.AddRange(this[GetReactionsKey(action, type)]);

            reactions.Add(reaction);

            this[GetReactionsKey(action, type)] = reactions;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the provided reaction info to the collection.
        /// </summary>
        /// <param name="reaction">The reaction info to add to the collection.</param>
        public void Add(ReactionInfo reaction)
        {
            if (reaction == null)
            {
                throw new ArgumentNullException("reaction");
            }

            string key = GetReactionsKey(reaction.Action, reaction.TypeName);

            ReactionInfoCollection list = new ReactionInfoCollection();

            if (ContainsKey(key))
            {
                list.AddRange(this[key]);
            }

            list.Add(reaction);

            this[key] = list;
        }
Ejemplo n.º 3
0
        /// <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());
        }