public static TOut Transform <TIn, TOut>(TIn input, ITransformationEngineContext context, TransformationRuleBase <TIn, TOut> startRule) where TIn : class where TOut : class { if (context == null) { throw new ArgumentNullException("context"); } var transformation = context.Transformation; if (!transformation.IsInitialized) { transformation.Initialize(); } if (startRule == null) { startRule = context.Transformation.GetRuleForTypeSignature(new Type[] { typeof(TIn) }, typeof(TOut)) as TransformationRuleBase <TIn, TOut>; } else { if (startRule.Transformation != context.Transformation) { ThrowRuleNotPartOfTransformation(); } } return(TransformationRunner.Transform(new object[] { input }, null, startRule, context).Output as TOut); }
/// <summary> /// Transforms the input arguments into an output using the provided transformation /// </summary> /// <typeparam name="TIn1">The type of the first input argument</typeparam> /// <typeparam name="TIn2">The type of the second input argument</typeparam> /// <typeparam name="TOut">The desired output type</typeparam> /// <param name="input1">The first input parameter</param> /// <param name="input2">The second input parameter</param> /// <param name="context">The context that should be used (must not be null)</param> /// <returns>The output from the transformation</returns> public static TOut Transform <TIn1, TIn2, TOut>(TIn1 input1, TIn2 input2, ITransformationEngineContext context) where TIn1 : class where TIn2 : class where TOut : class { return(Transform <TIn1, TIn2, TOut>(input1, input2, context, null)); }
public static void Process <TIn1, TIn2>(TIn1 input1, TIn2 input2, ITransformationEngineContext context, GeneralTransformationRule <TIn1, TIn2> startRule) where TIn1 : class where TIn2 : class { if (context == null) { throw new ArgumentNullException("context"); } var transformation = context.Transformation; if (!transformation.IsInitialized) { transformation.Initialize(); } if (startRule == null) { startRule = context.Transformation.GetRulesForInputTypes(new Type[] { typeof(TIn1), typeof(TIn2) }).FirstOrDefault() as GeneralTransformationRule <TIn1, TIn2>; } else { if (startRule.Transformation != context.Transformation) { ThrowRuleNotPartOfTransformation(); } } TransformationRunner.Transform(new object[] { input1, input2 }, null, startRule, context); }
public static void ProcessMany <TIn>(IEnumerable <TIn> inputs, ITransformationEngineContext context, GeneralTransformationRule <TIn> startRule) where TIn : class { if (context == null) { throw new ArgumentNullException("context"); } var transformation = context.Transformation; if (!transformation.IsInitialized) { transformation.Initialize(); } if (startRule == null) { startRule = context.Transformation.GetRulesForInputTypes(new Type[] { typeof(TIn) }).FirstOrDefault() as GeneralTransformationRule <TIn>; } else { if (startRule.Transformation != context.Transformation) { ThrowRuleNotPartOfTransformation(); } } TransformationRunner.TransformMany(inputs.Select(item => new object[] { item }), null, startRule, context); }
/// <summary> /// Transforms the input argument into an output using the provided transformation /// </summary> /// <typeparam name="TOut">The desired output type</typeparam> /// <param name="input">The input parameter</param> /// <param name="startRule">The rule that should be started with. If this is null, an applicable rule is found.</param> /// <param name="context">The context that should be used (must not be null).</param> /// <returns>The output from the transformation</returns> public static TOut Transform <TOut>(object[] input, ITransformationEngineContext context, GeneralTransformationRule startRule) where TOut : class { if (context == null) { throw new ArgumentNullException("context"); } if (input == null) { throw new ArgumentNullException("input"); } var transformation = context.Transformation; if (!transformation.IsInitialized) { transformation.Initialize(); } if (startRule == null) { startRule = context.Transformation.GetRuleForTypeSignature(input.GetTypes(), typeof(TOut)); } else { if (startRule.Transformation != context.Transformation) { ThrowRuleNotPartOfTransformation(); } CheckTransformationRule <TOut>(input, startRule); } return(TransformationRunner.Transform(input, null, startRule, context).Output as TOut); }
public void Initialize() { ruleT1 = new TestRuleT1(); ruleT2 = new TestRuleT2(); voidT1 = new VoidTestRuleT1(); voidT2 = new VoidTestRuleT2(); transformation = new MockTransformation(ruleT1, ruleT2, voidT1, voidT2); context = new TransformationContext(transformation); }
/// <summary> /// Transforms the input argument into an output using the provided transformation /// </summary> /// <param name="inputs">The input arguments as an array. This must not be null. The correct amount of parameters depends on the rule to start with.</param> /// <param name="inputContext">The context object in which the transformation is run</param> /// <param name="startRule">The start rule to begin with (must not be null)</param> /// <param name="context">The transformation context (must not be null)</param> /// <returns>The transformation computations</returns> public static IEnumerable<Computation> TransformMany(IEnumerable<object[]> inputs, IEnumerable inputContext, GeneralTransformationRule startRule, ITransformationEngineContext context) { if (context == null) throw new ArgumentNullException("context"); if (inputs == null) throw new ArgumentNullException("inputs"); if (startRule == null) throw new InvalidOperationException("Could not find transaction rule to start with."); if (!context.Transformation.IsInitialized) throw new InvalidOperationException("Could not initialize transformation"); var patternObjects = new List<ITransformationPatternContext>(); foreach (var pattern in context.Transformation.Patterns) { var obj = pattern.CreatePattern(context); if (obj != null) patternObjects.Add(obj); } var list = new List<Computation>(); foreach (var input in inputs) { var comp = context.CallTransformation(startRule, input, inputContext); list.Add(comp); if (!comp.IsDelayed) { context.Outputs.Add(comp.Output); } else { comp.OutputInitialized += (o,e) => context.Outputs.Add(comp.Output); } } context.ExecutePending(); foreach (var pattern in patternObjects) { pattern.Begin(); context.ExecutePending(); } foreach (var pattern in patternObjects) { pattern.Finish(); } return list; }
/// <summary> /// Transforms the input argument into an output using the provided transformation /// </summary> /// <typeparam name="TIn">The type of the input argument</typeparam> /// <typeparam name="TOut">The desired output type</typeparam> /// <param name="inputs">The input parameters</param> /// <param name="context">The context that should be used (must not be null).</param> /// <returns>The output from the transformation</returns> public static IEnumerable <TOut> TransformMany <TIn, TOut>(IEnumerable <TIn> inputs, ITransformationEngineContext context) where TIn : class where TOut : class { return(TransformMany <TIn, TOut>(inputs, context, null)); }
/// <summary> /// Transforms the input argument into an output using the provided transformation /// </summary> /// <typeparam name="TOut">The desired output type</typeparam> /// <param name="inputs">The input parameters</param> /// <param name="types">The types of the elements within the collection refered to in the inputs parameter</param> /// <param name="context">The context that should be used (must not be null).</param> /// <returns>The output from the transformation</returns> public static IEnumerable <TOut> TransformMany <TOut>(IEnumerable <object[]> inputs, Type[] types, ITransformationEngineContext context) where TOut : class { return(TransformMany <TOut>(inputs, types, context, null)); }
/// <summary> /// Transforms the input argument into an output using the provided transformation /// </summary> /// <param name="inputs">The input arguments as an array. This must not be null. The correct amount of parameters depends on the rule to start with.</param> /// <param name="inputContext">The context object in which the transformation is run</param> /// <param name="startRule">The start rule to begin with (must not be null)</param> /// <param name="context">The transformation context (must not be null)</param> /// <returns>The transformation computations</returns> public static IEnumerable <Computation> TransformMany(IEnumerable <object[]> inputs, IEnumerable inputContext, GeneralTransformationRule startRule, ITransformationEngineContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (inputs == null) { throw new ArgumentNullException("inputs"); } if (startRule == null) { throw new InvalidOperationException("Could not find transaction rule to start with."); } if (!context.Transformation.IsInitialized) { throw new InvalidOperationException("Could not initialize transformation"); } var patternObjects = new List <ITransformationPatternContext>(); foreach (var pattern in context.Transformation.Patterns) { var obj = pattern.CreatePattern(context); if (obj != null) { patternObjects.Add(obj); } } var list = new List <Computation>(); foreach (var input in inputs) { var comp = context.CallTransformation(startRule, input, inputContext); list.Add(comp); if (!comp.IsDelayed) { context.Outputs.Add(comp.Output); } else { comp.OutputInitialized += (o, e) => context.Outputs.Add(comp.Output); } } context.ExecutePending(); foreach (var pattern in patternObjects) { pattern.Begin(); context.ExecutePending(); } foreach (var pattern in patternObjects) { pattern.Finish(); } return(list); }
/// <summary> /// Processes the input argument using the provided transformation /// </summary> /// <typeparam name="TIn">The type of the input argument</typeparam> /// <param name="inputs">The input parameters</param> /// <param name="context">The context that should be used (must not be null)</param> public static void ProcessMany <TIn>(IEnumerable <TIn> inputs, ITransformationEngineContext context) where TIn : class { ProcessMany <TIn>(inputs, context, null); }
/// <summary> /// Processes the input argument using the provided transformation /// </summary> /// <typeparam name="TIn">The type of the input argument</typeparam> /// <param name="input">The input parameter</param> /// <param name="context">The context that should be used (must not be null)</param> public static void Process <TIn>(TIn input, ITransformationEngineContext context) where TIn : class { Process <TIn>(input, context, null); }
public static IEnumerable <TOut> TransformMany <TIn, TOut>(IEnumerable <TIn> inputs, ITransformationEngineContext context, TransformationRuleBase <TIn, TOut> startRule) where TIn : class where TOut : class { if (context == null) { throw new ArgumentNullException("context"); } var transformation = context.Transformation; if (!transformation.IsInitialized) { transformation.Initialize(); } if (startRule == null) { startRule = context.Transformation.GetRuleForTypeSignature(new Type[] { typeof(TIn) }, typeof(TOut)) as TransformationRuleBase <TIn, TOut>; } else { if (startRule.Transformation != context.Transformation) { ThrowRuleNotPartOfTransformation(); } } return(TransformationRunner.TransformMany(inputs.Select(item => new object[] { item }), null, startRule, context).Select(c => c.Output).OfType <TOut>()); }
/// <summary> /// Transforms the input argument into an output using the provided transformation /// </summary> /// <typeparam name="TOut">The desired output type</typeparam> /// <param name="input">The input parameter</param> /// <param name="context">The context that should be used (must not be null).</param> /// <returns>The output from the transformation</returns> public static TOut Transform <TOut>(object[] input, ITransformationEngineContext context) where TOut : class { return(Transform <TOut>(input, context, null)); }
/// <summary> /// Processes the input arguments using the provided transformation /// </summary> /// <typeparam name="TIn1">The type of the first input argument</typeparam> /// <typeparam name="TIn2">The type of the second input argument</typeparam> /// <param name="input1">The first input parameter</param> /// <param name="input2">The second input parameter</param> /// <param name="context">The context that should be used (must not be null).</param> public static void Process <TIn1, TIn2>(TIn1 input1, TIn2 input2, ITransformationEngineContext context) where TIn1 : class where TIn2 : class { Process(input1, input2, context, null); }
/// <summary> /// Transforms the input argument into an output using the provided transformation /// </summary> /// <typeparam name="TIn">The type of the input argument</typeparam> /// <typeparam name="TOut">The desired output type</typeparam> /// <param name="input">The input parameter</param> /// <param name="context">The context that should be used (must not be null).</param> /// <returns>The output from the transformation</returns> public static TOut Transform <TIn, TOut>(TIn input, ITransformationEngineContext context) where TIn : class where TOut : class { return(Transform <TIn, TOut>(input, context, null)); }
/// <summary> /// Processes the input arguments using the provided transformation /// </summary> /// <typeparam name="TIn1">The type of the first input argument</typeparam> /// <typeparam name="TIn2">The type of the second input argument</typeparam> /// <param name="inputs">The input parameters</param> /// <param name="context">The context that should be used (must not be null).</param> public static void ProcessMany <TIn1, TIn2>(IEnumerable <Tuple <TIn1, TIn2> > inputs, ITransformationEngineContext context) where TIn1 : class where TIn2 : class { ProcessMany(inputs, context, null as GeneralTransformationRule <TIn1, TIn2>); }