/// <summary> /// Find the converter based on its configuration mapping. /// </summary> /// <param name="dataPointKey">The data point to convert</param> /// <param name="targetConverter">The converter's config</param> /// <param name="converters">A list of configured converters</param> /// <returns>The converter if found, otherwise null.</returns> public IConverter MatchTargetConverter(string dataPointKey, SourceTargetConverter targetConverter, List <IConverter> converters) { IConverter converter = null; foreach (var c in converters) { if (c.Id.Equals(targetConverter.Id)) { if (targetConverter.InLeftSideMap) { // Check if the property is in the left side mapping foreach (var key in c.LeftSideMap.Keys) { if (key.Equals(dataPointKey)) { converter = c; break; } } if (converter != null) { break; } } else { converter = c; break; } } } return(converter); }
/// <summary> /// Pipe the data based on two rules. /// 1. pipeData=true, piped in data is lost. /// 2. pipeData=false, piped in data is combined with the output. /// </summary> /// <param name="config">The config for this converter.</param> /// <param name="convertedDataPointsIn">The input</param> /// <param name="convertedDataPointsOut">The output</param> /// <returns>The output based on the piping rules.</returns> public Dictionary <string, object> CombineData(SourceTargetConverter config, Dictionary <string, object> convertedDataPointsIn, Dictionary <string, object> convertedDataPointsOut) { var convertedDataPoints = new Dictionary <string, object>(); if (!config.CombineInputOutput) { // Add only the output, input is thrown away. convertedDataPoints = convertedDataPointsOut; } else { if (convertedDataPointsIn != null) { // Add both input and output foreach (var p in convertedDataPointsIn) { if (!config.InputFilter.ContainsKey(p.Key) || config.InputFilter[p.Key].Equals("allow")) { if (!convertedDataPoints.ContainsKey(p.Key)) { convertedDataPoints.Add(p.Key, p.Value); } } } } if (convertedDataPointsOut != null) { foreach (var p in convertedDataPointsOut) { if (!convertedDataPoints.ContainsKey(p.Key)) { convertedDataPoints.Add(p.Key, p.Value); } else { // Output wins convertedDataPoints[p.Key] = p.Value; } } } } return(convertedDataPoints); }