Пример #1
0
 public void Add(IAssemblyShim pluginAssembly, IEnumerable <Type> hostTypes = null)
 {
     this.pluginCache.Add(new CachedPluginAssembly
     {
         AssemblyShim = pluginAssembly,
         HostTypes    = hostTypes
     });
 }
Пример #2
0
 public IEnumerable <Type> SelectPluginTypes(Type type, IAssemblyShim assemblyShim)
 {
     return(assemblyShim.Types
            .Where(t => t.CustomAttributes
                   .Any(c => c.AttributeType.Name == typeof(Prise.Plugin.PluginAttribute).Name &&
                        (c.NamedArguments.First(a => a.MemberName == "PluginType").TypedValue.Value as Type).Name == type.Name))
            .OrderBy(t => t.Name)
            .AsEnumerable());
 }
        public IPluginActivationContext ProvideActivationContext(Type remoteType, IAssemblyShim pluginAssembly)
        {
            var bootstrapper = pluginAssembly
                               .Types
                               .FirstOrDefault(t => t.CustomAttributes
                                               .Any(c => c.AttributeType.Name == typeof(Prise.Plugin.PluginBootstrapperAttribute).Name &&
                                                    (c.NamedArguments.First(a => a.MemberName == "PluginType").TypedValue.Value as Type).Name == remoteType.Name));

            // TODO End support for PluginFactories by next major release
            var factoryMethod = remoteType.GetMethods()
                                .FirstOrDefault(m => m.CustomAttributes
                                                .Any(c => c.AttributeType.Name == typeof(Prise.Plugin.PluginFactoryAttribute).Name));

            var pluginServices = new List <PluginService>();
            var typeInfo       = remoteType as System.Reflection.TypeInfo;

            var pluginServiceFields = GetFieldsOfCustomAttribute(typeInfo, typeof(Prise.Plugin.PluginServiceAttribute).Name);

            if (pluginServiceFields.Any())
            {
                pluginServices = pluginServiceFields.Select(f => ParsePluginService(remoteType, f)).ToList();
            }

            var bootstrapperServices = new List <BootstrapperService>();

            if (bootstrapper != null)
            {
                var bootstrapperServiceFields = GetFieldsOfCustomAttribute(bootstrapper as System.Reflection.TypeInfo, typeof(Prise.Plugin.BootstrapperServiceAttribute).Name);
                if (bootstrapperServiceFields.Any())
                {
                    bootstrapperServices = bootstrapperServiceFields.Select(f => ParseBootstrapperService(bootstrapper, f)).ToList();
                }
            }

            var pluginActivatedMethod = GetPluginActivatedMethod(remoteType);

            return(new DefaultPluginActivationContext
            {
                PluginType = remoteType,
                PluginAssembly = pluginAssembly,
                PluginBootstrapperType = bootstrapper,
                PluginFactoryMethod = factoryMethod,
                PluginActivatedMethod = pluginActivatedMethod,
                PluginServices = pluginServices,
                BootstrapperServices = bootstrapperServices,
            });
        }
Пример #4
0
 public IEnumerable <Type> SelectPluginTypes <T>(IAssemblyShim assemblyShim)
 {
     return(this.SelectPluginTypes(typeof(T), assemblyShim));
 }