Exemple #1
0
        public static object GetConvertValue(this DeviceConfig deviceConfig, object value)
        {
            if (!deviceConfig.IsConversionEnabled)
            {
                return(value);
            }

            var v = value;

            foreach (var converter in deviceConfig.Converters)
            {
                v = converter.Convert(v);
            }

            return(v);
        }
Exemple #2
0
        public static object GetConvertBackValue(this DeviceConfig deviceConfig, object value)
        {
            if (!deviceConfig.IsConversionEnabled)
            {
                return(value);
            }

            var v = value;

            for (int i = deviceConfig.Converters.Count - 1; i >= 0; i--)
            {
                var converter = deviceConfig.ConverterCollection[i];
                v = converter.ConvertBack(v);
            }

            return(v);
        }
Exemple #3
0
 public static object ConvertBack(this object value, DeviceConfig deviceConfig)
 {
     return(GetConvertBackValue(deviceConfig, value));
 }
        private DeviceGroupConfig GetDeviceGroupConfig(DeviceDefSchema deviceDefSchema, int?generationIndex)
        {
            DeviceGroupConfig top = GetTopNode(deviceDefSchema);

            DeviceGroupConfigExtensions.TraverseFromTopLeft(
                top,
                (n, p) =>
            {
                //var deviceDefs = deviceDefSchema.DeviceDefs.Where(x => x.OffsetDefs.Last().GroupName == n.Name);
                if (!_deviceDefsDic.ContainsKey(n.Name))
                {
                    return;
                }

                var deviceDefs = _deviceDefsDic[n.Name];
                foreach (var deviceDef in deviceDefs)
                {
                    var offsetE = _deviceOffsetsDic[deviceDef];
                    offsetE.MoveNext();
                    var offset = offsetE.Current;

                    var tagIndex = deviceDef.TagIndexPosition + n.GlobalIndex + offset;
                    var path     = deviceDef.Path;
                    string tag;

                    if (generationIndex == null)
                    {
                        if (deviceDef.IsArray)
                        {
                            tag = PathFactory.CreateArrayPath(path, tagIndex);
                        }
                        else
                        {
                            tag = PathFactory.Create(path,
                                                     tagIndex,
                                                     deviceDef.TagIndexLength);
                        }
                    }
                    else
                    {
                        if (deviceDef.IsArray)
                        {
                            tag = PathFactory.CreateArrayPath(path, tagIndex, generationIndex.Value);
                        }
                        else
                        {
                            tag = PathFactory.Create(path,
                                                     tagIndex,
                                                     deviceDef.TagIndexLength,
                                                     generationIndex.Value);
                        }
                    }

                    var deviceConfig = new DeviceConfig
                    {
                        Name     = deviceDef.Name,
                        DataType = deviceDef.DataType,
                        //Path = path,
                        TagIndex            = tagIndex,
                        Tag                 = tag,
                        IsSimulated         = deviceDef.IsSimulated,
                        IsConversionEnabled = deviceDef.IsConversionEnabled,
                        ConverterCollection = deviceDef.ConverterCollection.DeepClone(),
                    };
                    //deviceDef.ConverterCollection.ForEach(c=>deviceConfig.ConverterCollection.Add(c.DeepClone()));
                    n.DeviceConfigCollection.Add(deviceConfig);
                }
            });
            return(top);
        }