/// <summary> /// 加载插件 /// </summary> /// <param name="dllPath"></param> /// <returns></returns> public bool Load(string dllPath) { try { //加载到AqiPlugin IAqiWeb iaw = AqiManage.Plugin.Load(dllPath); if (iaw == null) { Remind.Log_Info("未能从指定插件加载IAqiWeb接口", tag); return(false); } //加载到AqiRunner AqiRunner runner = null; switch (((AqiRunner.RunMode)Enum.Parse(typeof(AqiRunner.RunMode), Setting[AqiRunner.SET_RUNMODE]))) { case AqiRunner.RunMode.SELF: runner = new AqiRunner(this, iaw.GetAllSrcUrl().Values.ToList(), iaw.Tag + "_Runner"); runner.RunEvent += new AqiRunner.RunEventHandler(this.aqiRunner_RunEvent); if (!this.aqiRunner.ContainsKey(runner.Name)) { this.aqiRunner.Add(runner.Name, runner); Remind.Log_Info("初始化Runner:" + runner.Name, tag); } else { if (this.aqiRunner[runner.Name].Union(runner)) { runner = this.aqiRunner[runner.Name]; Remind.Log_Info("合并存在Runner:" + runner.Name, tag); } } break; case AqiRunner.RunMode.JOINT: runner = this.aqiRunner[AqiRunner.DEFAULT_NAME]; runner.AddSrcUrl(iaw.GetAllSrcUrl()); break; } //自动运行 if (Setting.Get <bool>("LoadAutoRun")) { runner.RunAll(); Remind.Log_Info("插件加载自动开启Runner:" + runner.Name, tag); } } catch (Exception ex) { Remind.Log_Error("加载指定插件错误", ex, tag); return(false); } return(true); }
/// <summary> /// 加载插件 /// </summary> /// <param name="dllpath"></param> /// <returns></returns> public IAqiWeb Load(string dllpath) { Assembly ass = null; IAqiWeb iaw = null; try { //DLL ass = Assembly.LoadFrom(dllpath); if (this.allDLLs.Exists(dll => dll.FullName == ass.FullName)) { AqiManage.Remind.Log_Error("程序集已经存在:" + ass.FullName, tag); return(null); } //IAW Type[] types = ass.GetTypes(); foreach (Type type in types) { if (type.GetInterface(typeof(IAqiWeb).Name) != null) { this.allDLLs.Add(ass); iaw = Activator.CreateInstance(type) as IAqiWeb; break; } } if (iaw == null) { AqiManage.Remind.Log_Error("程序集未实现IAqiWeb接口:" + ass.FullName, tag); return(null); } if (this.allAqiWebs.ContainsKey(iaw.Tag)) { AqiManage.Remind.Log_Error("IAqiWeb接口已经存在:" + iaw.Tag, tag); this.allDLLs.Remove(ass); return(null); } this.allAqiWebs.Add(iaw.Tag, iaw); //ISU Dictionary <string, ISrcUrl> dictISU = iaw.GetAllSrcUrl(); this.allSrcUrls = this.allSrcUrls.Concat <KeyValuePair <string, ISrcUrl> >(dictISU).ToDictionary <KeyValuePair <string, ISrcUrl>, string, ISrcUrl>(x => x.Key, x => x.Value); AqiManage.Remind.Log_Info("加载数据源插件成功:" + iaw.Name, AqiPlugin.tag); } catch (Exception ex) { this.allDLLs.Remove(ass); this.allAqiWebs.Remove(iaw.Tag); AqiManage.Remind.Log_Error("加载数据源插件错误", ex, tag); } return(iaw); }