コード例 #1
0
        public static void InvokeBeforePlugins(object sender, PluginEventArgs e)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            Control ctrl = sender as Control;

            if (ctrl == null)
            {
                throw new ApplicationExceptionFormat("传的sender {0}不是服务器控件", new object[] { sender.ToString() });
            }
            Page      absolutePage = ctrl.GetAbsolutePage();
            IBasePage page2        = absolutePage as IBasePage;

            if (page2 == null)
            {
                throw new ApplicationExceptionFormat("页面不是继承自BasePage", new object[0]);
            }
            IPagePlugin pluginInstance = page2.PluginInstance;

            if (pluginInstance != null)
            {
                CommandHandler commandPluginHandler = GetCommandPluginHandler(ctrl);
                if (commandPluginHandler != null)
                {
                    commandPluginHandler.ExecuteBefore(pluginInstance, ctrl, e);
                }
            }
            EventCallHelper.InvokeBefore(absolutePage, ctrl, new object[] { e.entityModel, e.RedirectURL, e.CurrentUserID });
        }
コード例 #2
0
        private static void LoadPluginHandlers()
        {
            string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Substring(8));

            if (!directoryName.Contains(@":\"))
            {
                directoryName = "/" + directoryName;
            }
            List <string> list = (from p in Directory.GetFiles(directoryName)
                                  where (((Path.GetFileName(p).StartsWith(PluginAssemblyPrefix) && !Path.GetFileName(p).StartsWith(PluginAssemblyNotPrefix)) && (Path.GetExtension(p).ToLower() == ".dll")) || (Path.GetFileName(p) == "King.Framework.Web.dll")) || (Path.GetFileName(p) == "King.Framework.PluginImpl.dll")
                                  select p).ToList <string>();

            foreach (string str2 in list)
            {
                Assembly assembly = Assembly.LoadFrom(str2);
                if (assembly != null)
                {
                    List <Type> list2 = new List <Type>();
                    try
                    {
                        list2 = assembly.GetTypes().ToList <Type>();
                    }
                    catch (ReflectionTypeLoadException exception)
                    {
                        StringBuilder builder = new StringBuilder();
                        builder.AppendFormat("加载程序集[{0}]的类型时出错\r\n", assembly.FullName);
                        builder.AppendLine(exception.Message);
                        foreach (Exception exception2 in exception.LoaderExceptions)
                        {
                            builder.AppendLine(exception2.Message);
                            if (exception2.InnerException != null)
                            {
                                builder.AppendLine(exception2.InnerException.Message);
                            }
                        }
                        Trace.WriteLine(builder.ToString());
                        throw new Exception(builder.ToString());
                    }
                    foreach (Type type in list2)
                    {
                        FindPagePlugin(type);
                        EventCallHelper.FindPluginInType(type);
                        FindViewQueryPlugin(type);
                    }
                }
            }
        }