public static void LoadAttribute(List <Assembly> BusinessDll, ModulePlugin mp) { List <WinformControllerAttributeInfo> cmdControllerList = new List <WinformControllerAttributeInfo>(); for (int k = 0; k < BusinessDll.Count; k++) { //System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]); System.Reflection.Assembly assembly = BusinessDll[k]; Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { WinformControllerAttribute[] winC = ((WinformControllerAttribute[])types[i].GetCustomAttributes(typeof(WinformControllerAttribute), true)); if (winC.Length > 0) { WinformControllerAttributeInfo cmdC = new WinformControllerAttributeInfo(); cmdC.controllerName = types[i].Name; cmdC.defaultViewName = winC[0].DefaultViewName; //cmdC.winformController = (AbstractController)Activator.CreateInstance(types[i], null); cmdC.winformController = (AbstractController)FactoryModel.GetObject(types[i], mp.database, mp.container, mp.cache, mp.plugin.name, null); cmdC.MethodList = new List <WinformMethodAttributeInfo>(); cmdC.ViewList = new List <WinformViewAttributeInfo>(); MethodInfo[] property = types[i].GetMethods(); for (int n = 0; n < property.Length; n++) { WinformMethodAttribute[] WinM = (WinformMethodAttribute[])property[n].GetCustomAttributes(typeof(WinformMethodAttribute), true); if (WinM.Length > 0) { WinformMethodAttributeInfo cmdM = new WinformMethodAttributeInfo(); cmdM.methodName = property[n].Name; cmdM.methodInfo = property[n]; if (WinM[0].OpenDBKeys != null && WinM[0].OpenDBKeys.ToString().Trim() != "") { cmdM.dbkeys = WinM[0].OpenDBKeys.Split(new char[] { ',' }).ToList(); } cmdC.MethodList.Add(cmdM); } } WinformViewAttribute[] viewAttribute = (WinformViewAttribute[])types[i].GetCustomAttributes(typeof(WinformViewAttribute), true); for (int n = 0; n < viewAttribute.Length; n++) { WinformViewAttributeInfo winView = new WinformViewAttributeInfo(); winView.Name = viewAttribute[n].Name; winView.DllName = viewAttribute[n].DllName; winView.ViewTypeName = viewAttribute[n].ViewTypeName; winView.IsDefaultView = winView.Name == cmdC.defaultViewName ? true : false; //Assembly _assembly = Assembly.LoadFrom(winView.DllName); winView.ViewType = assembly.GetType(winView.ViewTypeName, false, true); cmdC.ViewList.Add(winView); } cmdControllerList.Add(cmdC); } } } mp.cache.Add(mp.plugin.name + "@" + GetCacheKey(), cmdControllerList); }
/// <summary> /// 加载插件,之后必须重启中间件 /// </summary> /// <param name="plugfile"></param> public static void AddPlugin(string pluginfile) { string filepath = AppGlobal.AppRootPath + pluginfile;//转为绝对路径 ModulePlugin mp = new ModulePlugin(); mp.appType = AppGlobal.appType; mp.LoadPlugin(filepath); PluginSysManage.AddPlugin(mp.plugin.name, mp.plugin.title, pluginfile, mp.plugin.version); }
public static Dictionary <string, ModulePlugin> PluginDic;//本地插件 /// <summary> /// 加载所有插件 /// </summary> public static void LoadAllPlugin() { PluginDic = new Dictionary <string, ModulePlugin>(); List <string> pflist = PluginSysManage.GetAllPluginFile(); for (int i = 0; i < pflist.Count; i++) { //AddPlugin(pflist[i]); string filepath = AppGlobal.AppRootPath + pflist[i];//转为绝对路径 ModulePlugin mp = new ModulePlugin(); mp.appType = AppGlobal.appType; mp.LoadPlugin(filepath); mp.LoadAttribute(filepath); PluginDic.Add(mp.plugin.name, mp); } }
/// <summary> /// 加载插件,创建AppDomain来动态加载或卸载dll /// </summary> /// <param name="plugfile"></param> public static void AddPlugin(string plugfile) { if (PluginDic == null) { PluginDic = new Dictionary <string, ModulePlugin>(); } if (DomainDic == null) { DomainDic = new Dictionary <string, AppDomain>(); } if (IsOpenDomain)//开启程序域 { //AppDomainSetup setup = new AppDomainSetup(); //setup.ApplicationName = "ApplicationLoader"; //setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; //setup.PrivateBinPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "private"); //setup.CachePath = setup.ApplicationBase; //setup.ShadowCopyFiles = "true"; //setup.ShadowCopyDirectories = setup.ApplicationBase; //AppDomain.CurrentDomain.SetShadowCopyFiles(); //AppDomain appDomain = AppDomain.CreateDomain("ApplicationLoaderDomain", null, setup); //String name = Assembly.GetExecutingAssembly().GetName().FullName; //ModulePlugin mp = (ModulePlugin)appDomain.CreateInstanceAndUnwrap(name, typeof(ModulePlugin).FullName); //mp.appType = AppGlobal.appType; //mp.LoadPlugin(plugfile); //if (PluginDic.ContainsKey(mp.plugin.name) == false) //{ // PluginDic.Add(mp.plugin.name, mp); // DomainDic.Add(mp.plugin.name, appDomain); // mp.LoadAttribute(plugfile); //} } else { ModulePlugin mp = new ModulePlugin(); mp.appType = AppGlobal.appType; mp.LoadPlugin(plugfile); if (PluginDic.ContainsKey(mp.plugin.name) == false) { PluginDic.Add(mp.plugin.name, mp); mp.LoadAttribute(plugfile); } } }
public static void LoadAttribute(List <Assembly> BusinessDll, ModulePlugin mp) { List <WcfControllerAttributeInfo> cmdControllerList = new List <WcfControllerAttributeInfo>(); for (int k = 0; k < BusinessDll.Count; k++) { //System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]); System.Reflection.Assembly assembly = BusinessDll[k]; Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { WCFControllerAttribute[] webC = ((WCFControllerAttribute[])types[i].GetCustomAttributes(typeof(WCFControllerAttribute), true)); if (webC.Length > 0) { WcfControllerAttributeInfo cmdC = new WcfControllerAttributeInfo(); cmdC.controllerName = types[i].Name; //cmdC.wcfController = (AbstractController)Activator.CreateInstance(types[i], null); //cmdC.wcfController = (AbstractController)FactoryModel.GetObject(types[i], mp.database, mp.container, mp.cache, mp.plugin.name, null); cmdC.wcfControllerType = types[i]; cmdC.MethodList = new List <WcfMethodAttributeInfo>(); MethodInfo[] property = types[i].GetMethods(); for (int n = 0; n < property.Length; n++) { WCFMethodAttribute[] WcfM = (WCFMethodAttribute[])property[n].GetCustomAttributes(typeof(WCFMethodAttribute), true); if (WcfM.Length > 0) { WcfMethodAttributeInfo cmdM = new WcfMethodAttributeInfo(); cmdM.methodName = property[n].Name; cmdM.methodInfo = property[n]; if (WcfM[0].OpenDBKeys != null && WcfM[0].OpenDBKeys.ToString().Trim() != "") { cmdM.dbkeys = WcfM[0].OpenDBKeys.Split(new char[] { ',' }).ToList(); } cmdM.IsAuthentication = WcfM[0].IsAuthentication; cmdC.MethodList.Add(cmdM); } } cmdControllerList.Add(cmdC); } } } mp.cache.Add(mp.plugin.name + "@" + GetCacheKey(), cmdControllerList); }
public static WebServicesAttributeInfo GetPluginWebServicesAttributeInfo(string name, out ModulePlugin mp) { foreach (KeyValuePair <string, ModulePlugin> val in PluginDic) { List <WebServicesAttributeInfo> list = (List <WebServicesAttributeInfo>)WebServicesManager.GetAttributeInfo(val.Value.cache, val.Value.plugin.name); if (list.FindIndex(x => x.ServiceName == name) > -1) { mp = val.Value; return(list.Find(x => x.ServiceName == name)); } } mp = null; return(null); }
public static WcfControllerAttributeInfo GetPluginWcfControllerAttributeInfo(string pluginname, string name, out ModulePlugin mp) { mp = PluginDic[pluginname]; if (mp != null) { List <WcfControllerAttributeInfo> list = (List <WcfControllerAttributeInfo>)WcfControllerManager.GetAttributeInfo(mp.cache, mp.plugin.name); if (list.FindIndex(x => x.controllerName == name) > -1) { return(list.Find(x => x.controllerName == name)); } } return(null); //foreach (KeyValuePair<string, ModulePlugin> val in PluginDic) //{ // List<WcfControllerAttributeInfo> list = (List<WcfControllerAttributeInfo>)WcfControllerManager.GetAttributeInfo(val.Value.cache, val.Value.plugin.name); // if (list.FindIndex(x => x.controllerName == name) > -1) // { // mp = val.Value; // return list.Find(x => x.controllerName == name); // } //} //mp = null; //return null; }
public static WebControllerAttributeInfo GetPluginWebControllerAttributeInfo(string pluginname, string name, out ModulePlugin mp) { mp = PluginDic[pluginname]; if (mp != null) { List <WebControllerAttributeInfo> list = (List <WebControllerAttributeInfo>)WebControllerManager.GetAttributeInfo(mp.cache, mp.plugin.name); if (list.FindIndex(x => x.controllerName == name) > -1) { return(list.Find(x => x.controllerName == name)); } } return(null); }
/// <summary> /// Initialize /// </summary> public void Init() { // System plugins ( basic features - loops, if etc ) _sysMap["Break"] = new BreakPlugin(); _sysMap["Continue"] = new ContinuePlugin(); _sysMap["For"] = new ForPlugin(); _sysMap["Lambda"] = new LambdaPlugin(); _sysMap["FuncDeclare"] = new FunctionDeclarePlugin(); _sysMap["If"] = new IfPlugin(); _sysMap["New"] = new NewPlugin(); _sysMap["Return"] = new ReturnPlugin(); _sysMap["Throw"] = new ThrowPlugin(); _sysMap["TryCatch"] = new TryCatchPlugin(); _sysMap["TypeOf"] = new TypeOfPlugin(); _sysMap["While"] = new WhilePlugin(); _sysMap["Var"] = new VarPlugin(); _sysMap["Plugin"] = new PluginPlugin(); // Custom plugins - extended functionality. _extMap["AnyOf"] = new AnyOfPlugin(); _extMap["Aggregate"] = new AggregatePlugin(); _extMap["Alias"] = new AliasPlugin(); //_extMap["AndOr"] = new AndOrPlugin(); //_extMap["Bool"] = new BoolPlugin(); //_extMap["Compare"] = new ComparePlugin(); _extMap["ConstCaps"] = new ConstCapsPlugin(); //_extMap["Date"] = new DatePlugin(); _extMap["DateNumber"] = new DateNumberPlugin(); //_extMap["DateTimeCombiner"] = new DateTimeCombinerPlugin(); //_extMap["Day"] = new DayPlugin(); //_extMap["Def"] = new DefPlugin(); _extMap["Enable"] = new EnablePlugin(); _extMap["Email"] = new EmailPlugin(); _extMap["Fail"] = new FailPlugin(); _extMap["FileExt"] = new FileExtPlugin(); _extMap["FluentFunc"] = new FluentFuncPlugin(); _extMap["FluentMember"] = new FluentMemberPlugin(); _extMap["FuncWildCard"] = new FuncWildCardPlugin(); _extMap["HashComment"] = new HashCommentPlugin(); _extMap["Holiday"] = new HolidayPlugin(); _extMap["Linq"] = new LinqPlugin(); _extMap["Log"] = new LogPlugin(); _extMap["MachineInfo"] = new MachineInfoPlugin(); _extMap["Marker"] = new MarkerPlugin(); _extMap["MarkerLex"] = new MarkerLexPlugin(); //_extMap["Money"] = new MoneyPlugin(); _extMap["Module"] = new ModulePlugin(); _extMap["NamedIndex"] = new NamedIndexPlugin(); _extMap["Percent"] = new PercentPlugin(); _extMap["PhoneNumber"] = new PhoneNumberPlugin(); _extMap["Preprocessor"] = new PreprocessorPlugin(); _extMap["Plugin"] = new PluginPlugin(); _extMap["Print"] = new PrintPlugin(); _extMap["PrintExpression"] = new PrintExpressionPlugin(); _extMap["Records"] = new RecordsPlugin(); _extMap["Repeat"] = new RepeatPlugin(); _extMap["Round"] = new RoundPlugin(); _extMap["Run"] = new RunPlugin(); //_extMap["Set"] = new SetPlugin(); _extMap["Sort"] = new SortPlugin(); //_extMap["Step"] = new StepPlugin(); //_extMap["StringLiteral"] = new StringLiteralPlugin(); _extMap["Suffix"] = new SuffixPlugin(); _extMap["Swap"] = new SwapPlugin(); _extMap["Time"] = new TimePlugin(); _extMap["TypeOperations"] = new TypeOperationsPlugin(); _extMap["Units"] = new UnitsPlugin(); _extMap["Uri"] = new UriPlugin(); _extMap["VariablePath"] = new VariablePathPlugin(); _extMap["Version"] = new VersionPlugin(); _extMap["Words"] = new WordsPlugin(); _extMap["WordsInterpret"] = new WordsInterpretPlugin(); //SerializePluginMetadata(); }
public static WinformControllerAttributeInfo GetPluginWinformControllerAttributeInfo(string pluginname, string name, out ModulePlugin mp) { if (PluginDic.ContainsKey(pluginname) == false) { throw new Exception("[" + pluginname + "]插件模块并没有在pluginsys.xml配置文件中配置好!"); } mp = PluginDic[pluginname]; if (mp != null) { List <WinformControllerAttributeInfo> list = (List <WinformControllerAttributeInfo>)WinformControllerManager.GetAttributeInfo(mp.cache, mp.plugin.name); if (list != null && list.FindIndex(x => x.controllerName == name) > -1) { return(list.Find(x => x.controllerName == name)); } } return(null); //foreach (KeyValuePair<string, ModulePlugin> val in PluginDic) //{ // List<WinformControllerAttributeInfo> list = (List<WinformControllerAttributeInfo>)WinformControllerManager.GetAttributeInfo(val.Value.cache, val.Value.plugin.name); // if (list.FindIndex(x => x.controllerName == name) > -1) // { // mp = val.Value; // return list.Find(x => x.controllerName == name); // } //} //mp = null; //return null; }
public static void AddPlugin(string plugfile) { if (PluginDic == null) { PluginDic = new Dictionary <string, ModulePlugin>(); } ModulePlugin mp = new ModulePlugin(); mp.LoadPlugin(plugfile); if (PluginDic.ContainsKey(mp.plugin.name) == false) { PluginDic.Add(mp.plugin.name, mp); List <string> dllList = new List <string>(); switch (AppGlobal.appType) { case AppType.Web: foreach (businessinfoDll dll in mp.plugin.businessinfoDllList) { dllList.Add(AppGlobal.AppRootPath + "bin\\" + dll.name); } if (dllList.Count > 0) { EntityManager.LoadAttribute(dllList, mp.cache, mp.plugin.name); WebControllerManager.LoadAttribute(dllList, mp); WebServicesManager.LoadAttribute(dllList, mp.cache, mp.plugin.name); } break; case AppType.Winform: foreach (businessinfoDll dll in mp.plugin.businessinfoDllList) { dllList.Add(AppGlobal.AppRootPath + dll.name); } if (dllList.Count > 0) { EntityManager.LoadAttribute(dllList, mp.cache, mp.plugin.name); WinformControllerManager.LoadAttribute(dllList, mp); } break; case AppType.WCF: foreach (businessinfoDll dll in mp.plugin.businessinfoDllList) { dllList.Add(AppGlobal.AppRootPath + dll.name); } if (dllList.Count > 0) { EntityManager.LoadAttribute(dllList, mp.cache, mp.plugin.name); WcfControllerManager.LoadAttribute(dllList, mp); } break; case AppType.WCFClient: foreach (businessinfoDll dll in mp.plugin.businessinfoDllList) { dllList.Add(AppGlobal.AppRootPath + dll.name); } if (dllList.Count > 0) { WinformControllerManager.LoadAttribute(dllList, mp); } break; } } }