Esempio n. 1
0
        /// <summary>
        /// 给运行时编译的页面加了引用程序集。
        /// </summary>
        /// <param name="pluginName"></param>
        private string CodeGeneration(string areaname)
        {
            string directoryName;

            if (!directorylist.TryGetValue(areaname.ToLower(), out directoryName))
            {
                var plugin = manage.GetPluginByAreaName(areaname.ToLower());
                if (plugin != null)
                {
                    plugin.Areas.TryGetValue(areaname.ToLower(), out directoryName);
                    if (!string.IsNullOrEmpty(directoryName))
                    {
                        directoryName = plugin.DirectoryName + directoryName;
                    }
                    else
                    {
                        directoryName = plugin.DirectoryName;
                    }
                    directorylist.TryAdd(areaname.ToLower(), directoryName);
                    RazorBuildProvider.CodeGenerationStarted += (object sender, EventArgs e) =>
                    {
                        RazorBuildProvider provider = (RazorBuildProvider)sender;
                        var pluginInfo = manage.GetPluginByAreaName(areaname);
                        if (pluginInfo != null)
                        {
                            provider.AssemblyBuilder.AddAssemblyReference(pluginInfo.PluginAssembly);
                            var refrences = pluginInfo.PluginAssembly.GetReferencedAssemblies();
                            if (refrences.Length > 0)
                            {
                                foreach (var assem in refrences)
                                {
                                    provider.AssemblyBuilder.AddAssemblyReference(Assembly.Load(assem));
                                }
                            }
                        }
                    };
                }
            }
            return(directoryName);
        }
        /// <summary>
        /// 根据控制器名称获得控制器类型。
        /// </summary>
        /// <param name="controllerName">控制器名称。</param>
        /// <returns>控制器类型。</returns>
        private Type GetControllerType(string areaName, string controllerName)
        {
            Type   type;
            string key = areaName + "/" + controllerName;

            if (pluginControllers.TryGetValue(key.ToLower(), out type))
            {
                return(type);
            }
            else
            {
                var controlName = controllerName + "Controller";
                var plugin      = manage.GetPluginByAreaName(areaName);
                if (plugin != null)
                {
                    type = plugin.Types.FirstOrDefault(p => p.Name.ToLower() == controlName.ToLower());
                    pluginControllers.TryAdd(key, type);
                    return(type);
                }
                return(null);
            }
        }