Beispiel #1
0
        /// <summary>
        /// 推送数据
        /// </summary>
        void StartPushing()
        {
            String SendJsonStr = "";
            String recvJsonStr = "";

            try
            {
                int i = 0;
                while (IsPushing)
                {
                    if (PushingDataTabQueue.Count > 0) //&& IndexTable.Rows.Count > 0
                    {
                        DataTable dt       = new DataTable();
                        DataTable dt_orgin = new DataTable();
                        if (PushingDataTabQueue.TryDequeue(out dt))
                        {
                            //表号+仪器,断句
                            String        RecordName = dt.TableName;
                            String        RecordNo   = RecordName.Split('-')[0];
                            List <String> curvenames = new List <string>();
                            if (TitleDict.TryGetValue(RecordName, out curvenames))
                            {
                                dt_orgin = dt.Copy();
                                int Size = dt.Rows.Count;
                                //移除rowid 列
                                dt.Columns.RemoveAt(0);
                                SendJsonStr = InitCurveTable(Logid, RecordNo, Size, Instname.ToLower(), curvenames, dt);
                                recvJsonStr = _realdbws.WriteCurveData(SendJsonStr);
                                //计数
                                if (recvJsonStr.Contains("ok"))
                                {
                                    //各表累计发送记录数
                                    //SendSumDic[RecordNo] += Size;
                                    string status = ">>>" + i++.ToString("D4") + "Date:" +
                                                    DateTime.Now.ToShortDateString() + "..Time:" + DateTime.Now.ToLongTimeString() +
                                                    "..TabNo:" + RecordNo + "..Records:" + Size + "<<<";
                                    SendStatusQ.Enqueue(status);
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.Message + "<======PushingThread线程主体StartPushing()异常=====> \r\n");
                //this.realdbservices_Status = false;
                //切入网络状态监控线程。
                //GetHttpStatusTimer.Start(true);
                //IsPushing = false;
            }
        }
Beispiel #2
0
 /// <summary>
 /// 获取即将推送的数据
 /// </summary>
 public void getData(SQLiteDBHelper helper, List <String> selecttablist, String instru, String beginDate, String beginTime, String endDate, String endTime)
 {
     try
     {
         foreach (String tabname in selecttablist)
         {
             PushingDataTabQueue.Enqueue(helper.getPushingData(instru, tabname, beginDate, beginTime, endDate, endTime));
         }
     }
     catch (System.Exception ex)
     {
         Debug.WriteLine(ex.Message + "\r\t==========" + "pusher.getDataSQLiteDBHelper helper,List<String> selecttablist,String instru,String beginDate,String beginTime,String endDate,String endTime)");
     }
 }
Beispiel #3
0
        /// <summary>
        /// 静态推送数据进入队列
        /// </summary>
        /// <param name="helper">SQLitehelper</param>
        /// <param name="selecttablist">推送的表名列</param>
        /// <param name="instru">仪器</param>
        /// <param name="_fps">单词推送表数量</param>
        /// <returns>是否推送完毕</returns>
        public void getData(SQLiteDBHelper helper, List <String> selecttablist, String instru, int _fps)
        {
            IsSynPush = false;
            try
            {
                //锁定入队操作,加互斥锁
                //MTX = new Mutex(true, "ReaddingDB",out canReadDB);

                foreach (String tabname in selecttablist)
                {
                    int       rowidstart = 0;
                    int       rowidend   = 0;
                    DataTable dt         = new DataTable();
                    //起始rowid
                    int _startindex = LastSentRowIDDic[tabname];
                    //截至rowid
                    int _endindex = LastInsertRowIDDic[tabname];
                    //入队条件
                    while (_startindex >= 0 && _endindex >= 0 && _startindex + _fps <= _endindex)
                    {
                        lock (sqliteLockObj)
                        {
                            dt = helper.getPushingData(instru, tabname, _startindex, _fps, out rowidstart, out rowidend).Copy();
                        }
                        _startindex += _fps;
                        //if (PushingDataTabQueue.Count >= 100)
                        //    PushingQueueFull = true;
                        //else
                        PushingDataTabQueue.Enqueue(dt);
                        IsSynPush = true;
                        if (_endindex - _startindex < _fps)
                        {
                            SynchroData(helper, selectedTabList, Instname);
                            break;
                        }
                    }
                }
                //完成入队操作,释放互斥锁
                //MTX.ReleaseMutex();
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.Message + "\r\t==========" + "pusher.getData(SQLiteDBHelper helper, List<String> selecttablist, String instru,int _fps)");
            }
        }
Beispiel #4
0
 /// <summary>
 /// 将实时数据放入待推送队列中
 /// </summary>
 /// <param name="helper"></param>
 /// <param name="selecttablist"></param>
 /// <param name="instru"></param>
 public void SynchroData(SQLiteDBHelper helper, List <String> selecttablist, String instru)
 {
     try
     {
         ////锁定入队操作,加互斥锁
         //MTX = new Mutex(true, "ReaddingDB", out canReadDB);
         int rowid = 0;
         foreach (String tabname in selecttablist)
         {
             DataTable dt = new DataTable();
             //起始rowid
             int _startindex = LastSentRowIDDic[tabname];
             //截至rowid
             int _endindex = LastInsertRowIDDic[tabname];
             if (_endindex > _startindex)
             {
                 lock (sqliteLockObj)
                 {
                     dt = helper.getPushingData(instru, tabname, LastSentRowIDDic[tabname], out rowid);
                 }
             }
             if (rowid > 0)
             {
                 LastInsertRowIDDic[tabname] = rowid;
                 if (dt.Rows.Count > 0)
                 {
                     //if (PushingDataTabQueue.Count >= 100)
                     //    PushingQueueFull = true;
                     //else
                     PushingDataTabQueue.Enqueue(dt);
                 }
                 //完成入队后  startindex赋值为最新rowid
                 LastSentRowIDDic[tabname] = rowid;
             }
         }
         IsSynPush = false;
         ////完成入队操作,释放互斥锁
         //MTX.ReleaseMutex();
     }
     catch (System.Exception ex)
     {
         Debug.WriteLine(ex.Message + "\r\t==========" + "pusher.getDataSQLiteDBHelper helper,List<String> selecttablist,String instru,String beginDate,String beginTime,String endDate,String endTime)");
     }
 }
Beispiel #5
0
        /// <summary>
        /// 获取即将推送的数据
        /// </summary>
        /// <returns>缓存是否读取完</returns>
        public bool getData(SQLiteDBHelper helper, List <String> selecttablist, String instru, int _fps)
        {
            bool isOver = false;

            try
            {
                foreach (String tabname in selecttablist)
                {
                    int       rowidstart  = 0;
                    int       rowidend    = 0;
                    DataTable dt          = new DataTable();
                    int       _startindex = getLastIndex(tabname, IndexTable);
                    if (_startindex >= 0)
                    {
                        dt = helper.getPushingData(instru, tabname, _startindex, _fps, out rowidstart, out rowidend).Copy();
                        String strDate = dt.Rows[dt.Rows.Count - 1].ItemArray[5].ToString();
                        String strTime = dt.Rows[dt.Rows.Count - 1].ItemArray[6].ToString();
                        PushingDataTabQueue.Enqueue(dt);
                        DataRow dr = IndexTable.NewRow();
                        dr[0] = tabname;
                        dr[1] = strDate;
                        dr[2] = strTime;
                        //起始rowid
                        dr[3] = rowidstart;
                        //截至rowid
                        dr[4] = rowidend;
                        IndexTable.Rows.Add(dr);
                    }
                    if ((rowidend - rowidstart + 1) < _fps)
                    {
                        isOver = true;
                        continue;
                    }
                }
                return(isOver);
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.Message + "\r\t==========" + "pusher.getData(SQLiteDBHelper helper, List<String> selecttablist, String instru,int _fps)");
                return(false);
            }
        }
Beispiel #6
0
 /// <summary>
 /// 获取即将推送的数据(指定时间)
 /// </summary>
 public void getData(SQLiteDBHelper helper, List <String> selecttablist, String instru, String beginDate, String beginTime, String endDate, String endTime)
 {
     try
     {
         lock (sqliteLockObj)
         {
             foreach (String tabname in selecttablist)
             {
                 DataTable dt = new DataTable();
                 dt = helper.getPushingData(instru, tabname, beginDate, beginTime, endDate, endTime);
                 //if (PushingDataTabQueue.Count >= 100)
                 //    PushingQueueFull = true;
                 //else
                 PushingDataTabQueue.Enqueue(dt);
             }
         }
     }
     catch (System.Exception ex)
     {
         Debug.WriteLine(ex.Message + "\r\t==========" + "pusher.getDataSQLiteDBHelper helper,List<String> selecttablist,String instru,String beginDate,String beginTime,String endDate,String endTime)");
     }
 }
Beispiel #7
0
        /// <summary>
        /// 推送数据
        /// </summary>
        void StartPushing()
        {
            String SendJsonStr = "";
            String recvJsonStr = "";

            try
            {
                int i = 0;
                while (true)
                {
                    if (PushingDataTabQueue.Count > 0)
                    {
                        DataTable dt       = new DataTable();
                        DataTable dt_orgin = new DataTable();
                        if (PushingDataTabQueue.TryDequeue(out dt))
                        {
                            //表号+仪器,断句
                            String        RecordName = dt.TableName;
                            String        RecordNo   = RecordName.Split('-')[0];
                            List <String> curvenames = new List <string>();
                            if (TitleDict.TryGetValue(RecordName, out curvenames))
                            {
                                dt_orgin = dt.Copy();
                                int Size  = dt.Rows.Count;
                                int rowid = int.Parse(dt.Rows[dt.Rows.Count - 1].ItemArray[0].ToString());
                                //移除rowid 列
                                dt.Columns.RemoveAt(0);
                                SendJsonStr = InitCurveTable(Logid, RecordNo, Size, Instname.ToLower(), curvenames, dt);
                                if (this.Ping("10.242.0.186"))
                                {
                                    recvJsonStr = _realdbws.WriteCurveData(SendJsonStr);
                                    //计数
                                    if (recvJsonStr.Contains("ok"))                                    //各表累计发送记录数
                                                                                                       //SendSumDic[RecordNo] += Size;
                                    {
                                        //各表推送数据的最后一条记录rowid
                                        lastSentRowIDDic[RecordNo] = rowid;
                                        string status = ">>>" + i++.ToString("D4") + "Date:" +
                                                        DateTime.Now.ToShortDateString() + "..Time:" + DateTime.Now.ToLongTimeString() +
                                                        "..TabNo:" + RecordNo + "..Records:" + rowid + "<<<";
                                        SendStatusQ.Enqueue(status);
                                    }
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    Thread.Sleep(50);
                }
            }
            catch (System.Exception ex)
            {
                Trace.WriteLine(ex.Message + "<======StartPushing()异常=====> \r\n");
                PushingDataTabQueue = new ConcurrentQueue <DataTable>();
                PushingThread.Abort();
                PushingThread.Start();
            }
        }