Exemplo n.º 1
0
        public OneWaySynchronizationMultipleDependency(TransformationRuleBase <TSource, TTarget> parentRule, TransformationRuleBase <TSourceDep, TTargetDep> childRule, Expression <Func <TSource, IEnumerableExpression <TSourceDep> > > leftSelector, Expression <Func <TTarget, ICollection <TTargetDep> > > rightSelector)
        {
            if (parentRule == null)
            {
                throw new ArgumentNullException("parentRule");
            }
            if (childRule == null)
            {
                throw new ArgumentNullException("childRule");
            }
            if (leftSelector == null)
            {
                throw new ArgumentNullException("leftSelector");
            }
            if (rightSelector == null)
            {
                throw new ArgumentNullException("rightSelector");
            }

            this.parentRule = parentRule;
            this.childRule  = childRule;

            this.__sourceGetter = ExpressionCompileRewriter.Compile(leftSelector);
            this.__targetGetter = ExpressionCompileRewriter.Compile(rightSelector);
        }
        public MockComputation Add <TOut>(TransformationRuleBase <TOut> transformationRule, object[] input, TOut output)
            where TOut : class
        {
            var c = new MockComputation(input, transformationRule, CreateComputationContext(), output);

            Add(c);
            return(c);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a dependency to generate the code for the base classes of the current class
 /// </summary>
 /// <typeparam name="TClass">The model element type from which to generate the base class</typeparam>
 /// <param name="rule">The transformation rule that is used to generate the class</param>
 /// <param name="selector">A function used to select the model element from which to generate a base class</param>
 /// <returns>The transformation rule dependency</returns>
 public ITransformationRuleDependency RequireBaseClass <TClass>(TransformationRuleBase <TClass, CodeTypeDeclaration> rule, Func <T, TClass> selector)
     where TClass : class
 {
     return(Require(rule, selector, (cl, baseClass) =>
     {
         var typeRef = CodeDomHelper.GetOrCreateUserItem <CodeTypeReference>(baseClass, CodeDomHelper.TypeReferenceKey, () => new CodeTypeReference());
         cl.BaseTypes.Add(typeRef);
     }));
 }
Exemplo n.º 4
0
 public MissingItemInconsistency(ISynchronizationContext context, TransformationRuleBase <TSource, TTarget> rule, ICollection <TSource> sourceCollection, ICollection <TTarget> targetCollection, TSource source, bool isLeftMissing)
 {
     this.Context          = context;
     this.Rule             = rule;
     this.SourceCollection = sourceCollection;
     this.TargetCollection = targetCollection;
     this.Source           = source;
     this.IsLeftMissing    = isLeftMissing;
 }
        public MockComputation Add <TIn1, TIn2, TOut>(TransformationRuleBase <TIn1, TIn2, TOut> transformationRule, TIn1 input1, TIn2 input2, TOut output)
            where TIn1 : class
            where TIn2 : class
            where TOut : class
        {
            var c = new MockComputation(new object[] { input1, input2 }, transformationRule, CreateComputationContext(), output);

            Add(c);
            return(c);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a dependency that the given subsequent model elements are transformed to types
 /// </summary>
 /// <typeparam name="TType">The model elements input type</typeparam>
 /// <param name="rule">The transformation rule used to generate the types</param>
 /// <param name="selector">A function that selects the subsequent model elements</param>
 /// <returns>The created transformation rule dependency</returns>
 public ITransformationRuleDependency RequireTypes <TType>(TransformationRuleBase <TType, CodeTypeDeclaration> rule, Func <T, IEnumerable <TType> > selector)
     where TType : class
 {
     return(RequireMany(rule, selector, (ns, types) =>
     {
         foreach (var decl in types)
         {
             AddType(ns, decl);
         }
     }));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a new TransformationRuleSource instance for the given transformation rule in the given context
        /// </summary>
        /// <param name="rule">The transformation rule that should be used as source</param>
        /// <param name="context">The context in which the computations should be used by the current instance</param>
        public TransformationRuleSource(TransformationRuleBase <TIn, TOut> rule, ITransformationContext context)
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            TransformationRule = rule;
            Context            = context;

            rule.Dependencies.Add(this);
            foreach (var c in context.Trace.TraceAllIn(rule).OfType <Computation>())
            {
                items.Add(new TransformationComputationWrapper <TIn, TOut>(c));
            }
        }
        /// <summary>
        /// Creates a new computation source from a transformation rule
        /// </summary>
        /// <typeparam name="TInput">The type of the input arguments for the transformation rule</typeparam>
        /// <typeparam name="TOutput">The output type of the transformation rule</typeparam>
        /// <param name="rule">The rule that should be taken as a source of computation objects</param>
        /// <returns>A source of computations that can further be dealt with</returns>
        public static Func <ITransformationContext, INotifyEnumerable <TransformationComputationWrapper <TInput, TOutput> > > ToComputationSource <TInput, TOutput>(this TransformationRuleBase <TInput, TOutput> rule)
            where TInput : class
            where TOutput : class
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }

            return(context => rule.ToComputationSource(context));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a dependency to generate events from given subsequent model elements
 /// </summary>
 /// <typeparam name="TEvent">The model element type from which to generate events</typeparam>
 /// <param name="rule">The transformation rule to generate events</param>
 /// <param name="selector">The selector function that selects the model elements from which to generate events</param>
 /// <returns>The transformation rule dependency</returns>
 public ITransformationRuleDependency RequireEvents <TEvent>(TransformationRuleBase <TEvent, CodeMemberEvent> rule, Func <T, IEnumerable <TEvent> > selector)
     where TEvent : class
 {
     return(RequireMany(rule, selector, (cl, events) => cl.DependentMembers(true).AddRange(events)));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates a dependency to generate an event from a given subsequent model element
 /// </summary>
 /// <typeparam name="TEvent">The model element type from which to generate an event</typeparam>
 /// <param name="rule">The transformation rule that is used to generate the event</param>
 /// <param name="selector">The selector function that selects the model element from which to generate an event</param>
 /// <returns>The transformation rule dependency</returns>
 public ITransformationRuleDependency RequireEvent <TEvent>(TransformationRuleBase <TEvent, CodeMemberEvent> rule, Func <T, TEvent> selector)
     where TEvent : class
 {
     return(Require(rule, selector, (cl, ev) => cl.DependentMembers(true).Add(ev)));
 }
 public SynchronizationComputation(TransformationRuleBase <TIn, TOut> rule, TransformationRuleBase <TOut, TIn> reverseRule, IComputationContext context, TIn input)
     : base(rule, context)
 {
     Opposite = new OppositeComputation(this, reverseRule);
     Input    = input;
 }
        public static INotifyEnumerable <TransformationComputationWrapper <TInput, TOutput> > ToComputationSource <TInput, TOutput>(this TransformationRuleBase <TInput, TOutput> rule, ITransformationContext context, Func <TransformationComputationWrapper <TInput, TOutput>, bool> filter)
            where TInput : class
            where TOutput : class
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }

            return(new TransformationRuleSource <TInput, TOutput>(rule, context)
            {
                Filter = filter
            });
        }
Exemplo n.º 13
0
 /// <summary>
 /// Creates a dependency to generate a property from a given subsequent model element
 /// </summary>
 /// <typeparam name="TProp">The model element type from which to generate a property</typeparam>
 /// <param name="rule">The property generator</param>
 /// <param name="selector">The selector function that selects the model element from which to generate the property</param>
 /// <returns>The transformation rule dependency</returns>
 public ITransformationRuleDependency RequireGenerateProperty <TProp>(TransformationRuleBase <TProp, CodeMemberProperty> rule, Func <T, TProp> selector)
     where TProp : class
 {
     return(Require(rule, selector, persistor: (cl, prop) => cl.DependentMembers(true).Add(prop)));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Creates a dependency that the given subsequent model element is transformed to a type
 /// </summary>
 /// <typeparam name="TType">The model element of the input type</typeparam>
 /// <param name="rule">The transformation rule used to generate the type</param>
 /// <param name="selector">A function selecting the correct subsequent model element</param>
 /// <returns>The created transformation rule dependency</returns>
 public ITransformationRuleDependency RequireType <TType>(TransformationRuleBase <TType, CodeTypeDeclaration> rule, Func <T, TType> selector)
     where TType : class
 {
     return(Require(rule, selector, AddType));
 }
        /// <summary>
        /// Creates a new computation source from a transformation rule
        /// </summary>
        /// <typeparam name="TInput1">The type of the first input arguments for the transformation rule</typeparam>
        /// <typeparam name="TInput2">The type of the second input arguments for the transformation rule</typeparam>
        /// <typeparam name="TOutput">The output type of the transformation rule</typeparam>
        /// <param name="rule">The rule that should be taken as a source of computation objects</param>
        /// <param name="allowNull">A boolean value indicating whether null values should be allowed</param>
        /// <param name="filter">A method or lambda expression to filter the computation objects</param>
        /// <returns>A source of computations that can further be dealt with</returns>
        public static Func <ITransformationContext, INotifyEnumerable <TransformationComputationWrapper <TInput1, TInput2, TOutput> > > ToComputationSource <TInput1, TInput2, TOutput>(this TransformationRuleBase <TInput1, TInput2, TOutput> rule, bool allowNull, Func <TransformationComputationWrapper <TInput1, TInput2, TOutput>, bool> filter)
            where TInput1 : class
            where TInput2 : class
            where TOutput : class
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }

            return(context => rule.ToComputationSource(context, allowNull, filter));
        }
        public static INotifyEnumerable <TransformationComputationWrapper <TInput, TOutput> > ToComputationSource <TInput, TOutput>(this TransformationRuleBase <TInput, TOutput> rule, ITransformationContext context, bool allowNull)
            where TInput : class
            where TOutput : class
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }

            var trs = new TransformationRuleSource <TInput, TOutput>(rule, context);

            if (allowNull)
            {
                trs.AddNullItem();
            }
            return(trs);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Creates a dependency to generate properties from subsequent model elements
 /// </summary>
 /// <typeparam name="TProp">The model element type from which to generate a property</typeparam>
 /// <param name="rule">The transformation rule for the property generation rule</param>
 /// <param name="selector">The selector function to select the subsequent model elements</param>
 /// <returns>The created transformation rule dependency</returns>
 public ITransformationRuleDependency RequireGenerateProperties <TProp>(TransformationRuleBase <TProp, CodeMemberProperty> rule, Func <T, IEnumerable <TProp> > selector)
     where TProp : class
 {
     return(RequireMany(rule, selector, persistor: (cl, props) => cl.DependentMembers(true).AddRange(props)));
 }
 public OppositeComputation(SynchronizationComputation <TIn, TOut> opposite, TransformationRuleBase <TOut, TIn> rule)
     : base(rule, opposite)
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// Cregates a dependency to generate a method from a given subsequent model element
 /// </summary>
 /// <typeparam name="TMeth">The model element type from which to generate a method</typeparam>
 /// <param name="rule">The method generator</param>
 /// <param name="selector">The selector function that selects the model element from which to generate the method</param>
 /// <returns>The transformation rule dependency</returns>
 public ITransformationRuleDependency RequireGenerateMethod <TMeth>(TransformationRuleBase <TMeth, CodeMemberMethod> rule, Func <T, TMeth> selector)
     where TMeth : class
 {
     return(Require(rule, selector, (cl, meth) => cl.DependentMembers(true).Add(meth)));
 }
 private SynchronizationComputation(TransformationRuleBase <TIn, TOut> rule, SynchronizationComputation <TOut, TIn> opposite)
     : base(rule, opposite.Context)
 {
     Opposite = opposite;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Creates a dependency to generate methods from subsequent model elements
 /// </summary>
 /// <typeparam name="TMeth">The model elements type from which to generate methods</typeparam>
 /// <param name="rule">The method generator</param>
 /// <param name="selector">The selector function that selects the model elements from which to generate the methods</param>
 /// <returns>The transformation rule dependency</returns>
 public ITransformationRuleDependency RequireGenerateMethods <TMeth>(TransformationRuleBase <TMeth, CodeMemberMethod> rule, Func <T, IEnumerable <TMeth> > selector)
     where TMeth : class
 {
     return(RequireMany(rule, selector, (cl, methods) => cl.DependentMembers(true).AddRange(methods)));
 }