Ejemplo n.º 1
0
        public async Task <IActionResult> Enable(string pluginName)
        {
            if (String.IsNullOrEmpty(pluginName))
            {
                return(NotFound());
            }

            var pluginAssemblies = await this.assemblyScanner.Scan();

            var pluginToEnable = pluginAssemblies.FirstOrDefault(p => Path.GetFileNameWithoutExtension(p.AssemblyName) == pluginName);

            if (pluginToEnable == null)
            {
                return(NotFound());
            }

            var assemblyPluginLoadContext = DefaultPluginLoadContext <IMVCFeature> .FromAssemblyScanResult(pluginToEnable);

            var pluginAssembly = await this.pluginAssemblyLoader.LoadAsync(assemblyPluginLoadContext);

            this.applicationPartManager.ApplicationParts.Add(new PluginAssemblyPart(pluginAssembly));
            this.pluginCache.Add(pluginAssembly);
            this.pluginChangeProvider.TriggerPluginChanged();

            return(Redirect("/"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Enable(string pluginName)
        {
            if (String.IsNullOrEmpty(pluginName))
            {
                return(NotFound());
            }

            var pluginAssemblies = await this.assemblyScanner.Scan();

            var pluginToEnable = pluginAssemblies.FirstOrDefault(p => Path.GetFileNameWithoutExtension(p.AssemblyName) == pluginName);

            if (pluginToEnable == null)
            {
                return(NotFound());
            }

            var assemblyPluginLoadContext = DefaultPluginLoadContext <IMVCFeature> .FromAssemblyScanResult(pluginToEnable);

            var pluginAssembly = await this.pluginAssemblyLoader.LoadAsync(assemblyPluginLoadContext);

            var feature = pluginAssembly.GetTypes().FirstOrDefault(t => t.GetInterfaces().Any(i => i.Name == typeof(IMVCFeature).Name));
            var featureDescriptionAttribute = feature.GetCustomAttributes(false).FirstOrDefault(c => c.GetType().Name == typeof(MVCFeatureDescriptionAttribute).Name);
            var description = featureDescriptionAttribute.GetType().GetProperty("Description").GetValue(featureDescriptionAttribute);

            this.applicationPartManager.ApplicationParts.Add(new PluginAssemblyPart(pluginAssembly));
            this.pluginCache.Add(pluginAssembly);
            this.pluginChangeProvider.TriggerPluginChanged();

            return(Redirect("/"));
        }