Exemplo n.º 1
0
        /// <summary>
        /// 上报车载历史数据
        /// </summary>
        /// <param name="carHdList"></param>
        private bool UploadCarHdList(List <TbccCarAiData> carHdList)
        {
            bool flag = false;

            try
            {
                List <WRUpload.Model_NodeHistoryData> uploadList = new List <WRUpload.Model_NodeHistoryData>();
                List <int> carHdIdList = new List <int>();
                int        index       = 0;
                foreach (TbccCarAiData item in carHdList)
                {
                    index++;
                    carHdIdList.Add(item.Id);
                    Type t = item.GetType();
                    foreach (AiInfoModel aiInfo in FrmMain._relationList.Where(l => l.LinkProjectNo == _ProjectNo && l.LinkNetId == _NetId))
                    {
                        bool isLastAi = aiInfo == FrmMain._relationList.Where(l => l.LinkProjectNo == _ProjectNo && l.LinkNetId == _NetId).Last();
                        WRUpload.Model_NodeHistoryData rdm = new WRUpload.Model_NodeHistoryData();
                        rdm.DataTimek__BackingField = item.UpdateTime;//.ToString("yyyy-MM-dd HH:mm:ss");
                        rdm.PointIdk__BackingField  = aiInfo.aiNumber;
                        if (aiInfo.LinkPortNo < 5)
                        {
                            rdm.Datak__BackingField = Convert.ToDecimal(t.InvokeMember("AI" + aiInfo.LinkPortNo, System.Reflection.BindingFlags.GetProperty, null, item, null));
                        }
                        else if (aiInfo.LinkPortNo == 5)
                        {
                            rdm.Datak__BackingField = item.Longitude;
                        }
                        else if (aiInfo.LinkPortNo == 6)
                        {
                            rdm.Datak__BackingField = item.Latitude;
                        }

                        rdm.IsAlarmk__BackingField = item.AlarmStatus == 2 ? WRUpload.Enum_HdAlarm.Normal : WRUpload.Enum_HdAlarm.Alarm;
                        uploadList.Add(rdm);
                        //超过50条或者是剩余数据 则开始上报
                        if (uploadList.Count >= 50 || (index == carHdList.Count && isLastAi))
                        {
                            int  retryCount      = -1;
                            bool isUploadSuccess = false;
                            while (retryCount < 3)
                            {
                                retryCount++;
                                WRUpload.ResultModelOfboolean result = FrmMain._uploadClient.UploadCarHistDatas(uploadList.ToArray());
                                if (result.Code == 0)
                                {
                                    _LastUploadTime = item.UpdateTime;
                                    uploadList.Clear();
                                    isUploadSuccess = true;
                                    break;
                                }
                                else
                                {
                                    Thread.Sleep(_Inteval);
                                }
                            }
                            if (isUploadSuccess == false)
                            {
                                throw new Exception(string.Format("重复三次均上报失败[ProjectId={0}] [车载]", _ProjectNo));
                            }
                        }
                    }
                }
                UpdateUploadState(carHdIdList);
                flag = true;
            }
            catch (Exception ex)
            {
                FrmMain._MainForm.AppendLogText(string.Format("上报失败[ProjectId={0}] [车载]:{1}", _ProjectNo, ex.Message));
            }
            return(flag);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 上报仓库历史数据
        /// </summary>
        /// <param name="refHdList"></param>
        /// <returns></returns>
        private bool UploadRefHdList(List <TbccRefAiData> refHdList)
        {
            bool flag = false;

            try
            {
                List <WRUpload.Model_NodeHistoryData> uploadList = new List <WRUpload.Model_NodeHistoryData>();
                int index = 0;
                foreach (TbccRefAiData item in refHdList)
                {
                    index++;
                    Type t            = item.GetType();
                    bool isAlarmSpace = ((TimeSpan)(item.hDate - DateTime.Parse("1970-1-1"))).TotalSeconds % FrmMain._nSpace != 0;
                    foreach (AiInfoModel aiInfo in FrmMain._relationList.Where(l => l.LinkProjectNo == _ProjectNo && l.LinkNetId == _NetId))
                    {
                        bool isLastAi = aiInfo == FrmMain._relationList.Where(l => l.LinkProjectNo == _ProjectNo && l.LinkNetId == _NetId).Last();
                        if (isAlarmSpace)
                        {
                            //如果是报警间隔的数据,判断当前Ai所在的库是否报警
                            int alarmState = Convert.ToInt32(t.InvokeMember("Ref" + aiInfo.LinkRefId.ToString() + "_RefAlarmState", System.Reflection.BindingFlags.GetProperty, null, item, null));
                            if (alarmState == 2)//如果当前库的报警状态正常则跳过此条数据
                            {
                                continue;
                            }
                        }
                        WRUpload.Model_NodeHistoryData rdm = new WRUpload.Model_NodeHistoryData();
                        rdm.Datak__BackingField = Convert.ToDecimal(t.InvokeMember("AI" + aiInfo.LinkPortNo, System.Reflection.BindingFlags.GetProperty, null, item, null));
                        if (rdm.Datak__BackingField == -200)
                        {
                            continue;
                        }
                        rdm.DataTimek__BackingField = item.hDate;//.ToString("yyyy-MM-dd HH:mm:ss");
                        rdm.PointIdk__BackingField  = aiInfo.aiNumber;
                        rdm.IsAlarmk__BackingField  = isAlarmSpace ? WRUpload.Enum_HdAlarm.Alarm : WRUpload.Enum_HdAlarm.Normal;
                        uploadList.Add(rdm);
                        //超过50条或者是剩余数据 则开始上报
                        if (uploadList.Count >= 50 || (index == refHdList.Count && isLastAi))
                        {
                            int  retryCount      = -1;
                            bool isUploadSuccess = false;
                            while (retryCount < 3)
                            {
                                retryCount++;
                                WRUpload.ResultModelOfboolean result = FrmMain._uploadClient.UploadRefHistDatas(uploadList.ToArray());
                                if (result.Code == 0)
                                {
                                    _LastUploadTime = item.hDate;
                                    uploadList.Clear();
                                    isUploadSuccess = true;
                                    break;
                                }
                                else
                                {
                                    Thread.Sleep(_Inteval);
                                }
                            }
                            if (isUploadSuccess == false)
                            {
                                throw new Exception(string.Format("重复三次均上报失败[ProjectId={0}] [NetId={1}]", _ProjectNo, _NetId));
                            }
                        }
                    }
                }
                flag = true;
            }
            catch (Exception ex)
            {
                FrmMain._MainForm.AppendLogText(string.Format("上报失败[ProjectId={0}] [NetId={1}]:{2}", _ProjectNo, _NetId, ex.Message));
            }
            return(flag);
        }