/// <summary> /// This function is called to calculate destination values. /// </summary> /// <param name="loadNumber">The LoadNumber.</param> /// <param name="rowNumber">The RowNumber.</param> /// <param name="row">The raw parsed row data.</param> /// <param name="methodResolvers">Method Resolver collection.</param> /// <param name="existenceObjects">Existence Objects collection.</param>" /// <param name="lookups">Lookup objects collection.<param name="">/ /// <param name="map">The map that describes how to compute this value.</param> /// <param name="values">The computed row so far.</param> /// <returns></returns> public static string ComputeDestinationValue(int loadNumber, int rowNumber, IList<string> row, IDictionary<string, IMethodResolver> methodResolvers, IDictionary<string, IExistence> existenceObjects, IDictionary<string, ILookup> lookups, ISourceValueMap map, IDictionary<string, string> values) { var destinationValue = String.Empty; // Case 1: Where there's no transformation function, and we just want to migrate // data from the source to the destination (this is by far the most common case). if (String.IsNullOrEmpty (map.Method)) { if (String.IsNullOrEmpty (map.Value) && !String.IsNullOrEmpty (map.SrcColumns)) { destinationValue = ObtainSingleValueFromSourceWithNoTransform (row, map, lookups); } else if (String.IsNullOrEmpty (map.SrcColumns)) { // Case 2: We just want to take a constant value from the feedmap, and put // it in the destination. if (String.IsNullOrEmpty(map.Value)) { destinationValue = String.Empty; // Null is not permitted. } else { destinationValue = ProcessSingleValueWithLookupsIfSpecified( map.Value.Trim(), map, lookups); } } } else { // Case 3: A Method tag exists. This means we want to call a transformation // function to compute a result. The transformation function can take 1-N // arguments, and those argument values can come out of an ILookup object, // using the source values as keys to the lookup. destinationValue = ComputeDestinationValueUsingTransform (loadNumber, rowNumber, methodResolvers, existenceObjects, lookups, row, map, values); } return destinationValue; }
/// <summary> /// This function is called when a transformation function is specified in the map for /// this computed data value. /// </summary> /// <param name="loadNum">The LoadNumber.</param> /// <param name="rowNumber">The numeric index of the row.</param> /// <param name="methodResolvers">Method Resolver collection.</param> /// <param name="existenceObjects">Existence Objects collection.</param>" /// <param name="lookups">Lookup objects collection.<param name="">/ /// <param name="row">The raw data row.</param> /// <param name="map">An ISourceValueMap that describes how to perform the calculation. /// </param> /// <param name="values">The computed row so far.</param> /// <returns>The computed destination value.</returns> public static string ComputeDestinationValueUsingTransform(int loadNum, int rowNumber, IDictionary<string, IMethodResolver> methodResolvers, IDictionary<string, IExistence> existenceObjects, IDictionary<string, ILookup> lookups, IList<string> row, ISourceValueMap map, IDictionary<string, string> values) { if (String.IsNullOrEmpty (map.MethodTag)) { throw new Exception ( String.Format ("TransformRow - have method '{0}', but no methodTag", map.Method)); } if (!methodResolvers.ContainsKey (map.MethodTag)) { throw new Exception ( String.Format ("TransformRow - method tag '{0}' for method '{1}' " + "missing from map of MethodResolvers - config error", map.MethodTag, map.Method)); } var args = ParseMethodArguments (row, map, lookups); var method = methodResolvers [map.MethodTag].ResolveTransformationMethod ( map.Method); try { return method (loadNum, lookups, existenceObjects, values, args); } catch (BadRowException) { throw; } catch (Exception ex) { throw new Exception ( String.Format ("ComputeDestinationValueUsingTransform - transformation " + "function {0} incorrectly threw an error {1} - this is a " + "fatal bug in the transformation function code", map.Method, ex.Message)); } }
/// <summary> /// This function handles the case where a single source column is migrated to the /// destination column. This is the most common case. /// </summary> /// <param name="row">The raw data row.</param> /// <param name="map">Map that describes how to process the row.</param> /// <returns>The migrated destination value.</returns> static string ObtainSingleValueFromSourceWithNoTransform(IList<string> row, ISourceValueMap map, IDictionary<string, ILookup> lookups) { int iVal; if (!int.TryParse (map.SrcColumns, out iVal)) { throw new Exception ( String.Format ("ObtainSingleValueFromSourceWithNoTransform - {0} not " + "parseable as int", map.SrcColumns)); } // single value taken from src case if (iVal >= row.Count) { throw new Exception ( String.Format ("ObtainSingleValueFromSourceWithNoTransform - feedmap for " + "destinatonRow {0} specifies srcCol {1}, but data row is only {2} cells " + "long", map.DestCol, iVal, row.Count)); } var value = row [iVal].Trim (); return ProcessSingleValueWithLookupsIfSpecified(value, map, lookups); }