Esempio n. 1
0
 public void CopyFrom(ICacheParam other)
 {
     CacheMode = other.CacheMode;
     SizeInMB  = other.SizeInMB;
     CacheBlockExpiryPeriodMS = other.CacheBlockExpiryPeriodMS;
     EnableBlockExpiry        = other.EnableBlockExpiry;
 }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
 /// <summary>
 /// 读取更新时间
 ///     从 JSON 文件
 /// </summary>
 /// <param name="icp">ICacheParam</param>
 /// <returns></returns>
 public static DateTime ReadWriteTimeFormJson(ICacheParam icp)
 {
     try
     {
         //JSON路径
         string   jsonPath = icp.GetJsonFile();
         FileInfo fi       = new FileInfo(jsonPath);
         return(fi.LastWriteTime);
     }
     catch (System.Exception ex)
     {
         throw new ParamException("读取参数文件错误", ex);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// 读取参数列表
        ///     从 JSON 文件
        /// </summary>
        /// <param name="icp">ICacheParam</param>
        /// <param name="listProperty">(可选)属性列表</param>
        /// <returns></returns>
        public static List <AqiParam> CreateListFormJson(ICacheParam icp, params string[] listProperty)
        {
            List <AqiParam> listParam    = new List <AqiParam>();
            string          propertyPath = String.Join(".", listProperty);

            try
            {
                //JSON路径
                string jsonPath = icp.GetJsonFile();
                if (!File.Exists(jsonPath))
                {
                    return(listParam);
                }

                //读取JSON
                StreamReader sr       = new StreamReader(jsonPath);
                string       jsonText = sr.ReadToEnd();
                //转JSON Object
                JObject jo = JObject.Parse(jsonText);
                JToken  jt = jo.SelectToken(propertyPath);

                if (jt == null || !jt.HasValues)
                {
                    return(null);
                }
                else if (jt is JArray)
                {
                    //读取集合(任意个参数)
                    JEnumerable <JToken> je     = jt.Children();
                    AqiParam             baseAP = null;
                    foreach (JToken j in je)
                    {
                        AqiParam ap = createParamFormJsonObject(j as JObject, baseAP);
                        if (ap != null)
                        {
                            if (ap.IsTemplate)
                            {
                                baseAP = ap;
                            }
                            else
                            {
                                listParam.Add(ap);
                            }
                        }
                    }
                }
                else if (jt is JObject)
                {
                    //读取对象(仅一个参数)
                    AqiParam ap = createParamFormJsonObject(jt as JObject);
                    if (ap != null)
                    {
                        listParam.Add(ap);
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw new ParamException("参数创建错误", ex);
            }

            return(listParam);
        }
Esempio n. 5
0
        //TODO 应该合并GetProcess

        /// <summary>
        ///
        /// 获取处理
        /// </summary>
        /// <param name="isup"></param>
        /// <param name="sugt"></param>
        public void GetProcess(ISrcUrlParam isup, SrcUrlGroupTimer sugt)
        {
            //获取参数
            List <AqiParam> list = null;
            ISrcUrl         isu  = isup as ISrcUrl;

            try
            {
                if (isup is ICacheParam)
                {
                    ICacheParam icp = isup as ICacheParam;
                    if (icp.IsParamsExpired())
                    {
                        icp.LoadParams();
                    }
                    list = icp.FilterParams();
                }
                else
                {
                    list = isup.EnumParams();
                }
            }
            catch (Exception ex)
            {
                AqiManage.Remind.Log_Error("获取参数错误,错误严重无法继续", ex, this.name, sugt.Name, isu.Name);
                return;
            }

            //TODO
            //应该在检验参数
            while ((list == null) || (list.Count == 0))
            {
                if (isup.ParamIgnoreEmpty)
                {
                    AqiManage.Remind.Log_Error("缺少参数,此数据接口在无参数是将被忽略", new string[] { this.name, sugt.Name, isu.Name });
                    return;
                }
                if (this.ThrowWaitEvent(isu.Name + ":缺少参数,请输入以下参数", isu))
                {
                    AqiManage.Remind.Log_Debug("缺少参数,进入等待", new string[] { this.name, sugt.Name, isu.Name });
                    sugt.Wait();
                }
                else
                {
                    AqiManage.Remind.Log_Error("缺少参数,而且无法获取忽略此数据接口", new string[] { this.name, sugt.Name, isu.Name });
                    return;
                }
            }
            foreach (AqiParam ap in list)
            {
                if (sugt.IsCancellationRequested)
                {
                    break;
                }

                byte[] data = null;
                try
                {
                    data = isup.GetData(ap);
                }
                catch (Exception ex)
                {
                    AqiManage.Remind.Log_Error("数据获取失败,进入重试队列", ex, new string[] { this.name, sugt.Name, isu.Name });
                    this.ar.PutNew(this.name, isu, ap, ex);
                }

                this.SaveProcess(data, isu, ap);
            }
        }