예제 #1
0
        public decimal?FindValueFromDbc(string propertyName, ExchangeProtocolEntity data, ProtocolMapConfigEnttity dbcmap)
        {
            if (dbcmap == null || dbcmap.SubItem == null || !dbcmap.SubItem.ContainsKey(propertyName))
            {
                return(null);
            }
            var config = dbcmap.SubItem[propertyName];

            return(FindValueFromDbc(data, config));
        }
예제 #2
0
        public decimal?FindValueFromDbc(ExchangeProtocolEntity data, ProtocolMapConfigEnttity config)
        {
            // 记录通道信息,方便日志打印
            var channelString = string.Empty;

            // 记录通道值信息,方便日志打印
            var channelValueString = string.Empty;

            // 记录计算公式信息,方便日志打印
            var formula = string.Empty;

            try
            {
                // 未配置
                if (config.Serial == -1)
                {
                    return(null);
                }

                //记录通道信息
                channelString = config.Serial.ToString(CultureInfo.InvariantCulture);
                // 记录计算公式信息
                formula = string.IsNullOrEmpty(config.Formula) ? "null" : config.Formula;

                // 计算结果
                var resultValues = ComputeDbcValue(config, data.VariablesData);
                if (!resultValues.Successed)
                {
                    if (!string.IsNullOrEmpty(resultValues.ErrorMessage) && ErrorEvent != null)
                    {
                        ErrorEvent(string.Format("车辆:{0},md5code:{1},DBC配置公式计算错误:{2}",
                                                 data.Vin, data.Md5Code, resultValues.ErrorMessage), data);
                    }
                    return(null);
                }

                return(resultValues.Data);
            }
            catch (Exception ex)
            {
                if (ExceptionEvent != null)
                {
                    ExceptionEvent(ex, string.Format("车辆:{0},{1} 查询DBC映射关系表异常,相关信息:通道 {2},通道值:{3},计算公式:{4}",
                                                     data.Vin, config.ItemId, channelString, channelValueString, formula), data);
                }
            }
            return(null);
        }
예제 #3
0
        public void FindValueFromDbc(string propertyName, List <string> subPropertyName, ExchangeProtocolEntity data, ProtocolMapConfigEnttity dbcmap, out List <Dictionary <string, decimal?> > valueDic)
        {
            valueDic = null;
            // 记录通道信息,方便日志打印
            var channelString = string.Empty;
            // 记录通道值信息,方便日志打印
            var channelValueString = string.Empty;
            // 记录计算公式信息,方便日志打印
            var formula = string.Empty;

            try
            {
                #region 查找父节点
                // 获取配置
                if (dbcmap == null || dbcmap.SubItem == null || !dbcmap.SubItem.ContainsKey(propertyName))
                {
                    return;
                }
                var config = dbcmap.SubItem[propertyName];
                #endregion

                #region 查找子节点
                if (config.SubItem == null || config.SubItem.Count == 0)
                {
                    return;
                }
                // 创建结果集
                valueDic = new List <Dictionary <string, decimal?> >();
                #region 循环读取子项
                foreach (var item in config.SubItem.Values)
                {
                    var dictoinary = new Dictionary <string, decimal?>();
                    foreach (var subProperty in subPropertyName)
                    {
                        decimal?value = null;
                        // 读取到子项
                        if (item.SubItem.ContainsKey(subProperty) && item.SubItem[subProperty].Serial != -1)
                        {
                            // 计算子项
                            var resultValue = ComputeDbcValue(item.SubItem[subProperty],
                                                              data.VariablesData);
                            // 子项计算失败
                            if (!resultValue.Successed)
                            {
                                if (!string.IsNullOrEmpty(resultValue.ErrorMessage) && ErrorEvent != null)
                                {
                                    ErrorEvent(string.Format("md5code:{0},协议ID:{2},父项 {1} 子项:{3} 读取失败:{4}",
                                                             data.Md5Code,
                                                             propertyName, 8, subProperty,
                                                             resultValue.ErrorMessage), data);
                                }
                            }
                            else//计算成功
                            {
                                // 子项赋值
                                value = resultValue.Data;
                            }
                        }
                        // 记录子项
                        dictoinary[subProperty] = value;
                    }
                    // 添加到结果集
                    valueDic.Add(dictoinary);
                }
                #endregion 循环读取子项


                #endregion 查找子节点
            }
            catch (Exception ex)
            {
                if (ExceptionEvent != null)
                {
                    ExceptionEvent(ex, string.Format("车辆:{0},{1} 查询DBC映射关系表异常,相关信息:通道 {2},通道值:{3},计算公式:{4}",
                                                     data.Vin, propertyName, channelString, channelValueString, formula), data);
                }
            }
        }
예제 #4
0
        public void FindValueFromDbc(string propertyName, string subPropertyName, ExchangeProtocolEntity data, ProtocolMapConfigEnttity dbcmap, out List <decimal?> valueList)
        {
            valueList = null;
            // 记录通道信息,方便日志打印
            var channelString = string.Empty;
            // 记录通道值信息,方便日志打印
            var channelValueString = string.Empty;
            // 记录计算公式信息,方便日志打印
            var formula = string.Empty;

            try
            {
                #region 查找父节点
                // 获取配置
                if (dbcmap == null || dbcmap.SubItem == null || dbcmap.SubItem.Count == 0)
                {
                    return;
                }


                #endregion

                var parentConfig = dbcmap.SubItem[propertyName];

                #region 查找子节点
                if (parentConfig.SubItem == null ||
                    parentConfig.SubItem.Count == 0)
                {
                    return;
                }
                var configData = parentConfig.SubItem.Values.Where(item => item.SubItem.ContainsKey(subPropertyName)).Select(item => item.SubItem[subPropertyName]).FirstOrDefault();
                #endregion

                #region 计算数据结果
                if (configData == null || configData.Serials == null)
                {
                    return;
                }
                //记录通道信息
                channelString = configData.Serials != null?string.Join(",", configData.Serials) : "null";

                // 记录计算公式信息
                formula = string.IsNullOrEmpty(configData.Formula) ? "null" : configData.Formula;

                var resultData = GetDbcValues(configData, data.VariablesData);

                if (!resultData.Successed)
                {
                    if (!string.IsNullOrEmpty(resultData.ErrorMessage) && ErrorEvent != null)
                    {
                        ErrorEvent(string.Format("车辆:{0},md5code:{1},协议ID:{3},获取多通道数据失败:{2}",
                                                 data.Vin, data.Md5Code, resultData.ErrorMessage, 8), data);
                    }
                    return;
                }

                valueList = resultData.Data;

                #endregion
            }
            catch (Exception ex)
            {
                if (ExceptionEvent != null)
                {
                    ExceptionEvent(ex, string.Format("车辆:{0},{1} 查询DBC映射关系表异常,相关信息:通道 {2},通道值:{3},计算公式:{4}",
                                                     data.Vin, propertyName, channelString, channelValueString, formula),
                                   data);
                }
            }
        }
예제 #5
0
 public bool CheckDbcMapParent(string propertyName, ExchangeProtocolEntity data, ProtocolMapConfigEnttity dbcmap)
 {
     return(dbcmap != null && dbcmap.SubItem != null && dbcmap.SubItem.ContainsKey(propertyName));
 }