/// <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="name"></param> /// <returns></returns> public AqiRunner this[string name] { get { AqiRunner r = null; thisLock.EnterReadLock(); { RunMode rm = (RunMode)Enum.Parse(typeof(RunMode), AqiManage.Setting["RunMode"]); switch (rm) { case RunMode.SELF: if (runnerlist.ContainsKey(name)) { r = runnerlist[name]; } break; case RunMode.JOINT: default: r = aqiRunner; break; } } thisLock.ExitReadLock(); return(r); } }
/// <summary> /// 添加runner /// </summary> /// <param name="runner"></param> public void Add(AqiRunner runner) { if (runnerlist.ContainsKey(runner.Name)) { runnerlist[runner.Name].Union(runner); } else { runnerlist.Add(runner.Name, runner); runner.RunAll(); } }
/// <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> /// <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> private void initRunner() { //读取配置文件,独立或合并 RunMode rm = (RunMode)Enum.Parse(typeof(RunMode), AqiManage.Setting["RunMode"]); switch (rm) { case RunMode.SELF: runnerlist = new Dictionary <string, AqiRunner>(); foreach (IAqiWeb iaw in allAqiWebs.Values) { AqiRunner ar = new AqiRunner(this, iaw.getAllSrcUrl(), iaw.TAG + "_Runner"); runnerlist.Add(ar.Name, ar); } break; case RunMode.JOINT: default: aqiRunner = new AqiRunner(this, allSrcUrls); aqiRunner.RunEvent += new AqiRunner.RunEventHandler(aqiRunner_RunEvent); break; } }