/// <summary> /// 初始化运行者 /// </summary> private void initRunner() { this.aqiRunner = new Dictionary <string, AqiRunner>(); AqiRunner runner = null; //读取配置文件,独立或合并 switch (((AqiRunner.RunMode)Enum.Parse(typeof(AqiRunner.RunMode), Setting[AqiRunner.SET_RUNMODE]))) { case AqiRunner.RunMode.SELF: List <IAqiWeb> aqiWebList = AqiPlugin.Instance.GetAqiWebList(); foreach (IAqiWeb web in aqiWebList) { runner = new AqiRunner(this, web.GetAllSrcUrl().Values.ToList(), web.Tag + "_Runner"); runner.RunEvent += new AqiRunner.RunEventHandler(this.aqiRunner_RunEvent); this.aqiRunner.Add(runner.Name, runner); Remind.Log_Debug("初始化Runner:" + runner.Name, tag); } break; case AqiRunner.RunMode.JOINT: runner = new AqiRunner(this, AqiPlugin.Instance.GetSrcUrlList()); runner.RunEvent += new AqiRunner.RunEventHandler(this.aqiRunner_RunEvent); this.aqiRunner.Add(AqiRunner.DEFAULT_NAME, runner); Remind.Log_Debug("初始化单一Runner:" + runner.Name, tag); break; } }
/// <summary> /// 根据名称索引运行者 /// </summary> /// <param name="name"></param> /// <returns></returns> public AqiRunner this[string name] { get { AqiRunner runner = null; this.thisLock.EnterReadLock(); string str = Setting[AqiRunner.SET_RUNMODE]; if (str == null) { str = AqiRunner.RunMode.JOINT.ToString(); } switch (((AqiRunner.RunMode)Enum.Parse(typeof(AqiRunner.RunMode), str))) { case AqiRunner.RunMode.SELF: if (this.aqiRunner.ContainsKey(name)) { runner = this.aqiRunner[name]; } break; default: runner = this.aqiRunner[AqiRunner.DEFAULT_NAME]; break; } this.thisLock.ExitReadLock(); return(runner); } }
/// <summary> /// 合并timer /// </summary> /// <param name="runner"></param> public bool Union(AqiRunner runner) { try { runner.thisLock.EnterWriteLock(); this.thisLock.EnterWriteLock(); foreach (string name in runner.dictTimer.Keys) { if (this.dictTimer.ContainsKey(name)) { this.dictTimer[name].Union(runner.dictTimer[name]); } else { this.dictTimer.Add(name, runner.dictTimer[name]); } } runner.dictTimer.Clear(); return(true); } finally { this.thisLock.ExitWriteLock(); runner.thisLock.ExitWriteLock(); } }
/// <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="iawTag"></param> /// <returns></returns> public bool UnLoad(string iawTag) { try { //卸载AqiRunner AqiRunner runner = null; switch (((AqiRunner.RunMode)Enum.Parse(typeof(AqiRunner.RunMode), Setting[AqiRunner.SET_RUNMODE]))) { case AqiRunner.RunMode.SELF: runner = this.aqiRunner[iawTag + "_Runner"]; break; case AqiRunner.RunMode.JOINT: runner = this.aqiRunner[AqiRunner.DEFAULT_NAME]; break; } if (runner == null) { Remind.Log_Error("卸载插件时没有找到同名Runner:" + iawTag, tag); return(false); } if (!runner.DeleSrcUrl(iawTag)) { Remind.Log_Error("未能卸载Runner中的ISrcUrl接口:" + iawTag, tag); return(false); } //卸载AqiPlugin if (!AqiManage.Plugin.UnLoad(iawTag)) { Remind.Log_Error("未能卸载指定插件:" + iawTag, tag); return(false); } } catch (Exception ex) { Remind.Log_Error("卸载指定插件错误", ex, tag); return(false); } return(true); }
/// <summary> /// 处理 /// Timer处理线程调用 /// </summary> /// <param name="runner"></param> public bool Handle(AqiRunner runner) { this.thisLock.EnterReadLock(); foreach (ISrcUrl url in this.listISU.Values) { if (this.IsCancellationRequested) { return false; } runner.RouteProcess(url, this); } this.thisLock.ExitReadLock(); return true; }
/// <summary> /// 初始化运行者 /// </summary> private void initRunner() { this.aqiRunner = new Dictionary<string, AqiRunner>(); AqiRunner runner = null; //读取配置文件,独立或合并 switch (((AqiRunner.RunMode) Enum.Parse(typeof(AqiRunner.RunMode), Setting[AqiRunner.SET_RUNMODE]))) { case AqiRunner.RunMode.SELF: List<IAqiWeb> aqiWebList = AqiPlugin.Instance.GetAqiWebList(); foreach (IAqiWeb web in aqiWebList) { runner = new AqiRunner(this, web.GetAllSrcUrl().Values.ToList(), web.Tag + "_Runner"); runner.RunEvent += new AqiRunner.RunEventHandler(this.aqiRunner_RunEvent); this.aqiRunner.Add(runner.Name, runner); Remind.Log_Debug("初始化Runner:" + runner.Name, tag); } break; case AqiRunner.RunMode.JOINT: runner = new AqiRunner(this, AqiPlugin.Instance.GetSrcUrlList()); runner.RunEvent += new AqiRunner.RunEventHandler(this.aqiRunner_RunEvent); this.aqiRunner.Add(AqiRunner.DEFAULT_NAME, runner); Remind.Log_Debug("初始化单一Runner:" + runner.Name, tag); break; } }
/// <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> /// 合并timer /// </summary> /// <param name="runner"></param> public bool Union(AqiRunner runner) { try { runner.thisLock.EnterWriteLock(); this.thisLock.EnterWriteLock(); foreach(string name in runner.dictTimer.Keys) { if (this.dictTimer.ContainsKey(name)) { this.dictTimer[name].Union(runner.dictTimer[name]); } else { this.dictTimer.Add(name, runner.dictTimer[name]); } } runner.dictTimer.Clear(); return true; } finally { this.thisLock.ExitWriteLock(); runner.thisLock.ExitWriteLock(); } }