Пример #1
0
        public void Concat_ObservableSources_NoUpdateWhenDetached()
        {
            var update = false;
            var coll1 = new NotifyCollection<int>() { 1, 2, 3 };
            var coll2 = new NotifyCollection<int>() { 4, 5, 6 };

            var test = coll1.Concat(coll2);

            test.CollectionChanged += (o, e) => update = true;

            test.AssertSequence(1, 2, 3, 4, 5, 6);
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            coll1.Add(4);

            Assert.IsFalse(update);

            coll2.Add(7);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            test.AssertSequence(1, 2, 3, 4, 4, 5, 6, 7);
            update = false;

            coll1.Add(5);

            Assert.IsTrue(update);
        }
Пример #2
0
        public void TopX_Clear_CorrectResult()
        {
            INotifyCollection <Dummy <int> > collection = new NotifyCollection <Dummy <int> >();
            var top1 = new Dummy <int>(43);
            var top2 = new Dummy <int>(42);
            var top3 = new Dummy <int>(30);

            collection.Add(top1);
            collection.Add(top2);
            collection.Add(top3);
            collection.Add(new Dummy <int>(23));
            collection.Add(new Dummy <int>(6));

            var topEx = Observable.Expression(() => collection.TopX(3, d => d.Item));
            var top   = topEx.Value;

            Assert.AreEqual(top1, top[0].Key);
            Assert.AreEqual(top2, top[1].Key);
            Assert.AreEqual(top3, top[2].Key);
            Assert.AreEqual(3, top.Length);

            var changed = false;

            topEx.ValueChanged += (o, e) =>
            {
                Assert.IsNotNull(e.OldValue);
                Assert.IsNotNull(e.NewValue);
                changed = true;
            };

            collection.Clear();

            Assert.IsTrue(changed);
            Assert.AreEqual(0, topEx.Value.Length);
        }
Пример #3
0
        public void Count_ObservableSourceItemAdded_NoUpdateWhenDetached()
        {
            var update = false;
            var coll = new NotifyCollection<int>() { 1, 2, 3 };

            var test = Observable.Expression(() => coll.WithUpdates().Count());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(3, test.Value);
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(4, test.Value);
            update = true;

            coll.Add(5);

            Assert.IsTrue(update);
        }
Пример #4
0
        public void Count_ObservableSourceItemAdded_NoUpdateWhenDetached()
        {
            var update = false;
            var coll   = new NotifyCollection <int>()
            {
                1, 2, 3
            };

            var test = Observable.Expression(() => coll.WithUpdates().Count());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(3, test.Value);
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(4, test.Value);
            update = true;

            coll.Add(5);

            Assert.IsTrue(update);
        }
Пример #5
0
        public void NullableIntAverage_ObservableSource_NoUpdatesWhenDetached()
        {
            var update = false;
            var coll   = new NotifyCollection <int?>()
            {
                1, 2, 3, null
            };
            var testColl = coll.WithUpdates();

            var test = Observable.Expression(() => testColl.Average());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(2, test.Value);
            Assert.AreEqual(2, testColl.Average());
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(2.5, test.Value);
            update = false;

            coll.Add(5);

            Assert.IsTrue(update);
        }
Пример #6
0
        public void IntAverage_ObservableSource_NoUpdatesWhenDetached()
        {
            var update = false;
            var coll = new NotifyCollection<int>() { 1, 2, 3 };

            var test = Observable.Expression(() => coll.Average());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(2, test.Value);
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(2.5, test.Value);
            update = false;

            coll.Add(5);

            Assert.IsTrue(update);
        }
        static void Main()
        {
            NotifyCollection<Student> collection = new NotifyCollection<Student>();
            collection.PropertyChanged += (s, e) => { Console.WriteLine(e.PropertyName); };

            collection.Add(new Student("Pesho", 75321, 2));
            collection.Add(new Student("Gosho", 73242, 5));
        }
Пример #8
0
 private void FillPetriDishesCollection(int count)
 {
     for (var i = 0; i < count; i++)
     {
         var petriDish = CreatePetriDish();
         petriDish.GenerateInitialState();
         petriDishesCollection.Add(petriDish);
     }
 }
Пример #9
0
        static void Main(string[] args)
        {
            NotifyCollection<int> list = new NotifyCollection<int>();
               f observer = new f();
            list.CollectionChanged += f.HandleEvent;

            list.Add(5);
            list.Add(6);
            list.Add(7);
            list.Add(8);
            list.RemoveAt(3);
            list.RemoveAt(2);
        }
Пример #10
0
        public void TopX_EmptyMultipleAdd_CorrectResult()
        {
            INotifyCollection <Dummy <int> > collection = new NotifyCollection <Dummy <int> >();
            var top1 = new Dummy <int>(43);
            var top2 = new Dummy <int>(42);
            var top3 = new Dummy <int>(30);

            var changed = false;
            var topEx   = Observable.Expression(() => collection.TopX(3, d => d.Item));

            topEx.ValueChanged += (sender, args) => changed = true;

            var top = topEx.Value;

            Assert.AreEqual(0, top.Length);

            collection.Add(top2);
            top = topEx.Value;

            Assert.IsTrue(changed);
            Assert.AreEqual(top2, top[0].Key);
            Assert.AreEqual(1, top.Length);

            changed = false;
            collection.Add(top1);
            collection.Add(top3);
            top = topEx.Value;

            Assert.IsTrue(changed);
            Assert.AreEqual(top1, top[0].Key);
            Assert.AreEqual(top2, top[1].Key);
            Assert.AreEqual(top3, top[2].Key);
            Assert.AreEqual(3, top.Length);

            changed = false;
            collection.Add(new Dummy <int>(22));

            Assert.IsFalse(changed);
            Assert.AreEqual(top, topEx.Value);

            var newTop3 = new Dummy <int>((top3.Item + top2.Item) / 2);

            collection.Add(newTop3);
            top = topEx.Value;

            Assert.IsTrue(changed);
            Assert.AreEqual(top1, top[0].Key);
            Assert.AreEqual(top2, top[1].Key);
            Assert.AreEqual(newTop3, top[2].Key);
            Assert.AreEqual(3, top.Length);
        }
Пример #11
0
 static void Main(string[] args)
 {
     NotifyCollection nc = new NotifyCollection();
     nc.PropertyChanged += (s,e) =>
     {
         Console.WriteLine(e.PropertyName);
     };
     nc.Add(1);
     nc.Add(2);
     nc.Add(3);
     nc.Insert(2, 2);
     nc.Add(4);
     nc.Remove(4);
 }
Пример #12
0
        public void PredicateFirstOrDefault_ObservableSourceFirstItemAdded_Update()
        {
            var update = false;
            var coll   = new NotifyCollection <string>()
            {
                "1"
            };
            var collCasted = (INotifyCollection <string>)coll;

            var test = Observable.Expression(() => collCasted.FirstOrDefault(s => s.Length > 1));

            test.ValueChanged += (o, e) =>
            {
                update = true;
                Assert.AreEqual("42", e.NewValue);
                Assert.IsNull(e.OldValue);
            };

            Assert.IsNull(test.Value);
            Assert.IsFalse(update);

            coll.Add("42");

            Assert.IsTrue(update);
            Assert.AreEqual("42", test.Value);
        }
Пример #13
0
        public void Contains_ObservableSourceElementAdded_NoUpdateWhenDetached()
        {
            var update = false;
            var coll = new NotifyCollection<int>() { 1, 2, 3 };

            var test = Observable.Expression(() => coll.Contains(4));

            test.ValueChanged += (o, e) => update = true;

            Assert.IsFalse(test.Value);
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.IsTrue(test.Value);
            update = false;

            coll.Remove(4);

            Assert.IsTrue(update);
        }
Пример #14
0
        public void SetEqualsComparer_ObservableSource1ItemAddedSoFalse_Update()
        {
            var update = false;
            INotifyCollection <int> source1 = new NotifyCollection <int>()
            {
                -1, 1, -2, -3
            };
            INotifyCollection <int> source2 = new NotifyCollection <int>()
            {
                1, 2, 2, 3
            };

            var test = Observable.Expression(() => source1.SetEquals(source2, new AbsoluteValueComparer()));

            test.ValueChanged += (o, e) =>
            {
                Assert.IsTrue((bool)e.OldValue);
                Assert.IsFalse((bool)e.NewValue);
                update = true;
            };

            Assert.IsTrue(test.Value);
            Assert.IsFalse(update);

            source1.Add(4);

            Assert.IsTrue(update);
            Assert.IsFalse(test.Value);
        }
Пример #15
0
        public void SetEquals_ObservableSource2ItemAddedSoTrue_Update()
        {
            var update = false;
            INotifyCollection <int> source1 = new NotifyCollection <int>()
            {
                1, 1, 2, 3
            };
            INotifyCollection <int> source2 = new NotifyCollection <int>()
            {
                1, 2, 2
            };

            var test = Observable.Expression(() => source1.SetEquals(source2));

            test.ValueChanged += (o, e) =>
            {
                Assert.IsFalse((bool)e.OldValue);
                Assert.IsTrue((bool)e.NewValue);
                update = true;
            };

            Assert.IsFalse(test.Value);
            Assert.IsFalse(update);

            source2.Add(3);

            Assert.IsTrue(update);
            Assert.IsTrue(test.Value);
        }
Пример #16
0
        public void LambdaAny_ObservableSource_NoUpdateWhenDetached()
        {
            var update = false;
            var coll   = new NotifyCollection <int>()
            {
                -1, -2
            };

            var test = Observable.Expression(() => coll.Any(i => i > 0));

            test.ValueChanged += (o, e) => update = true;

            Assert.IsFalse(test.Value);
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(1);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.IsTrue(test.Value);
            update = false;

            coll.Remove(1);

            Assert.IsTrue(update);
        }
Пример #17
0
        /// <summary>
        /// 获取所有通知
        /// </summary>
        /// <returns>返回所有通知集合</returns>
        public NotifyCollection GetAllNotifies(int pageSize, int pageNumber, ref int?count)
        {
#if !Passport
            PassportClientConfig settings = Globals.PassportClient;
            if (settings.EnablePassport)
            {
                NotifyProxy[] notifys = settings.PassportService.Notify_GetAllNotifies(pageSize, pageNumber, ref count);


                NotifyCollection result = new NotifyCollection();
                foreach (NotifyProxy proxy in notifys)
                {
                    result.Add(GetNotify(proxy));
                }

                return(result);
            }
            else
#endif
            {
                pageNumber = pageNumber <= 0 ? 1 : pageNumber;
                pageSize   = pageSize <= 0 ? Consts.DefaultPageSize : pageSize;

                if (HasUnCatchedError)
                {
                    return(new NotifyCollection());
                }

                return(NotifyDao.Instance.GetNotifies(null, pageSize, pageNumber, ref count));
            }
        }
Пример #18
0
        public void PredicateFirstOrDefault_ObservableSourceFirstItemAdded_NoUpdateWhenDetached()
        {
            var update = false;
            var coll   = new NotifyCollection <string>()
            {
                "1"
            };

            var test = Observable.Expression(() => coll.FirstOrDefault(s => s.Length > 1));

            test.ValueChanged += (o, e) => update = true;

            Assert.IsNull(test.Value);
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            coll.Add("42");

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual("42", test.Value);
            update = false;

            coll.Remove("42");

            Assert.IsTrue(update);
        }
Пример #19
0
        public void Contains_ObservableSourceElementAdded_NoUpdateWhenDetached()
        {
            var update = false;
            var coll   = new NotifyCollection <int>()
            {
                1, 2, 3
            };

            var test = Observable.Expression(() => coll.Contains(4));

            test.ValueChanged += (o, e) => update = true;

            Assert.IsFalse(test.Value);
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.IsTrue(test.Value);
            update = false;

            coll.Remove(4);

            Assert.IsTrue(update);
        }
Пример #20
0
        public void TopX_Remove_CorrectResult()
        {
            var collection = new NotifyCollection <Dummy <int> >();
            var collCasted = (INotifyCollection <Dummy <int> >)collection;
            var top1       = new Dummy <int>(43);
            var top2       = new Dummy <int>(42);
            var top3       = new Dummy <int>(30);

            collection.Add(top1);
            collection.Add(top2);
            collection.Add(top3);
            collection.Add(new Dummy <int>(23));
            collection.Add(new Dummy <int>(6));

            var topEx = Observable.Expression(() => collCasted.TopX(3, d => d.Item));
            var top   = topEx.Value;

            Assert.AreEqual(top1, top[0].Key);
            Assert.AreEqual(top2, top[1].Key);
            Assert.AreEqual(top3, top[2].Key);
            Assert.AreEqual(3, top.Length);

            var changed = false;

            topEx.ValueChanged += (o, e) =>
            {
                Assert.IsNotNull(e.OldValue);
                Assert.IsNotNull(e.NewValue);
                changed = true;
            };

            collection.RemoveAt(3);

            Assert.AreEqual(top, topEx.Value);
            Assert.IsFalse(changed);

            collection.Remove(top1);

            Assert.IsTrue(changed);
            Assert.AreEqual(42, topEx.Value[0].Key.Item);
            Assert.AreEqual(30, topEx.Value[1].Key.Item);
            Assert.AreEqual(6, topEx.Value[2].Key.Item);
        }
Пример #21
0
        public void SelectManyWithAverage1()
        {
            var updates = 0;
            INotifyCollection <TestItem> coll = new NotifyCollection <TestItem>();

            var query = from item in coll
                        group item by item.Team into team
                        let avg = team.Average(it => it.Items)
                                  from item2 in team
                                  where item2.Items < avg
                                  select item2;


            var testItem1 = new TestItem()
            {
                Items = 1, Team = "A"
            };
            var testItem2 = new TestItem()
            {
                Items = 2, Team = "A"
            };

            query.CollectionChanged += (o, e) =>
            {
                updates++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(1, e.NewItems.Count);
                Assert.AreSame(testItem1, e.NewItems[0]);
            };

            coll.Add(testItem1);

            Assert.AreEqual(0, updates);

            coll.Add(testItem2);

            Assert.AreEqual(1, updates);
            Assert.AreEqual(1, query.Count());
            Assert.IsTrue(query.Contains(testItem1));
        }
Пример #22
0
        public void Concat_ObservableSources_NoUpdateWhenDetached()
        {
            var update = false;
            var coll1  = new NotifyCollection <int>()
            {
                1, 2, 3
            };
            var coll2 = new NotifyCollection <int>()
            {
                4, 5, 6
            };

            var test = coll1.Concat(coll2);

            test.CollectionChanged += (o, e) => update = true;

            test.AssertSequence(1, 2, 3, 4, 5, 6);
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            coll1.Add(4);

            Assert.IsFalse(update);

            coll2.Add(7);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            test.AssertSequence(1, 2, 3, 4, 4, 5, 6, 7);
            update = false;

            coll1.Add(5);

            Assert.IsTrue(update);
        }
Пример #23
0
        static void Main ( string[] args )
        {
            Delegates del = new Delegates();
            List<int> numbers = new List<int> { 5 , 4 , 8 , 7 , 9 , 6 , 6 , 6 , 3 , 1 , 20 };
            List<int> evens = del.FilterCollection(numbers , IsEven);
            foreach(var item in evens)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
            AverageAggregator aggregator = new AverageAggregator();
            aggregator.AverageChanged += delegate ( object sender )
            {
                if(sender is AverageAggregator)
                {
                    AverageAggregator newSender = (AverageAggregator)sender;
                    Console.WriteLine("Average has changed!\nNew value: {0}" , newSender.Average);
                }
            };
            aggregator.AddNumber(6);
            aggregator.AddNumber(4);
            aggregator.AddNumber(2);
            aggregator.AddNumber(3);
            Student stu = new Student();
            stu.PropertyChanged += PropChange;
            stu.Name = "Anton";
            stu.FacultyNumber = 65888;
            stu.Grade = 5.58;

            NotifyCollection<int> newList = new NotifyCollection<int>();
            newList.PropertyChanged += (object sender, PropertyChangedEventArgs e)=>
        {
            Console.WriteLine("The list has changed!\n{0}" , e.PropertyName);
        };
            newList.Add(5);
            newList.Add(12);
            newList.Insert(1 , 20);
            newList.Remove(12);
            Console.ReadKey();
        }
Пример #24
0
        public void Transformations_Relational_Select1()
        {
            bool nextItemCalled = false;
            int  expectedResult = 1;

            var select = source.Select(s => s.Length);

            select.CollectionChanged += (o, e) =>
            {
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(expectedResult, e.NewItems[0]);
                nextItemCalled = true;
            };

            select.AssertEmpty();

            source.Add("a");

            Assert.IsTrue(nextItemCalled);
            select.AssertContainsOnly(1);

            nextItemCalled = false;
            expectedResult = 2;

            source.Add("aa");
            Assert.IsTrue(nextItemCalled);
            select.AssertContainsOnly(1, 2);

            nextItemCalled = false;
            expectedResult = 0;

            select.Successors.UnsetAll();

            source.Add("");

            Assert.IsFalse(nextItemCalled);
        }
Пример #25
0
        public void SelectWithAverage2()
        {
            var updates = 0;
            var coll    = new NotifyCollection <TestItem>();

            var query = from item in coll
                        where item.Items < coll.Average(t => t.Items)
                        select item;


            var testItem1 = new TestItem()
            {
                Items = 1, Team = "A"
            };
            var testItem2 = new TestItem()
            {
                Items = 2, Team = "A"
            };

            query.CollectionChanged += (o, e) =>
            {
                updates++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(1, e.NewItems.Count);
                Assert.AreSame(testItem1, e.NewItems[0]);
            };

            coll.Add(testItem2);

            Assert.AreEqual(0, updates);

            coll.Add(testItem1);

            Assert.AreEqual(1, updates);
            Assert.AreEqual(1, query.Count());
            Assert.IsTrue(query.Contains(testItem1));
        }
Пример #26
0
        /// <summary>
        /// 获取指定用户指定类型的所有通知
        /// </summary>
        /// <param name="notifyType">指定类型</param>
        /// <returns>指定用户指定类型的所有通知集合</returns>
        public NotifyCollection GetNotifiesByType(int userID, int notifyType, int pageSize, int pageNumber, ref int?count)
        {
            if (userID <= 0)
            {
                ThrowError(new NotLoginError());
                return(new NotifyCollection());
            }

            pageNumber = pageNumber <= 0 ? 1 : pageNumber;
            pageSize   = pageSize <= 0 ? Consts.DefaultPageSize : pageSize;

            if (HasUnCatchedError)
            {
                return(new NotifyCollection());
            }

#if !Passport
            PassportClientConfig settings = Globals.PassportClient;
            if (settings.EnablePassport)
            {
                NotifyProxy[] proxys = settings.PassportService.Notify_GetNotifiesByType(userID, notifyType, pageSize, pageNumber, ref count);


                NotifyCollection notifies = new NotifyCollection();
                foreach (NotifyProxy proxy in proxys)
                {
                    notifies.Add(GetNotify(proxy));
                }

                return(notifies);
            }
            else
#endif
            {
                NotifyCollection notifys;
                string           cacheKey = string.Format(cacheKey_pagedNotify, userID, notifyType, pageSize, pageNumber);
                if (!CacheUtil.TryGetValue <NotifyCollection>(cacheKey, out notifys))
                {
                    notifys = NotifyDao.Instance.GetNotifiesByType(userID, notifyType, pageSize, pageNumber, ref count);
                    CacheUtil.Set <NotifyCollection>(cacheKey, notifys);
                }
                count = notifys.TotalRecords;
                return(notifys);
            }
        }
Пример #27
0
        public void GroupBy_ObservableSource_NoUpdatesWhenDetached()
        {
            var update = false;
            ICollection <Dummy <string> > coll = new NotifyCollection <Dummy <string> >();

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) => update = true;

            Assert.IsTrue(!test.Any());
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            var testDummy = new ObservableDummy <string>()
            {
                Item = "42"
            };

            coll.Add(testDummy);

            Assert.IsFalse(update);

            testDummy.Item = "23";

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual("23", test.FirstOrDefault().Key);
            update = false;

            testDummy.Item = "42";

            Assert.IsTrue(update);
            update = false;

            coll.Remove(testDummy);

            Assert.IsTrue(update);
        }
Пример #28
0
        public void FirstOrDefault_ObservableSourceOtherItemAdded_NoUpdate()
        {
            var update = false;
            var coll   = new NotifyCollection <string>()
            {
                "23"
            };

            var test = Observable.Expression(() => coll.FirstOrDefault());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual("23", test.Value);
            Assert.IsFalse(update);

            coll.Add("42");

            Assert.IsFalse(update);
        }
Пример #29
0
        public void LambdaIntAverage_ObservableSourceItemAdded_NoUpdatesWhenDetached()
        {
            var update = false;
            var coll   = new NotifyCollection <Dummy <int> >()
            {
                new Dummy <int>(1), new Dummy <int>(2), new Dummy <int>(3)
            };
            var testColl = coll.WithUpdates();

            var test = Observable.Expression(() => testColl.Average(d => d.Item));

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(2, test.Value);
            Assert.AreEqual(2, testColl.Average(d => d.Item));
            Assert.IsFalse(update);

            test.Detach();

            var testDummy = new ObservableDummy <int>(5);

            coll.Add(testDummy);

            Assert.IsFalse(update);

            testDummy.Item = 4;

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(2.5, test.Value);
            update = false;

            testDummy.Item = 5;

            Assert.IsTrue(update);
            update = false;

            coll.Remove(testDummy);
        }
Пример #30
0
        public void GroupBy_ObservableSource_NoUpdatesWhenDetached()
        {
            var update = false;
            ICollection<Dummy<string>> coll = new NotifyCollection<Dummy<string>>();

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) => update = true;

            Assert.IsTrue(!test.Any());
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            var testDummy = new ObservableDummy<string>() { Item = "42" };
            coll.Add(testDummy);

            Assert.IsFalse(update);

            testDummy.Item = "23";

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual("23", test.FirstOrDefault().Key);
            update = false;

            testDummy.Item = "42";

            Assert.IsTrue(update);
            update = false;

            coll.Remove(testDummy);

            Assert.IsTrue(update);
        }
Пример #31
0
        public void FirstOrDefault_ObservableSourceFirstItemAdded_Update()
        {
            var update = false;
            var coll = new NotifyCollection<string>();

            var test = Observable.Expression(() => coll.FirstOrDefault());

            test.ValueChanged += (o, e) =>
            {
                update = true;
                Assert.AreEqual("42", e.NewValue);
                Assert.IsNull(e.OldValue);
            };

            Assert.IsNull(test.Value);
            Assert.IsFalse(update);

            coll.Add("42");

            Assert.IsTrue(update);
            Assert.AreEqual("42", test.Value);
        }
Пример #32
0
        public void FirstOrDefault_ObservableSourceFirstItemAdded_Update()
        {
            var update = false;
            INotifyCollection <string> coll = new NotifyCollection <string>();

            var test = Observable.Expression(() => coll.FirstOrDefault());

            test.ValueChanged += (o, e) =>
            {
                update = true;
                Assert.AreEqual("42", e.NewValue);
                Assert.IsNull(e.OldValue);
            };

            Assert.IsNull(test.Value);
            Assert.IsFalse(update);

            coll.Add("42");

            Assert.IsTrue(update);
            Assert.AreEqual("42", test.Value);
        }
Пример #33
0
        public void LambdaIntAverage_ObservableSourceItemAdded_NoUpdatesWhenDetached()
        {
            var update = false;
            var coll = new NotifyCollection<Dummy<int>>() { new Dummy<int>(1), new Dummy<int>(2), new Dummy<int>(3) };
            var testColl = coll.WithUpdates();

            var test = Observable.Expression(() => testColl.Average(d => d.Item));

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(2, test.Value);
            Assert.AreEqual(2, testColl.Average(d => d.Item));
            Assert.IsFalse(update);

            test.Detach();

            var testDummy = new ObservableDummy<int>(5);
            coll.Add(testDummy);

            Assert.IsFalse(update);

            testDummy.Item = 4;

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(2.5, test.Value);
            update = false;

            testDummy.Item = 5;

            Assert.IsTrue(update);
            update = false;

            coll.Remove(testDummy);
        }
Пример #34
0
        public void SetEquals_ObservableSource2ItemAddedSoTrue_Update()
        {
            var update = false;
            var source1 = new NotifyCollection<int>() { 1, 1, 2, 3 };
            var source2 = new NotifyCollection<int>() { 1, 2, 2 };

            var test = Observable.Expression(() => source1.SetEquals(source2));

            test.ValueChanged += (o, e) =>
            {
                Assert.IsFalse((bool)e.OldValue);
                Assert.IsTrue((bool)e.NewValue);
                update = true;
            };

            Assert.IsFalse(test.Value);
            Assert.IsFalse(update);

            source2.Add(3);

            Assert.IsTrue(update);
            Assert.IsTrue(test.Value);
        }
Пример #35
0
        public NotifyCollection GetTopNotifys(int userID, int count, int type)
        {
#if !Passport
            PassportClientConfig settings = Globals.PassportClient;
            if (settings.EnablePassport)
            {
                NotifyProxy[] notifys = new NotifyProxy[0];
                try
                {
                    notifys = settings.PassportService.Notify_GetTopNotify(userID, count, type);
                }
                catch (Exception ex)
                {
                    ThrowError(new APIError(ex.Message));
                }

                NotifyCollection result = new NotifyCollection();
                foreach (NotifyProxy proxy in notifys)
                {
                    result.Add(GetNotify(proxy));
                }

                return(result);
            }
            else
#endif
            {
                NotifyCollection notifys;
                //string key = string.Format(cacheKey_UserNotifyType, userID, type, count, 1);
                //if (!CacheUtil.TryGetValue<NotifyCollection>(key, out notifys))
                //{
                notifys = NotifyDao.Instance.GetTopNotifys(userID, type, count);
                //   CacheUtil.Set<NotifyCollection>(key, notifys);
                //}
                return(notifys);
            }
        }
Пример #36
0
        public void SetEquals_ObservableSource1ItemAdded_NoUpdate()
        {
            var update = false;
            INotifyCollection <int> source1 = new NotifyCollection <int>()
            {
                1, 1, 2, 3
            };
            INotifyCollection <int> source2 = new NotifyCollection <int>()
            {
                1, 2, 2, 3
            };

            var test = Observable.Expression(() => source1.SetEquals(source2));

            test.ValueChanged += (o, e) => update = true;

            Assert.IsTrue(test.Value);
            Assert.IsTrue(source1.SetEquals(source2));
            Assert.IsFalse(update);

            source1.Add(1);

            Assert.IsFalse(update);
        }
Пример #37
0
        public void SetEqualsComparer_ObservableSource2ItemAdded_NoUpdate()
        {
            var update = false;
            INotifyCollection <int> source1 = new NotifyCollection <int>()
            {
                -1, -1, -2, -3
            };
            INotifyCollection <int> source2 = new NotifyCollection <int>()
            {
                1, 2, -2, 3
            };

            var test = Observable.Expression(() => source1.SetEquals(source2, new AbsoluteValueComparer()));

            test.ValueChanged += (o, e) => update = true;

            Assert.IsTrue(test.Value);
            Assert.IsTrue(source1.SetEquals(source2, new AbsoluteValueComparer()));
            Assert.IsFalse(update);

            source2.Add(1);

            Assert.IsFalse(update);
        }
Пример #38
0
    private void Content_Type_ItemCreated(GameObject obj)
    {
        obj.GetClickedEventHelper().Clicked += (go) =>
        {
            var type = (go.GetDataContextValue() as DesignerDataLogic).Type;
            var dialogPanel = DialogPanel_Rows.gameObject;
            dialogPanel.SetActive(true);

            var dataType = typeof(DataEntityTemplate<>).MakeGenericType(type);
            var allData = dataType.InvokeMember("GetAllData", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, null) as IEnumerable;
            var collection = new NotifyCollection<DesignerDataLogic>();
            int i = 0;
            foreach (var data in allData)
            {
                collection.Add(new DesignerDataLogic() { Index = i, Row = data });
                ++i;
            }

            Content_Rows.ItemCreated += Content_Rows_ItemCreated;
            Content_Rows.ItemTemplate = buttonPrefab;
            Content_Rows.SourceCollection = collection;
        };
    }
Пример #39
0
    private void Content_Rows_ItemCreated(GameObject obj)
    {
        obj.GetClickedEventHelper().Clicked += (go) =>
        {
            var ins = (go.GetDataContextValue() as DesignerDataLogic).Row;

            var dialogPanel = DialogPanel_RowDetail.gameObject;
            dialogPanel.SetActive(true);
            var collection = new NotifyCollection<DesignerDataLogic>();
            foreach (var pro in ins.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (pro.GetCustomAttributes(typeof(ColumnNameAttribute), false).Length <= 0)
                    continue;

                collection.Add(new DesignerDataLogic() { TextAlignment = TextAnchor.MiddleRight, DisplayText = pro.Name + " = " });
                string v = pro.GetValue(ins, null).ToString();
                if (string.IsNullOrEmpty(v))
                    v = "\"\"";
                collection.Add(new DesignerDataLogic() { TextAlignment = TextAnchor.MiddleLeft, DisplayText = v });
            }
            Content_RowDetail.ItemTemplate = textPrefab;
            Content_RowDetail.SourceCollection = collection;
        };
    }
Пример #40
0
        public void TopX_NoObservable_CorrectResult()
        {
            var collection = new NotifyCollection <Dummy <int> >();
            var top1       = new Dummy <int>(43);
            var top2       = new Dummy <int>(42);
            var top3       = new Dummy <int>(30);

            collection.Add(top1);
            collection.Add(new Dummy <int>(5));
            collection.Add(new Dummy <int>(7));
            collection.Add(new Dummy <int>(1));
            collection.Add(new Dummy <int>(27));
            collection.Add(new Dummy <int>(25));
            collection.Add(new Dummy <int>(13));
            collection.Add(new Dummy <int>(17));
            collection.Add(new Dummy <int>(7));
            collection.Add(top2);
            collection.Add(top3);
            collection.Add(new Dummy <int>(23));
            collection.Add(new Dummy <int>(6));

            var top = collection.TopX(3, d => d.Item);

            Assert.AreEqual(top1, top[0].Key);
            Assert.AreEqual(top2, top[1].Key);
            Assert.AreEqual(top3, top[2].Key);
            Assert.AreEqual(3, top.Length);
        }
Пример #41
0
        public void SetEqualsComparer_ObservableSource1ItemAdded_NoUpdate()
        {
            var update = false;
            var source1 = new NotifyCollection<int>() { -1, -1, -2, -3 };
            var source2 = new NotifyCollection<int>() { 1, 2, 2, 3 };

            var test = Observable.Expression(() => source1.SetEquals(source2, new AbsoluteValueComparer()));

            test.ValueChanged += (o, e) => update = true;

            Assert.IsTrue(test.Value);
            Assert.IsTrue(source1.SetEquals(source2, new AbsoluteValueComparer()));
            Assert.IsFalse(update);

            source1.Add(1);

            Assert.IsFalse(update);
        }
Пример #42
0
        public void LambdaAny_ObservableSource_NoUpdateWhenDetached()
        {
            var update = false;
            var coll = new NotifyCollection<int>() { -1, -2 };

            var test = Observable.Expression(() => coll.Any(i => i > 0));

            test.ValueChanged += (o, e) => update = true;

            Assert.IsFalse(test.Value);
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(1);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.IsTrue(test.Value);
            update = false;

            coll.Remove(1);

            Assert.IsTrue(update);
        }
Пример #43
0
 private INotifyEnumerable<string> GetCopyrights()
 {
     NotifyCollection<string> copyrights = new NotifyCollection<string>();
     copyrights.Add("2011 Torshify Records");
     copyrights.Add("2010 Mock Records");
     return copyrights;
 }
Пример #44
0
        public void SelectWithAverage2()
        {
            var updates = 0;
            var coll = new NotifyCollection<TestItem>();

            var query = from item in coll
                        where item.Items < coll.Average(t => t.Items)
                        select item;


            var testItem1 = new TestItem() { Items = 1, Team = "A" };
            var testItem2 = new TestItem() { Items = 2, Team = "A" };

            query.CollectionChanged += (o, e) =>
            {
                updates++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(1, e.NewItems.Count);
                Assert.AreSame(testItem1, e.NewItems[0]);
            };

            coll.Add(testItem2);

            Assert.AreEqual(0, updates);

            coll.Add(testItem1);

            Assert.AreEqual(1, updates);
            Assert.AreEqual(1, query.Count());
            Assert.IsTrue(query.Contains(testItem1));
        }
Пример #45
0
        static void Main(string[] args)
        {
            Console.InputEncoding = Encoding.Unicode;
            Console.OutputEncoding = Encoding.Unicode;
            AverageAggregator averageAgg = new AverageAggregator
                (delegate (object sender, decimal oldAverage, decimal newAverage)
                {
                    Console.Write("--->Handler: ");
                    Console.WriteLine("Average changed from {0} to {1}.", oldAverage, newAverage);
                });

            Console.WriteLine("---AverageAggregator---");
            Console.WriteLine();

            Console.WriteLine("Adding number to aggregator: 2");
            averageAgg.AddNumber(2);
            Console.WriteLine("Adding number to aggregator: 2");
            averageAgg.AddNumber(2);
            Console.WriteLine("Adding number to aggregator: 8");
            averageAgg.AddNumber(8);
            Console.WriteLine("Adding number to aggregator: 4");
            averageAgg.AddNumber(4);
            Console.WriteLine("Adding number to aggregator: 4");
            averageAgg.AddNumber(4);
            Console.WriteLine("Adding number to aggregator: 4");
            averageAgg.AddNumber(4);
            Console.WriteLine("Adding number to aggregator: -24");
            averageAgg.AddNumber(-24);
            Console.WriteLine("Adding number to aggregator: 0");
            averageAgg.AddNumber(0);
            Console.WriteLine("Adding number to aggregator: 0");
            averageAgg.AddNumber(0);
            Console.WriteLine("Adding number to aggregator: 10");
            averageAgg.AddNumber(10);
            Console.WriteLine("Adding number to aggregator: 1");
            averageAgg.AddNumber(1);
            Console.WriteLine("Adding number to aggregator: 1");
            averageAgg.AddNumber(1);
            Console.WriteLine("Adding number to aggregator: 2");
            averageAgg.AddNumber(2);

            Console.WriteLine();
            Console.WriteLine("---NotifyCollection---");
            Console.WriteLine();

            NotifyCollection<Book> notCol = new NotifyCollection<Book>
                ((sender, changeType, changedItemIndex, changedItemInfo) =>
                {
                    Console.Write("--->Handler: ");
                    switch (changeType)
                    {
                        case ItemChangeType.Add:
                            Console.WriteLine("Added item to collection on {0} index!", changedItemIndex);
                            break;
                        case ItemChangeType.Insert:
                            Console.WriteLine("Inserted item in collection on {0} index!", changedItemIndex);
                            break;
                        case ItemChangeType.Remove:
                            if (changedItemIndex == -1) Console.WriteLine("Collection items cleared!");
                            else Console.WriteLine("Removed item from collection being on {0} index!", changedItemIndex);
                            break;
                        case ItemChangeType.Replace:
                            Console.WriteLine("Replaced item in collection being on {0} index!", changedItemIndex);
                            break;
                        case ItemChangeType.ChangedProperty:
                            Console.WriteLine("Item on {0} index property {1} changed!", changedItemIndex, changedItemInfo);
                            break;
                        default:
                            break;
                    }
                });

            Book book1 = new Book("author1", "book1", 2000);
            Book book2 = new Book("author2", "book2", 2001);
            Book book3 = new Book("author3", "book3", 2002);
            Console.WriteLine("Adding {0}!", book1);
            notCol.Add(book1);
            Console.WriteLine("Adding {0}!", book2);
            notCol.Add(book2);
            Console.WriteLine("Inserting {0} on index 1!", book3);
            notCol.Insert(1, book3);
            Console.WriteLine("Changing {0} year to 2011!", book1);
            book1.Year = 2011;
            Console.WriteLine("Changing {0} year to 2005!", book3);
            book3.Year = 2005;
            Console.WriteLine("Removing {0}!", book2);
            notCol.Remove(book2);
            Console.WriteLine("Changing removed book year to 1995!");
            book2.Year = 1995;
            Console.WriteLine("Clearing all items!");
            notCol.Clear();
            Console.WriteLine("Adding {0}!", book1);
            notCol.Add(book1);
            Console.WriteLine("Adding {0}!", book2);
            notCol.Add(book2);
            Console.WriteLine("Replacing book on 0 index with {0}", book3);
            notCol[0] = book3;
            Console.WriteLine("Changing old book year to 1895!");
            book1.Year = 1895;
            Console.WriteLine("Changing new book year to 2003!");
            book3.Year = 2003;

            Console.WriteLine();
            Console.WriteLine("---Network Buffer---");

            ReceiveBuffer rec = new ReceiveBuffer(MessageReceivedHandle);
            PacketGenerator pg = new PacketGenerator(rec);
            Console.WriteLine("Write messages. Write exit for exit.");
            Console.Write("Message to send: ");
            string inputMessage = Console.ReadLine();
            while(!inputMessage.Equals("exit"))
            {
                pg.SendMessage(inputMessage);
                Console.Write("Message to send: ");
                inputMessage = Console.ReadLine();
            }
        }
Пример #46
0
        public void FirstOrDefault_ObservableSourceOtherItemAdded_NoUpdate()
        {
            var update = false;
            var coll = new NotifyCollection<string>() { "23" };

            var test = Observable.Expression(() => coll.FirstOrDefault());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual("23", test.Value);
            Assert.IsFalse(update);

            coll.Add("42");

            Assert.IsFalse(update);
        }
Пример #47
0
        public void PredicateFirstOrDefault_ObservableSourceFirstItemAdded_NoUpdateWhenDetached()
        {
            var update = false;
            var coll = new NotifyCollection<string>() { "1" };

            var test = Observable.Expression(() => coll.FirstOrDefault(s => s.Length > 1));

            test.ValueChanged += (o, e) => update = true;

            Assert.IsNull(test.Value);
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            coll.Add("42");

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual("42", test.Value);
            update = false;

            coll.Remove("42");

            Assert.IsTrue(update);
        }
Пример #48
0
        public void SelectManyWithAverage1()
        {
            var updates = 0;
            var coll = new NotifyCollection<TestItem>();

            var query = from item in coll
                        group item by item.Team into team
                        let avg = team.Average(it => it.Items)
                        from item2 in team
                        where item2.Items < avg
                        select item2;


            var testItem1 = new TestItem() { Items = 1, Team = "A" };
            var testItem2 = new TestItem() { Items = 2, Team = "A" };

            query.CollectionChanged += (o, e) =>
            {
                updates++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(1, e.NewItems.Count);
                Assert.AreSame(testItem1, e.NewItems[0]);
            };

            coll.Add(testItem1);

            Assert.AreEqual(0, updates);

            coll.Add(testItem2);

            Assert.AreEqual(1, updates);
            Assert.AreEqual(1, query.Count());
            Assert.IsTrue(query.Contains(testItem1));
        }
Пример #49
0
        public void TopX_NoChanges_CorrectResult()
        {
            INotifyCollection <Dummy <int> > collection = new NotifyCollection <Dummy <int> >();
            var top1 = new Dummy <int>(43);
            var top2 = new Dummy <int>(42);
            var top3 = new Dummy <int>(30);

            collection.Add(top1);
            collection.Add(new Dummy <int>(5));
            collection.Add(new Dummy <int>(7));
            collection.Add(new Dummy <int>(1));
            collection.Add(new Dummy <int>(27));
            collection.Add(new Dummy <int>(25));
            collection.Add(new Dummy <int>(13));
            collection.Add(new Dummy <int>(17));
            collection.Add(new Dummy <int>(7));
            collection.Add(top2);
            collection.Add(top3);
            collection.Add(new Dummy <int>(23));
            collection.Add(new Dummy <int>(6));

            var topEx = Observable.Expression(() => collection.TopX(3, d => d.Item));
            var top   = topEx.Value;

            Assert.AreEqual(top1, top[0].Key);
            Assert.AreEqual(top2, top[1].Key);
            Assert.AreEqual(top3, top[2].Key);
            Assert.AreEqual(3, top.Length);
        }