Example #1
0
        /// <summary>
        /// 重试处理
        ///     应该由Retryer线程调用
        /// </summary>
        /// <param name="arn">重试节点</param>
        /// <returns></returns>
        public bool RetryProcess(RetryNode arn)
        {
            ISrcUrl  isu = arn.SrcUrl;
            AqiParam ap  = arn.Param;

            byte[] data = null;
            try
            {
                if (isu is ISrcUrlParam)
                {
                    ISrcUrlParam isup = isu as ISrcUrlParam;
                    data = isup.GetData(ap);
                }
                else
                {
                    data = isu.GetData();
                }
            }
            catch (Exception ex)
            {
                AqiManage.Remind.Log_Error("数据重试失败,再入重试队列", new string[] { this.name, arn.Name, isu.Name });
                this.ar.PutAgain(arn, ex);
                return(false);
            }
            this.SaveProcess(data, isu, ap);
            arn.Reset();
            return(true);
        }
Example #2
0
 /// <summary>
 /// 保存处理
 /// </summary>
 /// <param name="data">数据</param>
 /// <param name="isu">数据接口</param>
 /// <param name="ap">参数</param>
 public void SaveProcess(byte[] data, ISrcUrl isu, AqiParam ap)
 {
     try
     {
         //统计信息
         NoteNode node = this.an.AddNew(isu, ap, data);
         //保存
         if (ap == null)
         {
             node.Saved = this.ias.Save(isu, data);
         }
         else
         {
             node.Saved = this.ias.Save(isu, ap, data);
         }
         if (node.Saved)
         {
             AqiManage.Remind.Log_Info("数据保存成功", new string[] { this.name, isu.Name });
         }
         else
         {
             node.Data = data;
             AqiManage.Remind.Log_Error("数据保存失败", new string[] { this.name, isu.Name });
         }
     }
     catch (Exception exception)
     {
         AqiManage.Remind.Log_Error("数据保存失败", exception, new string[] { this.name, isu.Name });
     }
 }
Example #3
0
        /// <summary>
        /// 新数据
        /// </summary>
        /// <param name="isu"></param>
        /// <param name="data"></param>
        public AqiNoteNode AddNew(ISrcUrl isu, AqiParam ap, byte[] data)
        {
            int    nSize = data.Length;
            string nName = null;

            if (ap == null)
            {
                nName = isu.TAG;
            }
            else
            {
                nName = isu.TAG + ap.Name;
            }
            AqiNoteNode n = new AqiNoteNode(nName, nSize);

            lock (history)
            {
                history.Add(n.Name, n);

                endtime = DateTime.Now;
                size    = size + n.DateSize;
                count++;
            }

            return(n);
        }
Example #4
0
 /// <summary>
 /// 新数据
 /// </summary>
 /// <param name="isu"></param>
 /// <param name="data"></param>
 public NoteNode AddNew(ISrcUrl isu, AqiParam ap, byte[] data)
 {
     int size = 0;
     if (data != null)
     {
         size = data.Length;
     }
     string name = null;
     if (ap == null)
     {
         name = isu.Tag;
     }
     else
     {
         name = isu.Tag + ap.Name;
     }
     NoteNode item = new NoteNode(name, size);
     lock (this.history)
     {
         this.history.Add(item);
         this.endtime = DateTime.Now;
         this.size += item.dateSize;
         this.count += 1L;
     }
     return item;
 }
Example #5
0
        public bool Save(ISrcUrl isu, AqiParam param, byte[] data)
        {
            try
            {
                string str;
                if (data == null)
                {
                    data = new byte[0];
                    if (!this.saveEmpty)
                    {
                        return false;
                    }
                }
                //目录
                string path = this.basePath + isu.IAW.Tag + @"\" + isu.Tag + @"\";
                //分组
                string grouptag = "";
                //文件名
                string nameFile = this.getDate() + "_" + this.getTime();

                if (param != null)
                {
                    grouptag = param.Name;
                    if (param.Unique)
                    {
                        nameFile = grouptag;
                    }
                    else
                    {
                        path = path + grouptag + @"\";
                    }
                }

                //扩展名
                string nameExtension = "." + isu.IAW.DAT.ToString().ToLower();
                if (isu is IDataType)
                {
                    IDataType idt = (isu as IDataType);
                    if (idt.DAT == AqiConstant.DataType.NONE)
                    {
                        nameExtension = "";
                    }else{
                        nameExtension = "." + idt.DAT.ToString().ToLower();
                    }
                }
                str = nameFile + nameExtension;

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                AqiManage.Remind.Log_Debug("保存路径为" + path + str, new string[] { this.Name });
                return FileReadSaveUtil.Save(data, path + str);
            }
            catch (Exception exception)
            {
                AqiManage.Remind.Log_Error("保存失败", exception, new string[] { this.Name });
                return false;
            }
        }
Example #6
0
        /// <summary>
        /// 重试处理
        /// </summary>
        /// <param name="arn"></param>
        private bool retryProcess(AqiRetryNode arn)
        {
            ISrcUrl  isu = arn.SRCURL;
            AqiParam ap  = arn.PARAM;

            byte[] data = null;
            try
            {
                if (ap != null)
                {
                    data = isu.getDate(ap);
                }
                else
                {
                    data = isu.getDate();
                }
            }
            catch (Exception ex)
            {
                //再 入重试队列
                PutAgain(arn, ex);
                return(false);
            }
            am.AqiRun.saveProcess(isu, ap, data);
            //重置
            arn.Reset();
            return(true);
        }
Example #7
0
        /// <summary>
        /// 新数据
        /// </summary>
        /// <param name="isu"></param>
        /// <param name="data"></param>
        public NoteNode AddNew(ISrcUrl isu, AqiParam ap, byte[] data)
        {
            int size = 0;

            if (data != null)
            {
                size = data.Length;
            }
            string name = null;

            if (ap == null)
            {
                name = isu.Tag;
            }
            else
            {
                name = isu.Tag + ap.Name;
            }
            NoteNode item = new NoteNode(name, size);

            lock (this.history)
            {
                this.history.Add(item);
                this.endtime = DateTime.Now;
                this.size   += item.dateSize;
                this.count  += 1L;
            }
            return(item);
        }
Example #8
0
        /// <summary>
        /// 合并
        ///     仅定时线程调用
        /// </summary>
        /// <param name="node"></param>
        public void Concat(AqiRetryNode node)
        {
            thisLock.EnterWriteLock();
            try
            {
                this.isu       = node.isu;
                this.ap        = node.ap;
                this.starttime = DateTime.Now;
                this.endtime   = DateTime.Now;
                this.count     = 1;

                //将NAME_DATA计数保留,其他清空
                int i = 0;
                if (this.counts.ContainsKey(NAME_DATA))
                {
                    i = this.counts[NAME_DATA];
                }
                this.counts.Clear();
                this.counts.Add(NAME_DATA, i);
                this.counts = this.counts.Concat(node.counts).ToDictionary(x => x.Key, y => y.Value);
                AddNameCount(NAME_DATA);
            }
            finally
            {
                thisLock.ExitWriteLock();
            }
        }
Example #9
0
        /// <summary>
        /// 路由处理
        /// </summary>
        /// <param name="isu">数据接口</param>
        /// <param name="sug">定时器,用于堵塞</param>
        public void routeProcess(ISrcUrl isu, SrcUrlGroupTimer sug)
        {
            if (isu.USEPARAM)
            {
                IMakeParam      ip        = isu as IMakeParam;
                List <AqiParam> paramList = ip.enumParams();

                while (paramList == null || paramList.Count == 0)
                {
                    bool bEvent = ThrowWaitEvent(isu.NAME + ":缺少参数,请输入以下参数", isu);
                    if (bEvent)
                    {
                        //若接受事件
                        //由用户生成参数
                        //TEST等待用户输入参数
                        sug.Wait();
                    }
                    else
                    {
                        //不接受事件则无法输入参数,忽略
                        ThrowEvent(RunMessage.RunType.TIP, isu.NAME + ":缺少参数,而且无法获取忽略此数据接口");
                        return;
                    }
                }
                foreach (AqiParam ap in paramList)
                {
                    getProcess(isu, ap);
                }
            }
            else
            {
                getProcess(isu, null);
            }
        }
Example #10
0
        /// <summary>
        /// 新数据
        /// </summary>
        /// <param name="isu"></param>
        /// <param name="data"></param>
        public AqiNoteNode AddNew(ISrcUrl isu, AqiParam ap, byte[] data)
        {
            int nSize = data.Length;
            string nName = null;
            if(ap == null)
            {
                nName = isu.TAG;
            }
            else
            {
                nName = isu.TAG + ap.Name;
            }
            AqiNoteNode n = new AqiNoteNode(nName, nSize);

            lock(history)
            {
                history.Add(n.Name, n);

                endtime = DateTime.Now;
                size = size + n.DateSize;
                count++;
            }

            return n;
        }
Example #11
0
        private ReaderWriterLockSlim thisLock; //读写锁

        #endregion Fields

        #region Constructors

        public AqiRetryNode(ISrcUrl isrcurl, AqiParam aqiparam)
        {
            this.ap = aqiparam;
            this.isu = isrcurl;
            this.starttime = DateTime.Now;
            this.endtime = DateTime.Now;
            this.count = 1;
            this.counts = new Dictionary<string, int>();
            this.thisLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
        }
Example #12
0
 public AqiRetryNode(ISrcUrl isrcurl, AqiParam aqiparam)
 {
     this.ap        = aqiparam;
     this.isu       = isrcurl;
     this.starttime = DateTime.Now;
     this.endtime   = DateTime.Now;
     this.count     = 1;
     this.counts    = new Dictionary <string, int>();
     this.thisLock  = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
 }
Example #13
0
 public bool ThrowWaitEvent(string eMsg, ISrcUrl eSrcUrl)
 {
     if (RunEvent != null)
     {
         RunMessage rm = new RunMessage(RunMessage.RunType.WAIT, eMsg, this);
         rm.AttachObject = (eSrcUrl as IMakeParam).PL;
         RunEvent(rm);
         return(true);
     }
     return(false);
 }
Example #14
0
        /// <summary>
        /// 入重试队列
        ///     定时器线程
        /// </summary>
        /// <param name="arName"></param>
        /// <param name="isu"></param>
        /// <param name="ap"></param>
        /// <param name="ex"></param>
        public void PutNew(string arName, ISrcUrl isu, AqiParam ap, Exception ex)
        {
            //封装为重试节点
            RetryNode arn = new RetryNode(arName, isu, ap);

            arn.NodeEvent += new RetryNode.NodeEventHandler(this.node_RunEvent);
            //更新计数
            arn.Update(ex);
            //添加历史记录
            arn = this.AddHistory(arn);
            //入队列
            this.Push(arn.Name);
            AqiManage.Remind.Log_Info("已添加到重试队列", new string[] { this.name, arn.RunnerName, arn.Name });
        }
Example #15
0
 /// <summary>
 /// 获取处理
 /// </summary>
 /// <param name="isu">数据接口</param>
 /// <param name="sugt">定时器</param>
 public void GetProcess(ISrcUrl isu, SrcUrlGroupTimer sugt)
 {
     byte[] data = null;
     try
     {
         data = isu.GetData();
     }
     catch (Exception exception)
     {
         AqiManage.Remind.Log_Error("数据获取失败,进入重试队列", new string[] { this.name, sugt.Name, isu.Name });
         this.ar.PutNew(this.name, isu, null, exception);
         return;
     }
     this.SaveProcess(data, isu, null);
 }
Example #16
0
        public bool Save(ISrcUrl isu, string grouptag, byte[] data)
        {
            string fileName = fileName = getDate() + "_" + getTime() + "." + isu.IAW.DAT.ToString().ToLower();
            string filePath = basePath + isu.IAW.TAG + "\\" + isu.TAG + "\\";
            if (!String.IsNullOrEmpty(grouptag))
            {
                filePath = filePath + grouptag + "\\";
            }

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            return FileReadSaveUtil.Save(data, filePath + fileName);
        }
Example #17
0
        /// <summary>
        /// 入重试队列
        ///     定时器线程
        /// </summary>
        /// <param name="isu"></param>
        /// <param name="ap"></param>
        /// <param name="ex"></param>
        public void PutNew(ISrcUrl isu, AqiParam ap, Exception ex)
        {
            //封装为重试节点
            AqiRetryNode arn = new AqiRetryNode(isu, ap);

            //更新计数
            if (!updateNode(arn, ex))
            {
                return;
            }

            //添加历史记录
            arn = AddHistory(arn);

            //入队列
            Push(arn.NAME);
        }
Example #18
0
        public bool Save(ISrcUrl isu, string grouptag, byte[] data)
        {
            string fileName = fileName = getDate() + "_" + getTime() + "." + isu.IAW.DAT.ToString().ToLower();
            string filePath = basePath + isu.IAW.TAG + "\\" + isu.TAG + "\\";

            if (!String.IsNullOrEmpty(grouptag))
            {
                filePath = filePath + grouptag + "\\";
            }

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            return(FileReadSaveUtil.Save(data, filePath + fileName));
        }
Example #19
0
        /// <summary>
        /// 获得所有数据源
        /// </summary>
        /// <returns></returns>
        public virtual Dictionary <string, ISrcUrl> GetAllSrcUrl()
        {
            Assembly asm = this.GetType().Assembly;

            if (allSrcUrls == null)
            {
                allSrcUrls = new Dictionary <string, ISrcUrl>();
                foreach (string classname in allSrcNames)
                {
                    Type    t   = asm.GetType(classname);
                    ISrcUrl src = (ISrcUrl)Activator.CreateInstance(t);
                    src.IAW = this as IAqiWeb;
                    allSrcUrls.Add(classname, src);
                }
            }
            return(allSrcUrls);
        }
Example #20
0
 /// <summary>
 /// 添加ISU
 ///     Main控制线程调用
 /// </summary>
 public bool Add(ISrcUrl isu)
 {
     if (intervalseconds == isu.UDI)
     {
         if (this.thisLock.TryEnterWriteLock(1000))
         {
             if (listISU.ContainsKey(isu.Tag))
             {
                 listISU[isu.Tag] = isu;
             }
             else
             {
                 listISU.Add(isu.Tag, isu);
             }
             this.thisLock.ExitWriteLock();
             return(true);
         }
     }
     return(false);
 }
Example #21
0
        /*
         * Process处理函数应该保持线程安全
         * Runner下的多个Timer会调用此Runner的处理函数
         *
         * */

        /// <summary>
        /// 路由处理
        ///     应该由Timer线程调用,可能会嵌套
        ///     再此方法中调用的方法应保证线程安全
        /// </summary>
        /// <param name="isu">数据接口</param>
        /// <param name="sugt">定时器,用于堵塞</param>
        public void RouteProcess(ISrcUrl isu, SrcUrlGroupTimer sugt)
        {
            //加载配置
            if (isu.IAW is ICacheConfig)
            {
                ICacheConfig icc = isu.IAW as ICacheConfig;
                if (!icc.IsSrcUrlEnabled(isu.Tag))
                {
                    return;
                }
            }

            //双向确认是否使用参数
            if (isu.UseParam && isu is ISrcUrlParam)
            {
                this.GetProcess(isu as ISrcUrlParam, sugt);
            }
            else
            {
                this.GetProcess(isu, sugt);
            }
        }
Example #22
0
 /// <summary>
 /// 获取处理
 /// </summary>
 /// <param name="isu">数据接口</param>
 /// <param name="ap">参数,无null</param>
 public void getProcess(ISrcUrl isu, AqiParam ap)
 {
     byte[] data = null;
     try
     {
         if (ap != null)
         {
             data = isu.getDate(ap);
         }
         else
         {
             data = isu.getDate();
         }
     }
     catch (Exception ex)
     {
         ThrowEvent(RunMessage.RunType.ERR, isu.NAME + ":数据获取失败,进入重试队列");
         //入重试队列
         ar.PutNew(isu, ap, ex);
         return;
     }
     saveProcess(isu, ap, data);
 }
Example #23
0
        public static Dictionary <string, SrcUrlGroupTimer> CreateList(List <ISrcUrl> listSrcUrl, Action <object, System.Timers.ElapsedEventArgs> firstMethod)
        {
            List <SrcUrlGroupTimer> source = new List <SrcUrlGroupTimer>();

            using (List <ISrcUrl> .Enumerator enumerator = listSrcUrl.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Predicate <SrcUrlGroupTimer> match = null;
                    ISrcUrl isu = enumerator.Current;
                    if (match == null)
                    {
                        match = sugt => sugt.IntervalSeconds == isu.UDI;
                    }
                    SrcUrlGroupTimer item = source.Find(match);
                    if (item != null)
                    {
                        item.listISU.Add(isu.Tag, isu);
                    }
                    else
                    {
                        string someTime = Language.GetSomeTime(isu.UDI);
                        if (isu.UDI <= 0.0)
                        {
                            item = new SrcUrlGroupTimer(someTime, firstMethod);
                        }
                        else
                        {
                            item = new SrcUrlGroupTimer(someTime, isu.UDI, firstMethod);
                        }
                        item.listISU.Add(isu.Tag, isu);
                        source.Add(item);
                    }
                }
            }
            return(source.ToDictionary <SrcUrlGroupTimer, string, SrcUrlGroupTimer>(sugt => sugt.name, sugt => sugt));
        }
Example #24
0
        /// <summary>
        /// 保存处理
        /// </summary>
        /// <param name="isu">数据接口</param>
        /// <param name="ap">参数</param>
        /// <param name="data">数据</param>
        public void saveProcess(ISrcUrl isu, AqiParam ap, byte[] data)
        {
            //统计信息
            AqiNoteNode n = an.AddNew(isu, ap, data);

            //保存
            if (ap == null)
            {
                n.Saved = ias.Save(isu, data);
            }
            else
            {
                n.Saved = ias.Save(isu, ap.Name, data);
            }

            if (n.Saved)
            {
                ThrowEvent(RunMessage.RunType.OK, isu.IAW.NAME + ":" + isu.NAME + ":数据获取成功");
            }
            else
            {
                ThrowEvent(RunMessage.RunType.ERR, isu.NAME + ":数据获取失败");
            }
        }
Example #25
0
        /// <summary>
        /// 入重试队列
        ///     定时器线程
        /// </summary>
        /// <param name="isu"></param>
        /// <param name="ap"></param>
        /// <param name="ex"></param>
        public void PutNew(ISrcUrl isu, AqiParam ap, Exception ex)
        {
            //封装为重试节点
            AqiRetryNode arn = new AqiRetryNode(isu, ap);

            //更新计数
            if (!updateNode(arn, ex))
            {
                return;
            }

            //添加历史记录
            arn = AddHistory(arn);

            //入队列
            Push(arn.NAME);
        }
Example #26
0
 /// <summary>
 /// 获取处理
 /// </summary>
 /// <param name="isu">数据接口</param>
 /// <param name="sugt">定时器</param>
 public void GetProcess(ISrcUrl isu, SrcUrlGroupTimer sugt)
 {
     byte[] data = null;
     try
     {
         data = isu.GetData();
     }
     catch (Exception exception)
     {
         AqiManage.Remind.Log_Error("数据获取失败,进入重试队列", new string[] { this.name, sugt.Name, isu.Name });
         this.ar.PutNew(this.name, isu, null, exception);
         return;
     }
     this.SaveProcess(data, isu, null);
 }
Example #27
0
 /// <summary>
 /// 获取处理
 /// </summary>
 /// <param name="isu">数据接口</param>
 /// <param name="ap">参数,无null</param>
 public void getProcess(ISrcUrl isu, AqiParam ap)
 {
     byte[] data = null;
     try
     {
         if (ap != null)
         {
             data = isu.getDate(ap);
         }
         else
         {
             data = isu.getDate();
         }
     }
     catch (Exception ex)
     {
         ThrowEvent(RunMessage.RunType.ERR, isu.NAME + ":数据获取失败,进入重试队列");
         //入重试队列
         ar.PutNew(isu, ap, ex);
         return;
     }
     saveProcess(isu, ap, data);
 }
Example #28
0
 /// <summary>
 /// 添加ISU
 ///     Main控制线程调用
 /// </summary>
 public bool Add(ISrcUrl isu)
 {
     if (intervalseconds == isu.UDI)
     {
         if (this.thisLock.TryEnterWriteLock(1000))
         {
             if (listISU.ContainsKey(isu.Tag))
             {
                 listISU[isu.Tag] = isu;
             }
             else
             {
                 listISU.Add(isu.Tag, isu);
             }
             this.thisLock.ExitWriteLock();
             return true;
         }
     }
     return false;
 }
Example #29
0
 public bool Save(ISrcUrl isu, AqiParam param, byte[] data)
 {
     throw new NotImplementedException();
 }
Example #30
0
 public bool Save(ISrcUrl isu, byte[] data)
 {
     return(Save(isu, null, data));
 }
Example #31
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);
        }
Example #32
0
 /// <summary>
 /// 入重试队列
 ///     定时器线程
 /// </summary>
 /// <param name="arName"></param>
 /// <param name="isu"></param>
 /// <param name="ap"></param>
 /// <param name="ex"></param>
 public void PutNew(string arName, ISrcUrl isu, AqiParam ap, Exception ex)
 {
     //封装为重试节点
     RetryNode arn = new RetryNode(arName, isu, ap);
     arn.NodeEvent += new RetryNode.NodeEventHandler(this.node_RunEvent);
     //更新计数
     arn.Update(ex);
     //添加历史记录
     arn = this.AddHistory(arn);
     //入队列
     this.Push(arn.Name);
     AqiManage.Remind.Log_Info("已添加到重试队列", new string[] { this.name, arn.RunnerName, arn.Name });
 }
Example #33
0
 public bool ThrowWaitEvent(string eMsg, ISrcUrl eSrcUrl)
 {
     if (RunEvent != null)
     {
         RunMessage rm = new RunMessage(RunMessage.RunType.WAIT, eMsg, this);
         rm.AttachObject = (eSrcUrl as IMakeParam).PL;
         RunEvent(rm);
         return true;
     }
     return false;
 }
Example #34
0
        /// <summary>
        /// 保存处理
        /// </summary>
        /// <param name="isu">数据接口</param>
        /// <param name="ap">参数</param>
        /// <param name="data">数据</param>
        public void saveProcess(ISrcUrl isu, AqiParam ap, byte[] data)
        {
            //统计信息
            AqiNoteNode n = an.AddNew(isu, ap, data);
            //保存
            if(ap == null)
            {
                n.Saved = ias.Save(isu, data);
            }
            else
            {
                n.Saved = ias.Save(isu, ap.Name, data);
            }

            if (n.Saved)
            {
                ThrowEvent(RunMessage.RunType.OK, isu.IAW.NAME + ":" + isu.NAME + ":数据获取成功");
            }
            else
            {
                ThrowEvent(RunMessage.RunType.ERR, isu.NAME + ":数据获取失败");
            }
        }
Example #35
0
        /// <summary>
        /// 路由处理
        /// </summary>
        /// <param name="isu">数据接口</param>
        /// <param name="sug">定时器,用于堵塞</param>
        public void routeProcess(ISrcUrl isu, SrcUrlGroupTimer sug)
        {
            if (isu.USEPARAM)
            {
                IMakeParam ip = isu as IMakeParam;
                List<AqiParam> paramList = ip.enumParams();

                while (paramList == null || paramList.Count == 0)
                {
                    bool bEvent = ThrowWaitEvent(isu.NAME + ":缺少参数,请输入以下参数", isu);
                    if (bEvent)
                    {
                        //若接受事件
                        //由用户生成参数
                        //TEST等待用户输入参数
                        sug.Wait();
                    }
                    else
                    {
                        //不接受事件则无法输入参数,忽略
                        ThrowEvent(RunMessage.RunType.TIP, isu.NAME + ":缺少参数,而且无法获取忽略此数据接口");
                        return;
                    }
                }
                foreach (AqiParam ap in paramList)
                {
                    getProcess(isu, ap);
                }
            }
            else
            {
                getProcess(isu, null);
            }
        }
Example #36
0
 public bool Save(ISrcUrl isu, byte[] data)
 {
     return Save(isu, null, data);
 }
Example #37
0
        public bool Save(ISrcUrl isu, AqiParam param, byte[] data)
        {
            try
            {
                string str;
                if (data == null)
                {
                    data = new byte[0];
                    if (!this.saveEmpty)
                    {
                        return(false);
                    }
                }
                //目录
                string path = this.basePath + isu.IAW.Tag + @"\" + isu.Tag + @"\";
                //分组
                string grouptag = "";
                //文件名
                string nameFile = this.getDate() + "_" + this.getTime();

                if (param != null)
                {
                    grouptag = param.Name;
                    if (param.Unique)
                    {
                        nameFile = grouptag;
                    }
                    else
                    {
                        path = path + grouptag + @"\";
                    }
                }

                //扩展名
                string nameExtension = "." + isu.IAW.DAT.ToString().ToLower();
                if (isu is IDataType)
                {
                    IDataType idt = (isu as IDataType);
                    if (idt.DAT == AqiConstant.DataType.NONE)
                    {
                        nameExtension = "";
                    }
                    else
                    {
                        nameExtension = "." + idt.DAT.ToString().ToLower();
                    }
                }
                str = nameFile + nameExtension;

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                AqiManage.Remind.Log_Debug("保存路径为" + path + str, new string[] { this.Name });
                return(FileReadSaveUtil.Save(data, path + str));
            }
            catch (Exception exception)
            {
                AqiManage.Remind.Log_Error("保存失败", exception, new string[] { this.Name });
                return(false);
            }
        }
Example #38
0
 /// <summary>
 /// 保存处理
 /// </summary>
 /// <param name="data">数据</param>
 /// <param name="isu">数据接口</param>
 /// <param name="ap">参数</param>
 public void SaveProcess(byte[] data, ISrcUrl isu, AqiParam ap)
 {
     try
     {
         //统计信息
         NoteNode node = this.an.AddNew(isu, ap, data);
         //保存
         if (ap == null)
         {
             node.Saved = this.ias.Save(isu, data);
         }
         else
         {
             node.Saved = this.ias.Save(isu, ap, data);
         }
         if (node.Saved)
         {
             AqiManage.Remind.Log_Info("数据保存成功", new string[] { this.name, isu.Name });
         }
         else
         {
             node.Data = data;
             AqiManage.Remind.Log_Error("数据保存失败", new string[] { this.name, isu.Name });
         }
     }
     catch (Exception exception)
     {
         AqiManage.Remind.Log_Error("数据保存失败", exception, new string[] { this.name, isu.Name });
     }
 }
Example #39
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);
            }
        }
Example #40
0
        /*
         * Process处理函数应该保持线程安全
         * Runner下的多个Timer会调用此Runner的处理函数
         *
         * */
        /// <summary>
        /// 路由处理
        ///     应该由Timer线程调用,可能会嵌套
        ///     再此方法中调用的方法应保证线程安全
        /// </summary>
        /// <param name="isu">数据接口</param>
        /// <param name="sugt">定时器,用于堵塞</param>
        public void RouteProcess(ISrcUrl isu, SrcUrlGroupTimer sugt)
        {
            //加载配置
            if(isu.IAW is ICacheConfig)
            {
                ICacheConfig icc = isu.IAW as ICacheConfig;
                if (!icc.IsSrcUrlEnabled(isu.Tag))
                {
                    return;
                }
            }

            //双向确认是否使用参数
            if (isu.UseParam && isu is ISrcUrlParam)
            {
                this.GetProcess(isu as ISrcUrlParam, sugt);
            }
            else
            {
                this.GetProcess(isu, sugt);
            }
        }
Example #41
0
        /// <summary>
        /// 合并
        ///     仅定时线程调用
        /// </summary>
        /// <param name="node"></param>
        public void Concat(RetryNode node)
        {
            thisLock.EnterWriteLock();
            try
            {
                this.isu = node.isu;
                this.ap = node.ap;
                this.starttime = DateTime.Now;
                this.endtime = DateTime.Now;
                this.count = 1;

                //将NAME_DATA计数保留,其他清空
                int i = 0;
                if (this.counts.ContainsKey(NAME_DATA))
                {
                    i = this.counts[NAME_DATA];
                }
                this.counts.Clear();
                this.counts.Add(NAME_DATA, i);
                this.counts = this.counts.Concat(node.counts).ToDictionary(x => x.Key, y => y.Value);
                AddNameCount(NAME_DATA);
            }
            finally
            {
                thisLock.ExitWriteLock();
            }
        }
Example #42
0
 public bool Save(ISrcUrl isu, AqiParam param, byte[] data)
 {
     throw new NotImplementedException();
 }