Esempio n. 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;
            }
        }
Esempio n. 2
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();
            }
        }