Exemplo n.º 1
0
        public static TOut ResolveIn <TOut>(this ITransformationTrace trace, TransformationRuleBase <TOut> rule, object[] input)
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            var comp = trace.TraceIn(rule, input).FirstOrDefault();

            return(comp != null ? comp.Output as TOut : null);
        }
 /// <summary>
 /// Creates a new transformation computation for the given input arguments
 /// </summary>
 /// <param name="transformationRule">The transformation rule for this computation</param>
 /// <param name="context">The context of this computation</param>
 /// <param name="input">The input for this computation</param>
 protected TransformationComputation(TransformationRuleBase <TIn, TOut> transformationRule, IComputationContext context, TIn input)
     : base(transformationRule, context, input)
 {
 }
Exemplo n.º 3
0
        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>());
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new trace-only computation
 /// </summary>
 /// <param name="rule">The transformation rule used as trace group</param>
 /// <param name="input">The trace key for this transformation rule</param>
 /// <param name="output">The output for this trace entry</param>
 public TraceEntry(TransformationRuleBase <TInput, TOut> rule, TInput input, TOut output)
 {
     this.input              = input;
     this.output             = output;
     this.transformationRule = rule;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Trace the output of the computation that transformed any input that matches the filter with the given transformation type
 /// </summary>
 /// <param name="trace">The trace component that is used as basis</param>
 /// <typeparam name="TIn">The input type that is looked for</typeparam>
 /// <param name="rule">The transformation rule the object was transformed with</param>
 /// <typeparam name="TOut">The output that is returned by the transformation rule</typeparam>
 /// <param name="list">A list of allowed input arguments</param>
 /// <returns>All outputs of computations with suitable input arguments or null, if there are none</returns>
 public static IEnumerable <TOut> ResolveManyIn <TIn, TOut>(this ITransformationTrace trace, TransformationRuleBase <TIn, TOut> rule, params TIn[] list)
     where TIn : class
     where TOut : class
 {
     return(ResolveManyIn <TIn, TOut>(trace, rule, list as IEnumerable <TIn>));
 }
Exemplo n.º 7
0
        public static IEnumerable <TOut> ResolveInWhere <TIn1, TIn2, TOut>(this ITransformationTrace trace, TransformationRuleBase <TIn1, TIn2, TOut> rule, Func <TIn1, TIn2, bool> filter)
            where TIn1 : class
            where TIn2 : class
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(from ITraceEntry c in trace.TraceAllIn(rule)
                   where (filter == null || filter(c.GetInput(0) as TIn1, c.GetInput(1) as TIn2))
                   select c.Output as TOut);
        }
Exemplo n.º 8
0
        public static IEnumerable <TOut> FindAllIn <TIn1, TIn2, TOut>(this ITransformationTrace trace, TransformationRuleBase <TIn1, TIn2, TOut> rule)
            where TOut : class
            where TIn1 : class
            where TIn2 : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(trace.TraceAllIn(rule).Select(c => c.Output as TOut));
        }
Exemplo n.º 9
0
        public static IEnumerable <TOut> FindInWhere <TOut>(this ITransformationTrace trace, TransformationRuleBase <TOut> rule, Predicate <TOut> filter)
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(trace.TraceAllIn(rule).Select(c => c.Output as TOut).Where(o => filter == null || filter(o)));
        }
Exemplo n.º 10
0
        public static IEnumerable <TOut> ResolveInWhere <TOut>(this ITransformationTrace trace, TransformationRuleBase <TOut> rule, Predicate <object[]> filter)
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(from ITraceEntry c in trace.TraceAllIn(rule)
                   where filter == null || filter(c.CreateInputArray())
                   select c.Output as TOut);
        }
Exemplo n.º 11
0
        public static IEnumerable <TOut> ResolveManyIn <TIn, TOut>(this ITransformationTrace trace, TransformationRuleBase <TIn, TOut> rule, IEnumerable <TIn> list)
            where TIn : class
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }
            if (list == null)
            {
                return(Enumerable.Empty <TOut>());
            }

            return(from ITraceEntry c in trace.TraceManyIn(rule, list.Select(input => new object[] { input }))
                   select c.Output as TOut);
        }
Exemplo n.º 12
0
        public static IEnumerable <TOut> ResolveManyIn <TIn, TOut>(this ITransformationTrace trace, TransformationRuleBase <TIn, TOut> rule, TIn input)
            where TIn : class
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(from ITraceEntry c in trace.TraceIn(rule, input)
                   select c.Output as TOut);
        }