/// <summary> /// 删除 数据源 /// </summary> /// <param name="awname">数据源名称</param> public IAqiWeb DeleAqiWeb(string awname) { IAqiWeb iaw = null; //1删除具体的Runner AqiRunner runner = this[awname + "_Runner"]; if (aqiRunner != null) { aqiRunner.DeleSrcUrl(awname); } //2删除All集合 if (allAqiWebs.ContainsKey(awname)) { iaw = allAqiWebs[awname]; allAqiWebs.Remove(awname); } List <string> tlist = new List <string>(); foreach (ISrcUrl isu in allSrcUrls.Values) { if (isu.IAW.TAG == awname) { tlist.Add(isu.TAG); } } foreach (string isutag in tlist) { allSrcUrls.Remove(isutag); } return(iaw); }
/// <summary> /// 添加插件 /// </summary> /// <param name="path">程序集路径</param> public IAqiWeb LoadDll(string dllpath) { try { //1过滤DLL IAqiWeb iaw = null; Assembly ass = Assembly.LoadFrom(dllpath); Type[] types = ass.GetTypes(); foreach (Type type in types) { if (type.GetInterface("IAqiWeb") != null) { iaw = Activator.CreateInstance(type) as IAqiWeb; } } if (iaw == null) { //无接口 ThrowEvent(RunMessage.RunType.ERR, "程序集未实现IAqiWeb接口:" + ass.FullName); return(null); } if (allDLLs.Exists(dll => { if (dll.FullName == ass.FullName) { return(true); } return(false); })) { //存在 ThrowEvent(RunMessage.RunType.TIP, "程序集已经存在:" + ass.FullName); allDLLs.Remove(ass); } allDLLs.Add(ass); //if (allAqiWebs.ContainsKey(iaw.TAG)) //{ // //存在 // ThrowEvent(RunMessage.RunType.TIP, "数据源已经存在:" + iaw.TAG); // allAqiWebs.Remove(iaw.TAG); //} //allAqiWebs.Add(iaw.TAG,iaw); return(iaw); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
/// <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); }
/// <summary> /// 初始化IAqiWeb接口 /// </summary> private void InitAqiWeb() { foreach (Assembly ass in allDLLs) { Type[] types = ass.GetTypes(); foreach (Type type in types) { if (type.GetInterface("IAqiWeb") != null) { IAqiWeb iaw = Activator.CreateInstance(type) as IAqiWeb; allAqiWebs.Add(iaw.TAG, iaw); Console.WriteLine("加载数据源:" + iaw.NAME); } } } }
private void initAqiWeb() { this.allAqiWebs = new Dictionary <string, IAqiWeb>(); foreach (Assembly assembly in this.allDLLs) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.GetInterface(typeof(IAqiWeb).Name) != null) { try { IAqiWeb iaw = Activator.CreateInstance(type) as IAqiWeb; this.allAqiWebs.Add(iaw.Tag, iaw); AqiManage.Remind.Log_Debug("加载数据源:" + iaw.Name, AqiPlugin.tag); } catch (Exception ex) { AqiManage.Remind.Log_Error("加载数据源错误", ex, AqiPlugin.tag); } } else if (type.GetInterface(typeof(IAqiSave).Name) != null) { /* AddTypeToMapping(typeof (IAqiSave), type);*/ // string name = typeof(IAqiSave).Name; // this.allPluginInterface[name].Add(type); // AqiManage.Remind.Log_Debug("加载持久插件:" + type.Name, AqiPlugin.tag); try { IAqiSave ias = Activator.CreateInstance(type) as IAqiSave; this.allAqiSaves.Add(ias.Name, ias); AqiManage.Remind.Log_Debug("加载持久插件:" + ias.Name, AqiPlugin.tag); } catch (Exception ex) { AqiManage.Remind.Log_Error("加载持久插件错误", ex, AqiPlugin.tag); } } } } }
/// <summary> /// 添加 数据源 /// </summary> /// <param name="iaw">数据源</param> public void AddAqiWeb(IAqiWeb iaw) { thisLock.EnterUpgradeableReadLock(); { if (allAqiWebs.ContainsKey(iaw.TAG)) { //移出旧数据 ThrowEvent(RunMessage.RunType.TIP, "数据源已经存在,进行更新:" + iaw.TAG); allAqiWebs.Remove(iaw.TAG); } //1添加到All集合 Dictionary <string, ISrcUrl> temp = iaw.getAllSrcUrl(); thisLock.EnterWriteLock(); { //添加到列表 allAqiWebs.Add(iaw.TAG, iaw); allSrcUrls = allSrcUrls.Concat(temp).ToDictionary(x => x.Key, x => x.Value); } thisLock.ExitWriteLock(); //2应用到具体的Runner AqiRunner runner = this[iaw.TAG + "_Runner"]; if (runner == null) { //独立模式&&不存在 runner = new AqiRunner(this, temp, iaw.TAG + "_Runner"); //新添加 Add(runner); } else { //只给数据 runner.AddSrcUrl(temp); } } thisLock.ExitUpgradeableReadLock(); }
/// <summary> /// 添加 数据源 /// </summary> /// <param name="iaw">数据源</param> public void AddAqiWeb(IAqiWeb iaw) { thisLock.EnterUpgradeableReadLock(); { if (allAqiWebs.ContainsKey(iaw.TAG)) { //移出旧数据 ThrowEvent(RunMessage.RunType.TIP, "数据源已经存在,进行更新:" + iaw.TAG); allAqiWebs.Remove(iaw.TAG); } //1添加到All集合 Dictionary<string, ISrcUrl> temp = iaw.getAllSrcUrl(); thisLock.EnterWriteLock(); { //添加到列表 allAqiWebs.Add(iaw.TAG, iaw); allSrcUrls = allSrcUrls.Concat(temp).ToDictionary(x => x.Key, x => x.Value); } thisLock.ExitWriteLock(); //2应用到具体的Runner AqiRunner runner = this[iaw.TAG + "_Runner"]; if (runner == null) { //独立模式&&不存在 runner = new AqiRunner(this, temp, iaw.TAG + "_Runner"); //新添加 Add(runner); } else { //只给数据 runner.AddSrcUrl(temp); } } thisLock.ExitUpgradeableReadLock(); }