示例#1
0
        public SynchronizationMultipleDependency(SynchronizationRule <TLeft, TRight> parentRule, SynchronizationRule <TDepLeft, TDepRight> childRule, Expression <Func <TLeft, ICollectionExpression <TDepLeft> > > leftSelector, Expression <Func <TRight, ICollectionExpression <TDepRight> > > 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.__leftGetter  = ExpressionCompileRewriter.Compile(leftSelector);
            this.__rightGetter = ExpressionCompileRewriter.Compile(rightSelector);
        }
示例#2
0
        public RightToLeftRule(SynchronizationRule <TLeft, TRight> rule)
        {
            this.rule = rule;
            var createLeftOutput = rule.GetType().GetMethod("CreateLeftOutput", BindingFlags.NonPublic | BindingFlags.Instance);

            this.needDependencies = createLeftOutput.ReflectedType != typeof(SynchronizationRule <TLeft, TRight>);
        }
示例#3
0
        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);
        }
示例#4
0
        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 SynchronizationSingleDependency(SynchronizationRule <TLeft, TRight> parentRule, SynchronizationRule <TDepLeft, TDepRight> childRule, Expression <Func <TLeft, TDepLeft> > leftSelector, Expression <Func <TRight, TDepRight> > rightSelector, Action <TLeft, TDepLeft> leftSetter, Action <TRight, TDepRight> rightSetter)
        {
            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.leftGetter  = ExpressionCompileRewriter.Compile(leftSelector);
            this.rightGetter = ExpressionCompileRewriter.Compile(rightSelector);
            if (leftSetter == null)
            {
                var leftSetterExp = SetExpressionRewriter.CreateSetter(leftSelector);
                if (leftSetterExp != null)
                {
                    this.leftSetter = ExpressionCompileRewriter.Compile(leftSetterExp);
                }
                this.leftFunc = Observable.Func(leftSelector);
            }
            else
            {
                this.leftSetter = leftSetter;
                this.leftFunc   = Observable.Func(leftSelector, leftSetter);
            }
            if (rightSetter == null)
            {
                var rightSetterExp = SetExpressionRewriter.CreateSetter(rightSelector);
                if (rightSetterExp != null)
                {
                    this.rightSetter = ExpressionCompileRewriter.Compile(rightSetterExp);
                }
                this.rightFunc = Observable.Func(rightSelector);
            }
            else
            {
                this.rightSetter = rightSetter;
                this.rightFunc   = Observable.Func(rightSelector, rightSetter);
            }
        }
示例#6
0
        public void SynchronizeManyRightToLeftOnly <TDepLeft, TDepRight>(SynchronizationRule <TDepLeft, TDepRight> rule, Expression <Func <TLeft, ICollection <TDepLeft> > > leftSelector, Expression <Func <TRight, IEnumerableExpression <TDepRight> > > rightSelector)
            where TDepLeft : class
            where TDepRight : class
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }
            if (leftSelector == null)
            {
                throw new ArgumentNullException("leftSelector");
            }
            if (rightSelector == null)
            {
                throw new ArgumentNullException("rightSelector");
            }

            var dependency = new OneWaySynchronizationMultipleDependency <TRight, TLeft, TDepRight, TDepLeft>(RightToLeft, rule.RightToLeft, rightSelector, leftSelector);

            RightToLeft.Dependencies.Add(dependency);
        }
示例#7
0
        public void SynchronizeMany <TDepLeft, TDepRight>(SynchronizationRule <TDepLeft, TDepRight> rule, Expression <Func <TLeft, ICollectionExpression <TDepLeft> > > leftSelector, Expression <Func <TRight, ICollectionExpression <TDepRight> > > rightSelector)
            where TDepLeft : class
            where TDepRight : class
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }
            if (leftSelector == null)
            {
                throw new ArgumentNullException("leftSelector");
            }
            if (rightSelector == null)
            {
                throw new ArgumentNullException("rightSelector");
            }

            var dependency = new SynchronizationMultipleDependency <TLeft, TRight, TDepLeft, TDepRight>(this, rule, leftSelector, rightSelector);

            LeftToRight.Dependencies.Add(dependency.CreateLeftToRightDependency());
            RightToLeft.Dependencies.Add(dependency.CreateRightToLeftDependency());
        }
示例#8
0
        public void SynchronizeRightToLeftOnly <TDepLeft, TDepRight>(SynchronizationRule <TDepLeft, TDepRight> rule, Expression <Func <TLeft, TDepLeft> > leftSelector, Expression <Func <TRight, TDepRight> > rightSelector, Expression <Func <TRight, bool> > guard = null)
            where TDepLeft : class
            where TDepRight : class
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }
            if (leftSelector == null)
            {
                throw new ArgumentNullException("leftSelector");
            }
            if (rightSelector == null)
            {
                throw new ArgumentNullException("rightSelector");
            }

            var dependency = new SynchronizationSingleDependency <TLeft, TRight, TDepLeft, TDepRight>(this, rule, leftSelector, rightSelector);
            var guardFunc  = ObservingFunc <TRight, bool> .FromExpression(guard);

            RightToLeft.Dependencies.Add(dependency.CreateRightToLeftOnlyDependency(guardFunc));
        }
示例#9
0
 public RTLComputation(SynchronizationRule <TLeft, TRight> rule, IComputationContext context, TRight right)
     : base(rule.RightToLeft, rule.LeftToRight, context, right)
 {
 }
 public SynchronizationSingleDependency(SynchronizationRule <TLeft, TRight> parentRule, SynchronizationRule <TDepLeft, TDepRight> childRule, Expression <Func <TLeft, TDepLeft> > leftSelector, Expression <Func <TRight, TDepRight> > rightSelector)
     : this(parentRule, childRule, leftSelector, rightSelector, null, null)
 {
 }