private List <IConverter> CreateConverters(string key, SourceTargetMapping mapping) { var converters = new List <IConverter>(); foreach (var targetConverter in mapping.TargetConverters) { if (targetConverter.LeftSideMap != null && targetConverter.LeftSideMap.ContainsKey(key)) { var config = new ConverterConfiguration() { Id = targetConverter.Id, CombineInputOutput = targetConverter.CombineInputOutput, NestOutput = targetConverter.NestOutput, LeftSideMap = targetConverter.LeftSideMap, Properties = (targetConverter.Properties.Count > 0) ? targetConverter.Properties : mapping.Properties, PipedConverters = converters, Mapping = mapping }; IConverter converter = CollectorFactory.CloneConverter(Converters[targetConverter.Id]); if (converter != null) { converter.Configure(config); converters.Add(converter); } } } return(converters); }
/// <summary> /// Convert a single data point. /// </summary> /// <param name="dataPoint">The data point to convert</param> /// <param name="dataRow">The associated row data points</param> /// <returns>A dictionary of converted data.</returns> public Dictionary <string, object> ConvertDataPoint(KeyValuePair <string, object> dataPoint, IEntityCollection dataRowIn) { Dictionary <string, object> result = null; var mapping = FindMapping(dataPoint.Key); if (mapping != null) { // make our local copy of the data row, we may need to manipulate it for nested conversions. var dataRow = new EntityCollection(); foreach (var e in dataRowIn.Entities) { dataRow.Entities.Add(e.Key, e.Value); } var converters = new List <IConverter>(); // first configure all of the trageted converters, // this in case a piped converter wants to run the other converters internally foreach (var targetConverter in mapping.TargetConverters) { if (Converters.ContainsKey(targetConverter.Id)) { var mergedProperties = MergeProperties(Converters[targetConverter.Id].Properties, targetConverter.Properties); mergedProperties = MergeProperties(mergedProperties, mapping.Properties); var config = new ConverterConfiguration() { Id = targetConverter.Id, CombineInputOutput = targetConverter.CombineInputOutput, NestOutput = targetConverter.NestOutput, LeftSideMap = targetConverter.LeftSideMap, Properties = mergedProperties, PipedConverters = converters, Mapping = mapping }; IConverter converter = CollectorFactory.CloneConverter(Converters[targetConverter.Id]); if (converter != null) { converter.Configure(config); converters.Add(converter); } } } Dictionary <string, object> convertedDataPoints = null; foreach (var targetConverter in mapping.TargetConverters) { IConverter converter = MatchTargetConverter(dataPoint.Key, targetConverter, converters); if (converter != null) { Dictionary <string, object> convertedDataPointsOut = null; if (convertedDataPoints != null) { convertedDataPointsOut = converter.Convert(convertedDataPoints, dataRow); } else { convertedDataPointsOut = converter.Convert(dataPoint, dataRow); // If we need to combine input and output, and this is our first converter. // Otherwise the data point will be lost. if (targetConverter.CombineInputOutput) { convertedDataPoints = new Dictionary <string, object>(); convertedDataPoints.Add(dataPoint.Key, dataPoint.Value); } } convertedDataPoints = CombineData(targetConverter.CombineInputOutput, convertedDataPoints, convertedDataPointsOut); if (targetConverter.NestOutput) { convertedDataPointsOut = NestedConversion(convertedDataPoints, dataRow); convertedDataPoints = CombineData(targetConverter.CombineInputOutput, convertedDataPoints, convertedDataPointsOut); } if (!targetConverter.Pipe) { break; } } } result = convertedDataPoints; } return(result); }