Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 高级搜索
        /// </summary>
        public override NotifyCollection GetNotifiesBySearch(AdminNotifyFilter notifyFilter, int pageNumber)
        {
            using (SqlQuery query = new SqlQuery())
            {
                StringBuilder condition = FilterToCondition(query, notifyFilter);

                query.Pager.IsDesc      = true;
                query.Pager.TableName   = "[bx_Notify]";
                query.Pager.SortField   = "[NotifyID]";
                query.Pager.PageNumber  = pageNumber;
                query.Pager.PageSize    = notifyFilter.PageSize;
                query.Pager.SelectCount = true;
                query.Pager.Condition   = condition.ToString();

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    NotifyCollection notifies = new NotifyCollection(reader);

                    if (reader.NextResult())
                    {
                        if (reader.Read())
                        {
                            notifies.TotalRecords = reader.Get <int>(0);
                        }
                    }
                    return(notifies);
                }
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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));
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public void PredicateFirstOrDefault_ObservableSourceFirstItemAdded_Update()
        {
            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.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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        public void WhereSelectOrderByTransaction_RemoveCausingChange_Update() // Works without Transaction
        {
            ExecutionEngine.Current = new SequentialExecutionEngine();

            var update = false;
            var dummy1 = new ObservableDummy <int>(1);
            var dummy2 = new Dummy <int>(3);
            var dummy3 = new Dummy <int>(5);
            INotifyCollection <Dummy <int> > coll = new NotifyCollection <Dummy <int> >()
            {
                dummy1, dummy2, dummy3
            };

            var test = coll.Where(d => d.Item > 0).Select(d => new Dummy <int>(d.Item * 2)).OrderBy(d => d.Item);

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

            ((IEnumerable <Dummy <int> >)test).Select(d => d.Item).AssertSequence(dummy1.Item * 2, dummy2.Item * 2, dummy3.Item * 2);
            Assert.AreEqual(3, test.Sequences.Count());
            Assert.IsFalse(update);

            ExecutionEngine.Current.BeginTransaction();

            dummy1.Item = 0;
            Assert.IsFalse(update);

            ExecutionEngine.Current.CommitTransaction();

            // Calling Select directly on test leads to quadrupling of the entries in test
            ((IEnumerable <Dummy <int> >)test).Select(d => d.Item).AssertSequence(dummy2.Item * 2, dummy3.Item * 2);
            Assert.AreEqual(2, test.Sequences.Count());
            Assert.IsTrue(update);
        }
Exemplo n.º 12
0
        public void WhereOrderByTransaction_ChangeRemove_Update() // Works without Transaction
        {
            ExecutionEngine.Current = new SequentialExecutionEngine();

            var update = false;
            var dummy1 = new ObservableDummy <int>(1);
            var dummy2 = new Dummy <int>(3);
            var dummy3 = new Dummy <int>(5);
            INotifyCollection <Dummy <int> > coll = new NotifyCollection <Dummy <int> >()
            {
                dummy1, dummy2, dummy3
            };

            var test = coll.Where(d => d.Item > 0).OrderBy(d => d.Item);

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

            test.AssertSequence(dummy1, dummy2, dummy3);
            Assert.AreEqual(3, test.Sequences.Count());
            Assert.IsFalse(update);

            ExecutionEngine.Current.BeginTransaction();

            dummy1.Item = 0;
            Assert.IsFalse(update);

            ExecutionEngine.Current.CommitTransaction();

            test.AssertSequence(dummy2, dummy3);
            Assert.AreEqual(2, test.Sequences.Count());
            Assert.IsTrue(update);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public void FirstOrDefault_ObservableSourceNewFirstItemAdded_Update()
        {
            var update = false;
            var coll   = new NotifyCollection <string>()
            {
                "23"
            };
            var collCasted = (INotifyCollection <string>)coll;

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

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

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

            coll.Insert(0, "42");

            Assert.IsTrue(update);
            Assert.AreEqual("42", test.Value);
        }
Exemplo n.º 15
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public MainViewModel()
        {
            VariationList = new NotifyCollection <VariationInfo>();
            MoveList      = new NotifyCollection <CsaMove>();

            if (string.IsNullOrEmpty(Name))
            {
                Name = "meijin_" + MathEx.RandInt(0, 1000);
            }
            ServerPort = "4084";

            ThreadNumMaximum = Global.GetCpuThreadNum();
            if (ThreadNum == 0)
            {
                ThreadNum = Math.Max(1, ThreadNumMaximum - 2);
            }

            var rawMemSizeList = GetMemorySizeList().ToList();

            MemSizeList = rawMemSizeList.Take(7).ToList();

            if (HashMemSize == 0)
            {
                var index = MathEx.Between(0, 6, rawMemSizeList.Count - 2);
                HashMemSize = rawMemSizeList[index].Item1;
            }

            this.AddDependModel(Global.Settings);
        }
Exemplo n.º 16
0
        public void SetEqualsComparer_ObservableSource1ItemRemovedSoTrue_Update()
        {
            var update  = false;
            var source1 = new NotifyCollection <int>()
            {
                -1, 1, -2, -3, 4
            };
            var source2 = new NotifyCollection <int>()
            {
                1, 2, 2, 3
            };

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

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

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

            source1.Remove(4);

            Assert.IsTrue(update);
            Assert.IsTrue(test.Value);
        }
Exemplo n.º 17
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public Scenario()
        {
            Children = new NotifyCollection<IAnimationTimeline>();
            Target = null;

            Children.CollectionChanged += Children_CollectionChanged;
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public Scenario()
        {
            Children = new NotifyCollection <IAnimationTimeline>();
            Target   = null;

            Children.CollectionChanged += Children_CollectionChanged;
        }
Exemplo n.º 20
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public ShogiModel()
        {
            CurrentBoard  = new Board();
            Board         = new Board();
            VariationList = new NotifyCollection <VariationInfo>();

            AddPropertyChangedHandler("CurrentEvaluationValue",
                                      (_, __) => CurrentEvaluationValueChanged());
            AddPropertyChangedHandler("BlackBaseLeaveTime",
                                      (_, __) => BlackLeaveTime = BlackBaseLeaveTime);
            AddPropertyChangedHandler("WhiteBaseLeaveTime",
                                      (_, __) => WhiteLeaveTime = WhiteBaseLeaveTime);

            MyTurn             = BWType.Black;
            CurrentTurn        = BWType.Black;
            BlackBaseLeaveTime = TimeSpan.Zero;
            WhiteBaseLeaveTime = TimeSpan.Zero;

            this.timer = new DispatcherTimer(
                TimeSpan.FromSeconds(0.1),
                DispatcherPriority.Normal,
                (_, __) => OnTimer(),
                WPFUtil.UIDispatcher);
            this.timer.Start();
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 高级搜索
        /// </summary>
        public override NotifyCollection AdminGetNotifiesBySearch(AdminNotifyFilter notifyFilter, int pageNumber, IEnumerable <Guid> excludeRoleIds)
        {
            using (SqlQuery query = new SqlQuery())
            {
                StringBuilder condition = FilterToCondition(query, notifyFilter);

                string exlcludeUserIDs = DaoUtil.GetExcludeRoleSQL("UserID", excludeRoleIds, query);
                if (!string.IsNullOrEmpty(exlcludeUserIDs))
                {
                    condition.Append(" AND " + exlcludeUserIDs);
                }

                query.Pager.IsDesc      = true;
                query.Pager.TableName   = "[bx_Notify]";
                query.Pager.SortField   = "[NotifyID]";
                query.Pager.PageNumber  = pageNumber;
                query.Pager.PageSize    = notifyFilter.PageSize;
                query.Pager.SelectCount = true;
                query.Pager.Condition   = condition.ToString();

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    NotifyCollection notifies = new NotifyCollection(reader);

                    if (reader.NextResult())
                    {
                        if (reader.Read())
                        {
                            notifies.TotalRecords = reader.Get <int>(0);
                        }
                    }
                    return(notifies);
                }
            }
        }
Exemplo n.º 23
0
        public void PredicateFirstOrDefault_ObservableSourceRemoveNewFirstItem_Update()
        {
            var update = false;
            var coll   = new NotifyCollection <string>()
            {
                "1", "42", "23"
            };
            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.OldValue);
                Assert.AreEqual("23", e.NewValue);
            };

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

            coll.Remove("42");

            Assert.IsTrue(update);
            Assert.AreEqual("23", test.Value);
        }
Exemplo n.º 24
0
        public void OrderByTransaction_ChangeReplace_Update()
        {
            ExecutionEngine.Current = new SequentialExecutionEngine();

            var update = false;
            var dummy1 = new ObservableDummy <int>(1);
            var dummy2 = new Dummy <int>(3);
            var dummy3 = new Dummy <int>(5);
            var coll   = new NotifyCollection <Dummy <int> >()
            {
                dummy1, dummy2, dummy3
            };
            var collCasted = (INotifyCollection <Dummy <int> >)coll;
            var newDummy   = new Dummy <int>(2);

            var test = collCasted.OrderBy(d => d.Item);

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

            test.AssertSequence(dummy1, dummy2, dummy3);
            Assert.AreEqual(3, test.Sequences.Count());
            Assert.IsFalse(update);

            ExecutionEngine.Current.BeginTransaction();

            dummy1.Item = 0;
            coll[0]     = newDummy;
            Assert.IsFalse(update);

            ExecutionEngine.Current.CommitTransaction();

            test.AssertSequence(newDummy, dummy2, dummy3);
            Assert.AreEqual(3, test.Sequences.Count());
            Assert.IsTrue(update);
        }
Exemplo n.º 25
0
        /// <summary>
        /// 获取指定用户/所有用户的所有通知
        /// </summary>
        /// <param name="userID">指定用户的ID,可以为空,为空则为要获取所有用户</param>
        /// <returns>返回指定用户的所有通知集合</returns>
        public override NotifyCollection GetNotifies(int?userID, int pageSize, int pageNumber, ref int?count)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.Pager.IsDesc       = true;
                query.Pager.TableName    = "[bx_Notify]";
                query.Pager.SortField    = "[NotifyID]";
                query.Pager.PrimaryKey   = "[NotifyID]";
                query.Pager.PageNumber   = pageNumber;
                query.Pager.PageSize     = pageSize;
                query.Pager.TotalRecords = count;
                query.Pager.SelectCount  = true;
                if (userID != null)
                {
                    query.Pager.Condition = @"[UserID] = @UserID";
                }

                query.CreateParameter <int?>("@UserID", userID, SqlDbType.Int);

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    NotifyCollection notifies = new NotifyCollection(reader);

                    if (count == null && reader.NextResult())
                    {
                        if (reader.Read())
                        {
                            count = reader.Get <int>(0);
                        }
                    }
                    return(notifies);
                }
            }
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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));
        }
Exemplo n.º 28
0
        public void SetEquals_ObservableSource2ItemRemovedSoFalse_Update()
        {
            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));

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

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

            source2.Remove(3);

            Assert.IsTrue(update);
            Assert.IsFalse(test.Value);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
 public PlayerViewModel() : base("Player Module", true, true)
 {
     DynamicViewName = "Player Module";
     //Mediator.GetInstance.RegisterInterest<Entity>(Topic.MockBondServiceDataReceived, DataReceived);
     //var grid = GetRef<DataGrid>("MainGrid");
     Entities             = new NotifyCollection <Entity>(EntityBuilder.LoadMetadata(AssetType.Common, AssetType.Player));
     CreateColumnsCommand = new SimpleCommand <Object, EventToCommandArgs>((parameter) => true, CreateColumns);
 }
        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));
        }
Exemplo n.º 32
0
 public FutureViewModel()
     : base("Future Module", true, true)
 {
     DynamicViewName = "Future Module";
     //Mediator.GetInstance.RegisterInterest<Entity>(Topic.MockBondServiceDataReceived, DataReceived);
     //var grid = GetRef<DataGrid>("MainGrid");
     Entities = new NotifyCollection<Entity>(EntityBuilder.LoadMetadata(AssetType.Common, AssetType.Future));
     CreateColumnsCommand = new SimpleCommand<Object, EventToCommandArgs>((parameter) => true, CreateColumns);
 }
Exemplo n.º 33
0
        public void ReversableFirstOrDefault_SetToNull_Correct()
        {
            var collection = new NotifyCollection <string>()
            {
                "a", "b", "c"
            };

            SetValue(() => collection.FirstOrDefault(), null);
            Assert.AreEqual(0, collection.Count);
        }
Exemplo n.º 34
0
        // ====================================================================================================


        // ====================================================================================================
        #region MÉTODOS PÚBLICOS
        // ====================================================================================================

        public void CargarDatos()
        {
            if (App.Global.CadenaConexion == null)
            {
                ListaFestivos.Clear();
                return;
            }
            ListaFestivos = new NotifyCollection <Festivo>(BdFestivos.GetFestivos());
            VistaFestivos = new ListCollectionView(ListaFestivos);
            //VistaFestivos.Filter = f => (f as Festivo).Año == AñoActual;
        }
Exemplo n.º 35
0
        public BondViewModel() : base("Bond Module", true, true)
        {
            DynamicViewName = "Bond Module";
            _grid           = GetRef <DataGrid>("MainGrid");

            // InputManager.Current.PreProcessInput += new PreProcessInputEventHandler(Current_PreProcessInput);
            // InputManager.Current.PostProcessInput += new ProcessInputEventHandler(Current_PostProcessInput);

            Entities             = new NotifyCollection <Entity>(EntityBuilder.LoadMetadata(AssetType.Common, AssetType.Bond));
            CreateColumnsCommand = new SimpleCommand <Object, EventToCommandArgs>((parameter) => true, CreateColumns);
        }
Exemplo n.º 36
0
        public void ReversableFirstOrDefault_WithPredicate_SetToNull_Correct()
        {
            var collection = new NotifyCollection <string>()
            {
                "a", "b", "c"
            };

            SetValue(() => collection.FirstOrDefault(s => string.Compare(s, "a") > 0), null);
            Assert.AreEqual(1, collection.Count);
            Assert.IsTrue(collection.Contains("a"));
        }
Exemplo n.º 37
0
        public BondViewModel()
            : base("Bond Module", true, true)
        {
            DynamicViewName = "Bond Module";
            _grid = GetRef<DataGrid>("MainGrid");

            // InputManager.Current.PreProcessInput += new PreProcessInputEventHandler(Current_PreProcessInput);
            // InputManager.Current.PostProcessInput += new ProcessInputEventHandler(Current_PostProcessInput);

            Entities = new NotifyCollection<Entity>(EntityBuilder.LoadMetadata(AssetType.Common, AssetType.Bond));
            CreateColumnsCommand = new SimpleCommand<Object, EventToCommandArgs>((parameter) => true, CreateColumns);
        }
Exemplo n.º 38
0
 private static void Main(string[] args)
 {
     var full                    = new NotifyCollection <string>();
     var readOnlyAccess          = (IReadOnlyCollection <string>)full;
     var readOnlyNotifyOfChange1 = (IReadOnlyNotifyCollection <string>)full;
     //Covarience
     var readOnlyListWithChanges = new List <IReadOnlyNotifyCollection <object> >()
     {
         new NotifyCollection <object>(),
         new NotifyCollection <string>(),
     };
 }
Exemplo n.º 39
0
 public ArtistInformation(Artist artist, Dispatcher dispatcher)
 {
     _portraits = new NotifyCollection<Image>();
     _tracks = new NotifyCollection<Track>();
     _albums = new NotifyCollection<Album>();
     _similarArtists = new NotifyCollection<Artist>();
     _dispatcher = dispatcher;
     _artist = artist;
     _browse = _artist.InternalArtist.Browse();
     _isLoading = !_browse.IsComplete;
     _browse.Completed += ArtistBrowseCompleted;
 }
Exemplo n.º 40
0
 // ====================================================================================================
 #region MÉTODOS PÚBLICOS
 // ====================================================================================================
 public void CargarConductores()
 {
     if (App.Global.CadenaConexion == null)
     {
         ListaConductores.Clear();
         return;
     }
     ListaConductores = new NotifyCollection <Conductor>(BdConductores.GetConductores());
     //foreach (Conductor c in ListaConductores) {
     //	c.PropertyChanged += ConductorPropertyChangedHandler;
     //}
     PropiedadCambiada(nameof(Detalle));
 }
Exemplo n.º 41
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);
        }
Exemplo n.º 42
0
        public Search(ISearch search, Dispatcher dispatcher)
        {
            _dispatcher = dispatcher;
            _albums = new NotifyCollection<ITorshifyAlbum>();
            _artists = new NotifyCollection<ITorshifyArtist>();
            _tracks = new NotifyCollection<ITorshifyTrack>();

            InternalSearch = search;

            if (!InternalSearch.IsComplete)
            {
                InternalSearch.Completed += OnSearchCompleted;
            }
        }
Exemplo n.º 43
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);
 }
Exemplo n.º 44
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);
        }
Exemplo n.º 45
0
        public void SetEquals_NoObservableSource2_NoUpdate()
        {
            var update = false;
            var source1 = new NotifyCollection<int>() { 1, 1, 2, 3 };
            var source2 = new List<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);

            source2.Add(4);

            Assert.IsFalse(update);
        }
Exemplo n.º 46
0
        public AlbumInformation(Artist originalArtist, Album album, Dispatcher dispatcher)
        {
            _orginalArtist = originalArtist;
            _tracks = new NotifyCollection<Track>();
            _copyrights = new NotifyCollection<string>();
            _dispatcher = dispatcher;
            _album = album;
            _browse = _album.InternalAlbum.Browse();
            _isLoading = !_browse.IsComplete;

            if (IsLoading)
            {
                _browse.Completed += AlbumBrowseCompleted;
            }
            else
            {
                AlbumBrowseCompleted(_browse, null);
            }
        }
Exemplo n.º 47
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();
        }
Exemplo n.º 48
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);
        }
Exemplo n.º 49
0
        public void FirstOrDefault_ObservableSourceNewFirstItemAdded_Update()
        {
            var update = false;
            var coll = new NotifyCollection<string>() { "23" };

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

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

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

            coll.Insert(0, "42");

            Assert.IsTrue(update);
            Assert.AreEqual("42", test.Value);
        }
Exemplo n.º 50
0
        public Playlist(IPlaylist playlist, Dispatcher dispatcher)
        {
            _dispatcher = dispatcher;
            _tracks = new NotifyCollection<PlaylistTrack>();

            InternalPlaylist = playlist;
            InternalPlaylist.DescriptionChanged += OnDescriptionChanged;
            InternalPlaylist.MetadataUpdated += OnMetadataChanged;
            InternalPlaylist.Renamed += OnRenamed;
            InternalPlaylist.StateChanged += OnStateChanged;
            InternalPlaylist.TracksAdded += OnTracksAdded;
            InternalPlaylist.TracksRemoved += OnTracksRemoved;
            InternalPlaylist.TracksMoved += OnTracksMoved;
            InternalPlaylist.UpdateInProgress += OnUpdateInProgress;

            _isLoaded = InternalPlaylist.IsLoaded;

            if (_isLoaded)
            {
                FetchTracks();
            }
        }
Exemplo n.º 51
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);
        }
Exemplo n.º 52
0
        public void SetEquals_ObservableSource2ItemRemovedSoFalse_Update()
        {
            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));

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

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

            source2.Remove(3);

            Assert.IsTrue(update);
            Assert.IsFalse(test.Value);
        }
Exemplo n.º 53
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            AddNavigationItem("通知");

            WaitForFillSimpleUsers<Notify>(this.NotifyList);

            pageNumber = _Request.Get<int>("page", 1);

            int? totalNotifies = null;
            if (notifyType != -1)
            {
                m_NotifyList = NotifyBO.Instance.GetNotifiesByType(MyUserID, notifyType, PageSize, pageNumber, ref totalNotifies);

                m_TotalCount = totalNotifies.Value;
                m_TotalCount += My.SystemNotifys.Count;
            }
            else
            {
                m_TotalCount = MyAllSystemNotifies.TotalRecords;
            }

            SetPager("pager1", null, pageNumber, PageSize, m_TotalCount);

        }
Exemplo n.º 54
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 public Scenario()
 {
     // コンストラクタで初期化しないと、インスタンスごとに
     // オブジェクトが作られません。
     Children = new NotifyCollection<AnimationTimeline>();
 }
 /// <summary>
 /// コンストラクタ
 /// </summary>
 public Point3dAnimationUsingKeyFrames()
     : base(typeof(Point3d))
 {
     KeyFrames = new NotifyCollection<Point3dKeyFrame>();
     //System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames
 }
Exemplo n.º 56
0
        public void Contains_ObservableSourceReset_Update()
        {
            var update = false;
            var coll = new NotifyCollection<int>() { 1, 2, 3 };

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

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

            coll.Clear();

            Assert.IsTrue(update);
        }
Exemplo n.º 57
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);
        }
 private ScriptErrorManager()
 {
   _scriptErrors = new NotifyCollection<ScriptError>();
 }
Exemplo n.º 59
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();
            }
        }
Exemplo n.º 60
0
        public void PredicateFirstOrDefault_ObservableSourceOtherItemRemoved_NoUpdate()
        {
            var update = false;
            var coll = new NotifyCollection<string>() { "1", "23", "42" };

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

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

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

            coll.Remove("42");

            Assert.IsFalse(update);
        }