示例#1
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);
        }
示例#2
0
 /// <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));
 }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        /// <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);
        }
示例#6
0
        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);
        }
示例#7
0
 /// <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;
 }
示例#8
0
 /// <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));
 }
示例#9
0
 /// <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));
 }
示例#10
0
        /// <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);
        }
示例#11
0
 /// <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);
 }
示例#12
0
 /// <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);
 }
示例#13
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>());
        }
示例#14
0
 /// <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));
 }
示例#15
0
 /// <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);
 }
示例#16
0
 /// <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));
 }
示例#17
0
 /// <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>);
 }