/// <summary> /// 加载参数 /// 可以重写 /// </summary> /// <returns></returns> public virtual bool LoadParams() { switch (ParamSourceType) { case AqiConstant.ParamSourceType.JSON: this.listParamCache = AqiParam.CreateListFormJson(this, this.Tag, AqiParam.PARAMS); this.dtParamCacheTime = AqiParam.ReadWriteTimeFormJson(this); break; case AqiConstant.ParamSourceType.ISrcUrl: if (this is IParseSrcUrlParam) { IParseSrcUrlParam ipp = this as IParseSrcUrlParam; this.listParamCache = AqiParam.CreateListFormSrcUrl(ipp, ipp.ParamSrcUrl); this.dtParamCacheTime = DateTime.Now; } else { throw new ParamException("参数来源类型(ISRCUrl)与接口(IParseParam)不匹配"); } break; default: throw new ParamException("参数来源类型(ParamSourceType)未知"); } //TODO //验证参数是否匹配ParamName return(true); }
/// <summary> /// 读取参数列表 /// 从 SrcUrl 接口 /// </summary> /// <param name="iParseSrcUrlParam">实现IParseSrcUrlParam的SrcUrl</param> /// <param name="relySrcUrl">参数来源SrcUrl</param> /// <returns></returns> public static List <AqiParam> CreateListFormSrcUrl(IParseSrcUrlParam iParseSrcUrlParam, ISrcUrl relySrcUrl) { List <AqiParam> listParam = new List <AqiParam>(); //TODO 应该将 runner的处理过程公开,交由Runner处理,公用代码,考虑将Process处理函数静态化 try { if (relySrcUrl is ISrcUrlParam) { ISrcUrlParam isup = relySrcUrl as ISrcUrlParam; List <AqiParam> list = null; if (isup is ICacheParam) { ICacheParam icp = isup as ICacheParam; if (icp.IsParamsExpired()) { icp.LoadParams(); } list = icp.FilterParams(); } else { list = isup.EnumParams(); } if ((list == null) || (list.Count == 0)) { throw new ParamException("缺少参数"); } foreach (AqiParam ap in list) { byte[] data = data = isup.GetData(ap); List <AqiParam> aps = iParseSrcUrlParam.ParseParam(data); listParam.AddRange(aps); } } else { byte[] data = relySrcUrl.GetData(); List <AqiParam> aps = iParseSrcUrlParam.ParseParam(data); listParam.AddRange(aps); } } catch (System.Exception ex) { throw new ParamException("参数创建错误", ex); } return(listParam); }
/// <summary> /// 检查过期 /// 可以重写 /// </summary> /// <remarks> /// 判断是否需要重新设置Cookie /// </remarks> /// <returns>true过期;false未过期</returns> public override bool IsParamsExpired() { if (ParamCache == null || ParamCache.Count == 0) { return(true); } IParseSrcUrlParam ipp = this as IParseSrcUrlParam; AqiParam dsidAqiParam = AqiParam.CreateListFormSrcUrl(ipp, ipp.ParamSrcUrl)[0]; HttpData data = ((ICacheData)ipp.ParamSrcUrl).Data; if (data.Header.ContainsKey("Set-Cookie")) { return(true); } return(false); }
/// <summary> /// 加载参数 /// 可以重写 /// </summary> /// <remarks> /// 获取DSId与Cookie /// </remarks> /// <returns></returns> public override bool LoadParams() { bool result = base.LoadParams(); if (result) { IParseSrcUrlParam ipp = this as IParseSrcUrlParam; AqiParam dsidAqiParam = AqiParam.CreateListFormSrcUrl(ipp, ipp.ParamSrcUrl)[0]; HttpData data = ((ICacheData)ipp.ParamSrcUrl).Data; foreach (AqiParam param in ParamCache) { param["DSId"] = dsidAqiParam["DSId"]; if (data.Header.ContainsKey("Set-Cookie")) { param.Header["Cookie"] = data.Header["Set-Cookie"]; } } } return(result); }