示例#1
0
        /// <summary>
        /// 取得设备的实时数据列表
        /// 可以不要做防止小数覆盖,因为没有时就不会有此条数据
        /// </summary>
        /// <returns></returns>
        public void GetDeviceRunDataList()
        {
            if (ListTcpbody == null || ListTcpbody.Count==0) return;
            List<DeviceRunData> dayDatalist = new List<DeviceRunData>();
            DeviceRunData mdd = null;
            int collectorID = GetCollectorId();
            int deviceID;
            //StringBuilder sb;
            foreach (DeviceDataBase ddb in ListTcpbody)
            {
                deviceID = GetDeviceId(collectorID, ddb.deviceAddress);
                //根据历史测点数据构建设备天数据
                if (!deviceRunDataMap.ContainsKey(deviceID))
                {
                    mdd = new DeviceRunData();
                    mdd.deviceID = deviceID;
                    deviceRunDataMap[deviceID] = mdd;
                }
                else
                {
                    mdd = deviceRunDataMap[deviceID];
                }

                //旧的数据不再更新实时数据,20120714修改为 当原有时间是超前的仍然更新,这里用服务器时间判断没有考虑时差,还是有点不准确,非超前则不更新,即实时数据始终显示最新的
                if (messageHeader.TimeNow < mdd.updateTime && mdd.updateTime < DateTime.Now) continue;

                mdd.energy = 0;
                mdd.todayEnergy = 0;

                //sb = new StringBuilder();

                //原数据dic
                IDictionary<int, object> odic = getDicfromstring(mdd.rundatastr);

                //测点代码:数据#代码:数据.
                foreach (int key in ddb.realMonitorMap.Keys)
                {
                    //sb.Append("#").Append(key + ":").Append(ddb.realMonitorMap[key]);
                    if (odic.ContainsKey(key))
                    {
                        odic[key] = ddb.realMonitorMap[key];
                    }
                    else {
                        odic.Add(key, ddb.realMonitorMap[key]);
                    }
                    if (key == MonitorType.MIC_INVERTER_TOTALENERGY || key == MonitorType.MIC_INVERTER_ACENERGY)
                        mdd.energy = float.Parse(ddb.realMonitorMap[key].ToString());
                    if (key == MonitorType.MIC_INVERTER_TODAYENERGY)
                        mdd.todayEnergy = float.Parse(ddb.realMonitorMap[key].ToString());
                }

                mdd.rundatastr = convertDictoString(odic);
                mdd.updateTime = messageHeader.TimeNow;
                mdd.collectorID = collectorID;
                mdd.changed = true;

            }
        }
示例#2
0
        /// <summary>
        /// 取得设备的实时数据列表
        /// 可以不要做防止小数覆盖,因为没有时就不会有此条数据
        /// </summary>
        /// <returns></returns>
        public void GetDeviceRunDataList()
        {
            List<DeviceRunData> dayDatalist = new List<DeviceRunData>();
            DeviceRunData mdd = null;
            int collectorID = GetCollectorId();
            int deviceID;
            StringBuilder sb;
            foreach (DeviceDataBase ddb in ListTcpbody)
            {
                deviceID = GetDeviceId(collectorID, ddb.deviceAddress);
                //根据历史测点数据构建设备天数据
                if (!deviceRunDataMap.ContainsKey(deviceID))
                {
                    mdd = new DeviceRunData();
                    mdd.deviceID = deviceID;
                    deviceRunDataMap[deviceID] = mdd;
                }
                else
                {
                    mdd = deviceRunDataMap[deviceID];
                }
                //就的数据不再更新实时数据
                if (mdd.updateTime > messageHeader.TimeNow) continue;
                sb = new StringBuilder();
                //测点代码:数据#代码:数据..
                foreach (int key in ddb.realMonitorMap.Keys)
                {
                    sb.Append("#").Append(key + ":").Append(ddb.realMonitorMap[key]);
                    if (key == MonitorType.MIC_INVERTER_TOTALENERGY || key == MonitorType.MIC_INVERTER_ACENERGY)
                        mdd.energy = float.Parse(ddb.realMonitorMap[key].ToString());
                    if (key == MonitorType.MIC_INVERTER_TODAYENERGY)
                        mdd.todayEnergy = float.Parse(ddb.realMonitorMap[key].ToString());
                }

                mdd.rundatastr = sb.Length>0?sb.ToString(1,sb.Length-1):"";
                mdd.updateTime = messageHeader.TimeNow;
                mdd.collectorID = collectorID;
                mdd.changed = true;

            }
        }
 /// <summary>
 /// 判断设备对应的实时数据是否存在
 /// </summary>
 /// <param name="rundata"></param>
 /// <returns></returns>
 private bool ExistDeviceRunData(DeviceRunData rundata)
 {
     if(deviceIdList.Contains(rundata.deviceID))
         return true;
     else{
         DeviceRunData tmp = _deviceRunDataDao.Get(rundata);
         if(tmp == null)return false;
         deviceIdList.Add(tmp.deviceID);
         return true;
     }
 }
 /// <summary>
 /// 判断采集器对应的实时数据是否存在
 /// </summary>
 /// <param name="rundata"></param>
 /// <returns></returns>
 private bool ExistRunData(DeviceRunData rundata)
 {
     if (deviceIdList.Contains(rundata.deviceID))
         return true;
     else
     {
         //LogUtil.writeline("get  collector Run Data" + rundata.collectorID);
         DeviceRunData tmp = _deviceRunDataDao.Get(rundata);
         if (tmp == null) return false;
         deviceIdList.Add(tmp.deviceID);
         return true;
     }
 }
 /// <summary>
 /// 保存设备实时数据
 /// </summary>
 /// <param name="runData"></param>
 public void save(DeviceRunData runData)
 {
     if (runData == null) return;
     if (ExistRunData(runData))
     {
         _deviceRunDataDao.Update(runData);
     }
     else
     {
         _deviceRunDataDao.Insert(runData);
     }
 }