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 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); }
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>()); }
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 ISynchronizationContext SynchronizeMany <TLeft, TRight>(SynchronizationRule <TLeft, TRight> startRule, ICollection <TLeft> lefts, ICollection <TRight> rights, SynchronizationDirection direction, ChangePropagationMode changePropagation) where TLeft : class where TRight : class { if (startRule == null) { throw new ArgumentNullException("startRule"); } var context = new SynchronizationContext(this, direction, changePropagation); switch (direction) { case SynchronizationDirection.LeftToRight: var c1 = TransformationRunner.TransformMany(lefts.Select(l => new object[] { l }), rights, startRule.LeftToRight, context); rights.Clear(); rights.AddRange(c1.Select(c => c.Output as TRight)); break; case SynchronizationDirection.RightToLeft: var c2 = TransformationRunner.TransformMany(rights.Select(r => new object[] { r }), lefts, startRule.RightToLeft, context); lefts.Clear(); lefts.AddRange(c2.Select(c => c.Output as TLeft)); break; default: throw new ArgumentOutOfRangeException("direction"); } return(context); }
public ISynchronizationContext Synchronize <TLeft, TRight>(SynchronizationRule <TLeft, TRight> startRule, ref TLeft left, ref TRight right, SynchronizationDirection direction, ChangePropagationMode changePropagation) where TLeft : class where TRight : class { if (startRule == null) { throw new ArgumentNullException("startRule"); } Initialize(); var context = new SynchronizationContext(this, direction, changePropagation); switch (direction) { case SynchronizationDirection.LeftToRight: case SynchronizationDirection.LeftToRightForced: case SynchronizationDirection.LeftWins: var c1 = TransformationRunner.Transform(new object[] { left }, right != null ? new Axiom(right) : null, startRule.LeftToRight, context); right = c1.Output as TRight; break; case SynchronizationDirection.RightToLeft: case SynchronizationDirection.RightToLeftForced: case SynchronizationDirection.RightWins: var c2 = TransformationRunner.Transform(new object[] { right }, left != null ? new Axiom(left) : null, startRule.RightToLeft, context); left = c2.Output as TLeft; break; default: throw new ArgumentOutOfRangeException("direction"); } return(context); }
public bool Load(TransformationRunner runner) { bool success = false; if (runner == null) { throw new ArgumentNullException(nameof(runner)); } try { if (AssemblyName != null) { Assembly = runner.LoadFromAssemblyName(AssemblyName); } success = true; } catch (Exception) { throw; } return(success); }
protected virtual IProcessTransformationRunner CompileAndPrepareRunner(ParsedTemplate pt, string content, ITextTemplatingEngineHost host, IProcessTransformationRunFactory runFactory, TemplateSettings settings) { TransformationRunner runner = null; bool success = false; if (pt == null) { throw new ArgumentNullException(nameof(pt)); } if (host == null) { throw new ArgumentNullException(nameof(host)); } if (runFactory == null) { throw new ArgumentNullException(nameof(runFactory)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } try { try { if (runFactory.CreateTransformationRunner() is TransformationRunner theRunner) { runner = theRunner; } } catch (Exception ex) { if (IsCriticalException(ex)) { throw; } pt.LogError(ex.ToString(), new Location(host.TemplateFile)); } if (runner != null && !runner.Errors.HasErrors) { // reference the assemblies and ensure they are path rooted settings.SetAssemblies(ProcessReferences(host, pt, settings)); if (!pt.Errors.HasErrors) { try { success = runFactory.PrepareTransformation(runner.RunnerId, pt, content, host, settings); } catch (SerializationException) { pt.LogError(VsTemplatingErrorResources.SessionHostMarshalError, new Location(host.TemplateFile)); throw; } } } } catch (Exception ex) { if (IsCriticalException(ex)) { throw; } pt.LogError(ex.ToString(), new Location(host.TemplateFile, -1, -1)); } finally { if (runner != null) { pt.Errors.AddRange(runFactory.GetErrors(runner.RunnerId)); } } return(success ? runner : null); }