Exemple #1
0
        public void InitTestContext()
        {
            ruleT1 = new TestRuleT1();
            ruleT2 = new TestRuleT2();
            ruleTN = new TestRuleTN();

            ruleDependent = new OtherRuleT1();
            transformation = new MockTransformation(ruleT1, ruleT2, ruleTN, ruleDependent);
            transformation.Initialize();
            context = CreateContext(transformation);
            trace = context.Trace;

            c_a = context.CallTransformation(ruleT1, new object[] { "a" });
            c_b = context.CallTransformation(ruleT1, new object[] { "b" });
            c_ab = context.CallTransformation(ruleT2, new object[] { "a", "b" });
            c_bc = context.CallTransformation(ruleT2, new object[] { "b", "c" });
            c_abc = context.CallTransformation(ruleTN, new object[] { "a", "b", "c" });
            c_bcd = context.CallTransformation(ruleTN, new object[] { "b", "c", "d" });

            c_a.InitializeOutput("b");
            c_b.InitializeOutput(null);
            c_ab.InitializeOutput("c");
            c_bc.InitializeOutput(null);
            c_abc.InitializeOutput("d");
            c_bcd.InitializeOutput(null);
        }
Exemple #2
0
        public void InitTestContext()
        {
            ruleT1 = new TestRuleT1();
            ruleT2 = new TestRuleT2();
            ruleTN = new TestRuleTN();

            ruleDependent  = new OtherRuleT1();
            transformation = new MockTransformation(ruleT1, ruleT2, ruleTN, ruleDependent);
            transformation.Initialize();
            context = CreateContext(transformation);
            trace   = context.Trace;

            c_a   = context.CallTransformation(ruleT1, new object[] { "a" });
            c_b   = context.CallTransformation(ruleT1, new object[] { "b" });
            c_ab  = context.CallTransformation(ruleT2, new object[] { "a", "b" });
            c_bc  = context.CallTransformation(ruleT2, new object[] { "b", "c" });
            c_abc = context.CallTransformation(ruleTN, new object[] { "a", "b", "c" });
            c_bcd = context.CallTransformation(ruleTN, new object[] { "b", "c", "d" });

            c_a.InitializeOutput("b");
            c_b.InitializeOutput(null);
            c_ab.InitializeOutput("c");
            c_bc.InitializeOutput(null);
            c_abc.InitializeOutput("d");
            c_bcd.InitializeOutput(null);
        }
Exemple #3
0
 public static IEnumerable <TOut> FindWhere <TIn1, TIn2, TOut>(this ITransformationTrace trace, Predicate <TOut> filter)
     where TIn1 : class
     where TIn2 : class
     where TOut : class
 {
     return(FindWhere <TOut>(trace, new Type[] { typeof(TIn1), typeof(TIn2) }, filter));
 }
Exemple #4
0
        private void AssertSimilar(FSM.FiniteStateMachine fsm, PN.PetriNet pn, ITransformationTrace trace)
        {
            Assert.AreEqual(fsm.ID, pn.ID, "The ID of the petri net is not set correctly");
            Assert.AreEqual(fsm.States.Count, pn.Places.Count, "The number of places is incorrect");
            Assert.AreEqual(fsm.Transitions.Count + fsm.States.Where(s => s.IsEndState).Count(), pn.Transitions.Count,
                            "The number of transitions is incorrect");

            foreach (var state in fsm.States)
            {
                var place = trace.Resolve <FSM.State, PN.Place>(state);

                Assert.IsNotNull(place, "A state has not been transformed");
                Assert.AreEqual(state.Name, place.ID, "The name of a place has not been set correctly");
                Assert.IsTrue(pn.Places.Contains(place), "A corresponding place has not been added to the states of the Petri net");

                if (state.IsStartState)
                {
                    Assert.AreEqual(1, place.TokenCount, "The number of tokens has not been set");
                }
                else
                {
                    Assert.AreEqual(0, place.TokenCount, "The number of tokens has not been set");
                }

                foreach (var t in state.Transitions)
                {
                    var t2 = trace.Resolve <FSM.Transition, PN.Transition>(t);

                    Assert.IsNotNull(t2, "A transition has not been transformed");
                    Assert.IsTrue(pn.Transitions.Contains(t2), "A transition has not been added to the transitions of the Petri net");
                }
            }
        }
Exemple #5
0
        private void AssertSimilar(FSM.FiniteStateMachine fsm, PN.PetriNet pn, ITransformationTrace trace)
        {
            Assert.AreEqual(fsm.ID, pn.ID, "The ID of the petri net is not set correctly");
            Assert.AreEqual(fsm.States.Count, pn.Places.Count, "The number of places is incorrect");
            Assert.AreEqual(fsm.Transitions.Count + fsm.States.Where(s => s.IsEndState).Count(), pn.Transitions.Count,
                "The number of transitions is incorrect");

            foreach (var state in fsm.States)
            {
                var place = trace.Resolve<FSM.State, PN.Place>(state);

                Assert.IsNotNull(place, "A state has not been transformed");
                Assert.AreEqual(state.Name, place.ID, "The name of a place has not been set correctly");
                Assert.IsTrue(pn.Places.Contains(place), "A corresponding place has not been added to the states of the Petri net");

                if (state.IsStartState)
                {
                    Assert.AreEqual(1, place.TokenCount, "The number of tokens has not been set");
                }
                else
                {
                    Assert.AreEqual(0, place.TokenCount, "The number of tokens has not been set");
                }

                foreach (var t in state.Transitions)
                {
                    var t2 = trace.Resolve<FSM.Transition, PN.Transition>(t);

                    Assert.IsNotNull(t2, "A transition has not been transformed");
                    Assert.IsTrue(pn.Transitions.Contains(t2), "A transition has not been added to the transitions of the Petri net");
                }
            }
        }
 /// <summary>
 /// Creates a new transformation context for the given transformation
 /// </summary>
 /// <param name="transformation">The transformation, a context should be generated for</param>
 public TransformationContext(Transformation transformation)
 {
     if (transformation == null)
     {
         throw new ArgumentNullException("transformation");
     }
     Transformation = transformation;
     trace          = new TransformationContextTrace(this);
 }
Exemple #7
0
        public static IEnumerable <TOut> FindAllIn <TOut>(this ITransformationTrace trace, TransformationRuleBase <TOut> rule) where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(trace.TraceAllIn(rule).Select(c => c.Output as TOut));
        }
Exemple #8
0
        /// <summary>
        /// Finds all outputs of computations of from the specified source type to the specified target type that match the given filter
        /// </summary>
        /// <param name="trace">The trace component that is used as basis</param>
        /// <typeparam name="TOut">The output type of the transformation rule</typeparam>
        /// <param name="filter">The filter that should be applied to the transformation outputs</param>
        /// <param name="inputTypes">The input types for the transformation rule</param>
        /// <returns>A collection with all suitable outputs</returns>
        public static IEnumerable <TOut> FindWhere <TOut>(this ITransformationTrace trace, Type[] inputTypes, Predicate <TOut> filter)
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(trace.TraceAll(inputTypes, typeof(TOut)).Select(c => c.Output as TOut).Where(o => filter == null || filter(o)));
        }
Exemple #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)));
        }
Exemple #10
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="TOut">The output that is returned by the transformation rule</typeparam>
        /// <returns>All outputs of computations</returns>
        /// <param name="inputTypes">The input types of the trace request</param>
        public static IEnumerable <TOut> FindAll <TOut>(this ITransformationTrace trace, Type[] inputTypes)
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(from Computation c in trace.TraceAll(inputTypes, typeof(TOut))
                   select c.Output as TOut);
        }
Exemple #11
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>
        /// <param name="rule">The transformation rule that was used to transform the outputs</param>
        /// <param name="filter">The filter that should filter the inputs</param>
        /// <returns>All outputs of computations with suitable input arguments or null, if there are none</returns>
        public static IEnumerable <object> ResolveInWhere(this ITransformationTrace trace, GeneralTransformationRule rule, Predicate <ITraceEntry> filter)
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(from ITraceEntry c in trace.TraceAllIn(rule)
                   where filter == null || filter(c)
                   select c.Output);
        }
Exemple #12
0
        /// <summary>
        /// Trace the output of the computation that transformed the given input with the given transformation type
        /// </summary>
        /// <param name="rule">The rule that transformed the argument</param>
        /// <param name="input">The input arguments</param>
        /// <param name="trace">The trace component that is used as basis</param>
        /// <returns>The output of the computation with the specified input argument or null, if there is none such</returns>
        public static object ResolveIn(this ITransformationTrace trace, GeneralTransformationRule rule, object[] input)
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

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

            return(comp != null ? comp.Output : null);
        }
Exemple #13
0
        public static IEnumerable <TOut> FindAll <TIn, TOut>(this ITransformationTrace trace)
            where TOut : class
            where TIn : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(trace.TraceAll(new Type[] { typeof(TIn) }, typeof(TOut)).Select(c => c.Output as TOut));
        }
Exemple #14
0
        public static IEnumerable <ITraceEntry> TraceInWhere <TIn>(this ITransformationTrace trace, GeneralTransformationRule <TIn> rule, Predicate <TIn> filter) where TIn : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(from ITraceEntry c in trace.TraceAllIn(rule)
                   where filter == null || filter(c.GetInput(0) as TIn)
                   select c);
        }
Exemple #15
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);
        }
Exemple #16
0
        public static IEnumerable <TOut> ResolveMany <TIn, TOut>(this ITransformationTrace trace, TIn input)
            where TIn : class
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(from ITraceEntry c in trace.Trace(input)
                   select c.Output as TOut);
        }
Exemple #17
0
        public static IEnumerable <TOut> ResolveWhere <TOut>(this ITransformationTrace trace, Type[] inputTypes, Predicate <object[]> filter)
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(from ITraceEntry c in trace.TraceAll(inputTypes, typeof(TOut))
                   where filter == null || filter(c.CreateInputArray())
                   select c.Output as TOut);
        }
Exemple #18
0
        public static TOut Resolve <TIn, TOut>(this ITransformationTrace trace, TIn input)
            where TIn : class
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            var comp = trace.Trace(input).FirstOrDefault();

            return(comp != null ? comp.Output as TOut : null);
        }
Exemple #19
0
        public static IEnumerable <TOut> ResolveWhere <TIn, TOut>(this ITransformationTrace trace, Predicate <TIn> filter)
            where TIn : class
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            return(from ITraceEntry c in trace.TraceAll(new Type[] { typeof(TIn) }, typeof(TOut))
                   where filter == null || filter(c.GetInput(0) as TIn)
                   select c.Output as TOut);
        }
Exemple #20
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);
        }
Exemple #21
0
        public static TOut Resolve <TIn1, TIn2, TOut>(this ITransformationTrace trace, TIn1 input1, TIn2 input2)
            where TIn1 : class
            where TIn2 : class
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            var outputType = typeof(TOut);
            var comp       = trace.Trace(input1, input2).FirstOrDefault(c => c.TransformationRule.OutputType == outputType);

            return(comp != null ? comp.Output as TOut : null);
        }
Exemple #22
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>
        /// <param name="filter">The filter that should filter the inputs</param>
        /// <returns>All outputs of computations with suitable input arguments or null, if there are none</returns>
        public static IEnumerable <TOut> ResolveWhere <TIn1, TIn2, TOut>(this ITransformationTrace trace, Func <TIn1, TIn2, bool> filter)
            where TIn1 : class
            where TIn2 : class
            where TOut : class
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            Type[] types = { typeof(TIn1), typeof(TIn2) };
            return(from Computation c in trace.TraceAll(types, typeof(TOut))
                   where (filter == null || filter(c.GetInput(0) as TIn1, c.GetInput(1) as TIn2))
                   select c.Output as TOut);
        }
Exemple #23
0
        public static IEnumerable <TOut> ResolveMany <TIn, TOut>(this ITransformationTrace trace, 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.TraceMany(new Type[] { typeof(TIn) }, typeof(TOut), list.Select(input => new object[] { input }))
                   select c.Output as TOut);
        }
 /// <summary>
 /// Creates a new transformation context for the given transformation
 /// </summary>
 /// <param name="transformation">The transformation, a context should be generated for</param>
 public ParallelTransformationContext(Transformation transformation)
 {
     if (transformation == null) throw new ArgumentNullException("transformation");
     Transformation = transformation;
     trace = new TransformationContextTrace(this);
 }
Exemple #25
0
 /// <summary>
 /// Trace the output of the computation that transformed any input that matches the filter into the desired 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>
 /// <typeparam name="TOut">The desired output type</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> ResolveMany <TIn, TOut>(this ITransformationTrace trace, params TIn[] list)
     where TIn : class
     where TOut : class
 {
     return(ResolveMany <TIn, TOut>(trace, list as IEnumerable <TIn>));
 }