예제 #1
0
        public void NotifySystem_SemaphoreNeighbor()
        {
            var connectedRoute = ObservingFunc <IRoute, IRoute> .FromExpression(route =>
                                                                                (from sensor1 in route.DefinedBy
                                                                                 from te1 in sensor1.Elements
                                                                                 from te2 in te1.ConnectsTo
                                                                                 where te2.Sensor != null && te2.Sensor.Parent != route
                                                                                 select te2.Sensor.Parent as IRoute).Where(r => r != null).FirstOrDefault());


            var func = CreateExpression(from route1 in RailwayContainer.Invalids.OfType <Route>().Concat(RailwayContainer.Routes)
                                        let route2 = connectedRoute.Evaluate(route1)
                                                     where route2 != null && route2.Entry != route1.Exit
                                                     select new { Route1 = route1, Route2 = route2 });

            var first       = func.FirstOrDefault();
            var incremental = func.AsNotifiable();
            var changed     = false;

            incremental.CollectionChanged += (o, e) =>
            {
                changed = true;
                Assert.AreEqual(NotifyCollectionChangedAction.Remove, e.Action);
                Assert.AreEqual(1, e.OldItems.Count);
                Assert.AreEqual(first, e.OldItems[0]);
            };

            Assert.IsFalse(changed);
            Assert.AreEqual(func.Count(), incremental.Count());

            first.Route2.Entry = first.Route1.Exit;

            Assert.IsTrue(changed);
            Assert.AreEqual(func.Count(), incremental.Count());
        }
예제 #2
0
        public void MarkInstantiatingFor(SynchronizationRuleBase synchronizationRule, Expression <Func <TLeft, bool> > leftPredicate = null, Expression <Func <TRight, bool> > rightPredicate = null)
        {
            if (synchronizationRule == null)
            {
                throw new ArgumentNullException("synchronizationRule");
            }

            if (!synchronizationRule.LeftType.IsAssignableFrom(typeof(TLeft)))
            {
                throw new ArgumentException("The left types do not conform. The left type of the current rule must be an assignable of the given synchronization rules left type.", "synchronizationRule");
            }
            if (!synchronizationRule.RightType.IsAssignableFrom(typeof(TRight)))
            {
                throw new ArgumentException("The right types do not conform. The right type of the current rule must be an assignable of the given synchronization rules right type.", "synchronizationRule");
            }
            leftPredicate  = SimplifyPredicate(leftPredicate);
            rightPredicate = SimplifyPredicate(rightPredicate);

            ObservingFunc <TLeft, bool> leftFunc = ObservingFunc <TLeft, bool> .FromExpression(leftPredicate);

            ObservingFunc <TRight, bool> rightFunc = ObservingFunc <TRight, bool> .FromExpression(rightPredicate);

            if (leftFunc != null)
            {
                LeftToRight.MarkInstantiatingFor(synchronizationRule.LTR, leftFunc.Evaluate);
                SynchronizationJobs.Add(new LeftInstantiationMonitorJob <TLeft, TRight>(leftFunc));
            }
            else
            {
                LeftToRight.MarkInstantiatingFor(synchronizationRule.LTR);
            }
            if (rightFunc != null)
            {
                RightToLeft.MarkInstantiatingFor(synchronizationRule.RTL, rightFunc.Evaluate);
                SynchronizationJobs.Add(new RightInstantiationMonitorJob <TLeft, TRight>(rightFunc));
            }
            else
            {
                RightToLeft.MarkInstantiatingFor(synchronizationRule.RTL);
            }
        }
예제 #3
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));
        }