예제 #1
0
        /// <summary>
        /// Finds all the strategies in the available assemblies.
        /// </summary>
        /// <param name="includeTestStrategies"></param>
        /// <returns>An array of info about the strategies found.</returns>
        public StrategyInfo[] FindStrategies(bool includeTestStrategies)
        {
            List <StrategyInfo> strategies = new List <StrategyInfo>();

            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 (ContainsStrategies(assembly, includeTestStrategies))
                    {
                        Type[] types = new Type[] {};

                        try
                        {
                            types = assembly.GetTypes();
                        }
                        catch (ReflectionTypeLoadException ex)
                        {
                            LogWriter.Error("An error occurred when scanning for busines strategies...");

                            LogWriter.Error(ex);
                        }

                        foreach (Type type in types)
                        {
                            if (IsStrategy(type))
                            {
                                using (LogGroup logGroup2 = LogGroup.StartDebug("Found strategy type: " + type.ToString()))
                                {
                                    foreach (StrategyInfo strategyInfo in StrategyInfo.ExtractInfo(type))
                                    {
                                        if (strategyInfo.TypeName != null && strategyInfo.TypeName != String.Empty &&
                                            strategyInfo.Action != null && strategyInfo.Action != String.Empty)
                                        {
                                            LogWriter.Debug("Found match.");

                                            LogWriter.Debug("Type name: " + strategyInfo.TypeName);
                                            LogWriter.Debug("Action: " + strategyInfo.Action);

                                            strategies.Add(strategyInfo);
                                        }
                                        else
                                        {
                                            LogWriter.Debug("Not all necessary properties were set. Skipping.");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(strategies.ToArray());
        }