private IEnumerable<Type> GetPlugins(PluginGroupLoaderTypeVisitor visitor , Type[] priorityPlugins)
        {
            Type type = visitor.GetPluginType();

            IList<Type> types = AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(a =>
            {
                Type pluginType = type;

                try
                {
                    return a.GetTypes().Where(t => pluginType.IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract);
                }
                catch (Exception ex)
                {
                    if (ex is ReflectionTypeLoadException)
                    {
                        ReflectionTypeLoadException rtl = ex as ReflectionTypeLoadException;

                        foreach (Exception rtlEx in rtl.LoaderExceptions)
                        {
                            new CSException(CSExceptionType.UnknownError,
                                string.Format("Failed to load IApplicationPlugin from {0}, because of:", a.FullName), rtlEx).Log();
                        }
                    }
                    else
                    {
                        new CSException(CSExceptionType.UnknownError,
                            string.Format("Failed to load IApplicationPlugin implementation from {0}", a.FullName), ex).Log();
                    }
                }

                return new Type[0];
            }).ToList();

            // Ensure priority plugins are loaded first, if they are not application plugins then they just get added
            if (priorityPlugins != null)
            {
                for (int i = priorityPlugins.Length - 1; i >= 0; i--)
                {
                    type = priorityPlugins[i];

                    if (types.Contains(type))
                    {
                        types.Remove(type);
                    }

                    types.Insert(0, type);
                }
            }

            return types;
        }
Пример #2
0
        private IEnumerable <Type> GetPlugins(PluginGroupLoaderTypeVisitor visitor, Type[] priorityPlugins)
        {
            Type type = visitor.GetPluginType();

            IList <Type> types = AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(a =>
            {
                Type pluginType = type;

                try
                {
                    return(a.GetTypes().Where(t => pluginType.IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract));
                }
                catch (Exception ex)
                {
                    if (ex is ReflectionTypeLoadException)
                    {
                        ReflectionTypeLoadException rtl = ex as ReflectionTypeLoadException;

                        foreach (Exception rtlEx in rtl.LoaderExceptions)
                        {
                            new CSException(CSExceptionType.UnknownError,
                                            string.Format("Failed to load IApplicationPlugin from {0}, because of:", a.FullName), rtlEx).Log();
                        }
                    }
                    else
                    {
                        new CSException(CSExceptionType.UnknownError,
                                        string.Format("Failed to load IApplicationPlugin implementation from {0}", a.FullName), ex).Log();
                    }
                }

                return(new Type[0]);
            }).ToList();

            // Ensure priority plugins are loaded first, if they are not application plugins then they just get added
            if (priorityPlugins != null)
            {
                for (int i = priorityPlugins.Length - 1; i >= 0; i--)
                {
                    type = priorityPlugins[i];

                    if (types.Contains(type))
                    {
                        types.Remove(type);
                    }

                    types.Insert(0, type);
                }
            }

            return(types);
        }
 public void Initialize(PluginGroupLoaderTypeVisitor visitor, Type[] priorityPlugins = null)
 {
     _plugins = GetPlugins(visitor, priorityPlugins);
 }
Пример #4
0
 public void Initialize(PluginGroupLoaderTypeVisitor visitor, Type[] priorityPlugins = null)
 {
     _plugins = GetPlugins(visitor, priorityPlugins);
 }