示例#1
0
        public void Initialize()
        {
            ISiteService           siteService            = container.Resolve <ISiteService>();
            IPluginEngine          pluginEngine           = container.Resolve <IPluginEngine>();
            PluginTemplateRegistry pluginTemplateRegistry = container.Resolve <PluginTemplateRegistry>();
            RouteCollection        routes = container.Resolve <RouteCollection>();
            PluginScriptRegistry   pluginScriptRegistry = container.Resolve <PluginScriptRegistry>();
            PluginStyleRegistry    pluginStyleRegistry  = container.Resolve <PluginStyleRegistry>();

            pluginEngine.AutoInitializePlugins = false;

            // load dynamically compiled assemblies
            pluginEngine.LoadAssembliesFromCodeFiles("~" + siteService.GetSite().PluginsPath);

            // load plugins that are in assemblies
            pluginEngine.LoadPlugins();

            // initialize plugins that are installed
            foreach (Plugin plugin in container.Resolve <IPluginService>().GetPlugins())
            {
                PluginContainer pluginContainer = pluginEngine.GetPlugin(plugin);

                if (pluginContainer != null)
                {
                    plugin.Container    = pluginContainer;
                    pluginContainer.Tag = plugin;

                    if (pluginContainer.IsLoaded)
                    {
                        pluginContainer.ApplyProperties(plugin.ExtendedProperties);
                        pluginContainer.Initialize();

                        if (plugin.Enabled)
                        {
                            pluginContainer.RegisterTemplates(pluginTemplateRegistry);
                            pluginContainer.RegisterRoutes(routes);
                            pluginContainer.RegisterScripts(pluginScriptRegistry);
                            pluginContainer.RegisterStyles(pluginStyleRegistry);
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(plugin.VirtualPath))
                    {
                        pluginContainer = new PluginContainer(new PluginAssemblyContainer(plugin.VirtualPath, (Assembly)null), new PluginFileNotFoundException(plugin.VirtualPath));
                    }

                    if (pluginContainer != null)
                    {
                        plugin.Container    = pluginContainer;
                        pluginContainer.Tag = plugin;

                        pluginEngine.AddPlugin(pluginContainer);
                    }
                }
            }

            container.RegisterInstance(pluginStyleRegistry);
            container.RegisterInstance(pluginScriptRegistry);
            container.RegisterInstance(pluginTemplateRegistry);
            container.RegisterInstance(pluginEngine);
        }