Exemple #1
0
        private void Collect(List <PandaPumpJZ> pandaJZs, ref List <PumpJZ> jzs)
        {
            if (pandaJZs == null)
            {
                return;
            }
            if (jzs == null)
            {
                return;
            }

            foreach (PumpJZ jz in jzs)
            {
                int errorTimes = 0; // 三个离线就认为该机组离线了
                foreach (Point point in jz.points)
                {
                    // 防止采集的点多了,错误消息炸了,每个都报出来了---直接让机组离线
                    if (errorTimes >= 3)
                    {
                        TraceManagerForWeb.AppendErrMsg(jz._PumpName + jz._PumpJZName + "三个条目采集失败,已跳过该机组采集,请检查点表和数据源");
                        jz.IsOnline = false;
                        break;
                    }

                    // 检查未通过
                    if (!point.CheckPumpWeb(out string err))
                    {
                        point.MakeFail(jz._PumpName + jz._PumpJZName + point.name + err);
                        TraceManagerForWeb.AppendErrMsg(jz._PumpName + jz._PumpJZName + point.name + err);
                        errorTimes++;
                        continue;
                    }

                    // 拿到数据源
                    PandaPumpJZ[] curPandaPumpJZs = pandaJZs.Where(p => p.ID.ToUpper() == jz._PandaPumpJZID.ToUpper()).ToArray();// 注意转换大写在比较
                    if (curPandaPumpJZs.Length == 0)
                    {
                        point.MakeFail("未在WEB数据源中找到机组实时信息,机组编码:" + jz._PandaPumpJZID);
                        TraceManagerForWeb.AppendErrMsg("未在WEB数据源中找到机组实时信息,机组编码:" + jz._PandaPumpJZID);
                        errorTimes++;
                        continue;
                    }
                    object pointDataSource;
                    string tempTime     = DataUtil.ToDateString(DateTime.Now);
                    bool   tempTimeFlag = false;
                    try
                    {
                        PandaPumpJZ curPandaPumpJZ = curPandaPumpJZs[0];

                        // 获取在线状态-防止点表没有配置在线状态
                        Type         typeOnLine         = curPandaPumpJZ.GetType();          //获取类型
                        PropertyInfo propertyInfoOnLine = typeOnLine.GetProperty("FOnLine"); //获取采集时间的属性
                        object       curOnLine          = propertyInfoOnLine.GetValue(curPandaPumpJZ, null);
                        if (curOnLine != null && DataUtil.ToInt(curOnLine) == 1)
                        {
                            jz.IsOnline = true;
                        }

                        // 先拿到时间
                        Type         typeTempTime         = curPandaPumpJZ.GetType();             //获取类型
                        PropertyInfo propertyInfoTempTime = typeTempTime.GetProperty("TempTime"); //获取采集时间的属性
                        object       curTempTime          = propertyInfoTempTime.GetValue(curPandaPumpJZ, null);
                        if (curTempTime != null && !string.IsNullOrWhiteSpace(curTempTime.ToString()))
                        {
                            tempTime     = DataUtil.ToDateString(curTempTime); //获取采集时间属性值
                            tempTimeFlag = true;
                        }

                        // 在拿到值
                        Type type = curPandaPumpJZ.GetType();                                                    //获取类型
                        System.Reflection.PropertyInfo propertyInfo = type.GetProperty(point.dataSourceAddress); //获取指定名称的属性
                        pointDataSource = propertyInfo.GetValue(curPandaPumpJZ, null);                           //获取属性值
                    }
                    catch (Exception e)
                    {
                        string er = string.Format("{0}-{1}-{2}采集失败,错误的原因:{3}", jz._PumpName, jz._PumpJZName, point.name, e.Message);
                        point.MakeFail(er);
                        TraceManagerForWeb.AppendErrMsg(er);
                        errorTimes++;
                        continue;
                    }
                    // 根据数据源获取数据
                    point.ReadWEBPoint(pointDataSource);
                    if (point.State == ValueState.Fail)
                    {
                        string er = string.Format("{0}-{1}-{2}采集失败,取值错误:{3}", jz._PumpName, jz._PumpJZName, point.name, point.Mess);
                        TraceManagerForWeb.AppendErrMsg(er);
                        errorTimes++;
                        continue;
                    }

                    // 判断采集时间是否正常
                    if (!tempTimeFlag)
                    {
                        jz.IsOnline = false;
                    }
                }
            }
        }
        private void Collect(List <PandaPumpJZ> pandaJZs, ref Dictionary <int, Station> dicStations)
        {
            if (pandaJZs == null)
            {
                return;
            }
            if (dicStations == null)
            {
                return;
            }

            foreach (int key in dicStations.Keys)
            {
                Station station    = dicStations[key];
                int     errorTimes = 0; // 三个离线就认为其离线了
                string  sensorIDs  = "";
                foreach (Sensor sensor in dicStations[key].sensors)
                {
                    // 防止采集的点多了,错误消息炸了,每个都报出来了---直接让其离线
                    if (errorTimes >= 3)
                    {
                        TraceManagerForWeb.AppendWarning("StationName:" + station._Name + "sensorID三个条目:" + sensorIDs + "采集失败,已跳过该站点采集,请检查点表和数据源");
                        dicStations[key].IsOnline = false;
                        break;
                    }

                    // 检查未通过
                    if (!sensor.CheckScadaWeb(out string err))
                    {
                        sensor.MakeFail(sensor.sensorName + err);
                        TraceManagerForWeb.AppendWarning("StationName:" + station._Name + "SensorName" + sensor.sensorName + " " + err);
                        errorTimes++;
                        sensorIDs += sensor.sensorID + " ";
                        continue;
                    }

                    // 跳过忽略型
                    if (sensor.type == PointType.Ignore)
                    {
                        continue;
                    }

                    // 拿到数据源
                    PandaPumpJZ[] curJZs = pandaJZs.Where(y => y.ID.ToUpper() == station._GUID.ToUpper()).ToArray();// 注意转换大写在比较
                    if (curJZs.Length == 0)
                    {
                        sensor.MakeFail("未在WEB监测点数据源中找到配置站点信息,站点编码:" + station._GUID);
                        TraceManagerForWeb.AppendWarning("未在WEB监测点数据源中找到配置站点信息,站点编码:" + station._GUID);
                        sensorIDs += sensor.sensorID + " ";
                        errorTimes++;
                        continue;
                    }
                    object pointDataSource;
                    string tempTime     = DataUtil.ToDateString(DateTime.Now);
                    bool   tempTimeFlag = false;
                    try
                    {
                        PandaPumpJZ curJZ = curJZs[0];
                        // 获取在线状态-防止sensor表没有配置在线状态
                        Type         typeOnLine         = curJZ.GetType();                   //获取类型
                        PropertyInfo propertyInfoOnLine = typeOnLine.GetProperty("FOnLine"); //获取采集时间的属性
                        object       curOnLine          = propertyInfoOnLine.GetValue(curJZ, null);
                        if (curOnLine != null && DataUtil.ToInt(curOnLine) == 1)
                        {
                            dicStations[key].IsOnline = true;
                        }

                        // 先拿到时间
                        Type typeTempTime = curJZ.GetType();                                                        //获取类型
                        System.Reflection.PropertyInfo propertyInfoTempTime = typeTempTime.GetProperty("TempTime"); //获取采集时间的属性
                        object curTempTime = propertyInfoTempTime.GetValue(curJZ, null);
                        if (curTempTime != null && !string.IsNullOrWhiteSpace(curTempTime.ToString()))
                        {
                            tempTime     = DataUtil.ToDateString(curTempTime); //获取采集时间属性值
                            tempTimeFlag = true;
                        }
                        // 在拿到值
                        Type         type         = curJZ.GetType();                            //获取类型
                        PropertyInfo propertyInfo = type.GetProperty(sensor.dataSourceAddress); //获取指定名称的属性
                        pointDataSource = propertyInfo.GetValue(curJZ, null);                   //获取属性值
                    }
                    catch (Exception e)
                    {
                        string er = string.Format("配置站点信息:{0}找到点地址为:{1}的点,采集异常,错误原因:{2},位置:{3}" + station._Name, sensor.sensorName, e.Message, e.StackTrace);
                        sensor.MakeFail(er);
                        TraceManagerForWeb.AppendErrMsg(er);
                        sensorIDs += sensor.sensorID + " ";
                        errorTimes++;
                        continue;
                    }

                    // 根据数据源获取数据
                    sensor.ReadWEBPoint(pointDataSource);
                    sensor.LastTime = tempTime;// 使用采集时间,不要用当前时间

                    if (sensor.State == ValueState.Fail)
                    {
                        string er = string.Format("站点名称:{0},sensorName:{1},取值错误:{2}", station._Name, sensor.sensorName, sensor.Mess);
                        TraceManagerForWeb.AppendWarning(er);
                        sensorIDs += sensor.sensorID + " ";
                        errorTimes++;
                        continue;
                    }

                    // 判断采集时间是否正常
                    if (!tempTimeFlag)
                    {
                        dicStations[key].IsOnline = false;
                    }
                }
            }
        }